amath  1.8.5
Simple command line calculator
PreferencesBase Class Referenceabstract

#include <preferences.h>

Inheritance diagram for PreferencesBase:
Collaboration diagram for PreferencesBase:

Public Member Functions

 PreferencesBase ()
 
virtual ~PreferencesBase ()
 
char * GetDescription () const
 
char * GetPrompt () const
 
void SetPrompt (const char *prompt)
 
int GetDigits () const
 
void SetDigits (int digits)
 
bool GetRefactorNames ()
 
void SetRefactorNames (bool yes)
 
void SetDefaults ()
 
virtual bool Load ()=0
 
virtual bool Keep ()=0
 
virtual bool Save ()=0
 

Static Protected Member Functions

static void SetPrefs (char *prefs)
 

Private Attributes

CharBufferbuf
 
char * prompt
 
int digits
 
bool refactorNames
 

Detailed Description

Definition at line 35 of file preferences.h.

Constructor & Destructor Documentation

◆ PreferencesBase()

PreferencesBase::PreferencesBase ( )

Definition at line 41 of file preferences.cpp.

References buf, CharBuffer::CharBuffer(), and SetDefaults().

42 {
43  buf = new CharBuffer();
44  SetDefaults();
45 }
CharBuffer * buf
Definition: preferences.h:56
Encapsulate an character array which can be used as a string.
Definition: charbuf.h:44
Here is the call graph for this function:

◆ ~PreferencesBase()

PreferencesBase::~PreferencesBase ( )
virtual

Definition at line 47 of file preferences.cpp.

References buf, and prompt.

48 {
49  delete buf;
50  delete prompt;
51 }
CharBuffer * buf
Definition: preferences.h:56

Member Function Documentation

◆ GetDescription()

char * PreferencesBase::GetDescription ( ) const

Definition at line 60 of file preferences.cpp.

References CharBuffer::Append(), buf, DecimalSystem::DecimalSystem(), CharBuffer::Empty(), CharBuffer::EnsureSize(), Lexer::FindKeyword(), GetDigits(), CharBuffer::GetString(), NumeralSystem::GetText(), prompt, RealNumber::RealNumber(), StrLen(), symdelimiter, symdigits, and symprompt.

Referenced by PrefsStatement::Execute().

61 {
62  static char* promptkw = Lexer::FindKeyword(symprompt);
63  static char* digitkw = Lexer::FindKeyword(symdigits);
64  static char delimiter = *(Lexer::FindKeyword(symdelimiter));
65  static char promptq = '"';
66 
67  Number* d = new RealNumber(GetDigits());
68  NumeralSystem* ns = new DecimalSystem(2);
69  const char* dtext = ns->GetText(d);
70  delete d;
71 
72  buf->Empty();
73  buf->EnsureSize(
74  StrLen(promptkw) + sizeof(SPACE) + sizeof(promptq) +
75  StrLen(prompt) + sizeof(promptq) + sizeof(delimiter) +
76  StrLen(digitkw) + sizeof(SPACE) + StrLen(dtext) + sizeof(delimiter) + sizeof(char));
77 
78  buf->Append(promptkw);
79  buf->Append(SPACE);
80  buf->Append(promptq);
81  buf->Append(prompt);
82  buf->Append(promptq);
83  buf->Append(delimiter);
84  buf->Append(digitkw);
85  buf->Append(SPACE);
86  buf->Append(dtext);
87  buf->Append(delimiter);
88 
89  delete ns;
90  return buf->GetString();
91 }
void Empty()
Definition: charbuf.cpp:218
char * GetString() const
Definition: charbuf.cpp:306
#define SPACE
Definition: amath.h:214
void Append(const char *source)
Definition: charbuf.cpp:262
Definition: numb.h:66
virtual const char * GetText(Number *number)=0
static char * FindKeyword(Symbol symbol)
Definition: lexer.cpp:248
Represent a real number with 15 significant digits.
Definition: real.h:45
CharBuffer * buf
Definition: preferences.h:56
int StrLen(const char *string)
Get the length of a null terminated string.
Definition: strlen.c:34
Base class for all numeral systems.
Definition: ntext.h:49
void EnsureSize(unsigned int size)
Ensure a memory block of specified size is allocated.
Definition: charbuf.cpp:114
int GetDigits() const
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetDigits()

int PreferencesBase::GetDigits ( ) const

Definition at line 118 of file preferences.cpp.

References digits.

Referenced by PrefsStatement::Execute(), GetDescription(), and Program::Program().

119 {
120  return digits;
121 }
Here is the caller graph for this function:

◆ GetPrompt()

char * PreferencesBase::GetPrompt ( ) const

Definition at line 107 of file preferences.cpp.

References prompt.

Referenced by PrefsStatement::Execute(), and StandardProgram::Initialize().

108 {
109  return prompt;
110 }
Here is the caller graph for this function:

◆ GetRefactorNames()

bool PreferencesBase::GetRefactorNames ( )

Definition at line 128 of file preferences.cpp.

References refactorNames.

Referenced by FunctionNode::GetNodeText().

129 {
130  return refactorNames;
131 }
Here is the caller graph for this function:

◆ Keep()

virtual bool PreferencesBase::Keep ( )
pure virtual

Implemented in StandardPreferences.

Referenced by PrefsStatement::Execute(), and Program::~Program().

Here is the caller graph for this function:

◆ Load()

virtual bool PreferencesBase::Load ( )
pure virtual

Implemented in StandardPreferences.

Referenced by PrefsStatement::Execute(), and StandardProgram::Start().

Here is the caller graph for this function:

◆ Save()

virtual bool PreferencesBase::Save ( )
pure virtual

Implemented in StandardPreferences.

Referenced by PrefsStatement::Execute().

Here is the caller graph for this function:

◆ SetDefaults()

void PreferencesBase::SetDefaults ( )

Definition at line 53 of file preferences.cpp.

References AllocAndCopy(), digits, prompt, and refactorNames.

Referenced by PreferencesBase().

54 {
55  AllocAndCopy(&this->prompt, "> ");
56  digits = 9;
57  refactorNames = false;
58 }
unsigned int AllocAndCopy(char **destination, const char *source)
Allocate memory and copy a string into the array.
Definition: alloccpy.c:40
Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetDigits()

void PreferencesBase::SetDigits ( int  digits)

Definition at line 123 of file preferences.cpp.

References digits.

Referenced by DigitsStatement::Execute().

124 {
125  this->digits = digits;
126 }
Here is the caller graph for this function:

◆ SetPrefs()

void PreferencesBase::SetPrefs ( char *  prefs)
staticprotected

Definition at line 93 of file preferences.cpp.

References SyntaxNode::Execute(), Parser::Parse(), and Parser::Parser().

94 {
95  if (prefs == nullptr)
96  {
97  return;
98  }
99 
100  Parser* parser = new Parser(prefs);
101  SyntaxNode* node = parser->Parse();
102  delete parser;
103  node->Execute();
104  delete node;
105 }
Base class for all nodes in a syntax tree.
Definition: nodes.h:65
virtual char * Execute()=0
SyntaxNode * Parse()
Parses the input into a syntax tree.
Definition: parser.cpp:56
Encapsulates a recursive descent parser.
Definition: parser.h:49
Here is the call graph for this function:

◆ SetPrompt()

void PreferencesBase::SetPrompt ( const char *  prompt)

Definition at line 112 of file preferences.cpp.

References AllocAndCopy(), and prompt.

Referenced by Program::SetPrompt().

113 {
114  delete this->prompt;
115  AllocAndCopy(&this->prompt, prompt);
116 }
unsigned int AllocAndCopy(char **destination, const char *source)
Allocate memory and copy a string into the array.
Definition: alloccpy.c:40
Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetRefactorNames()

void PreferencesBase::SetRefactorNames ( bool  yes)

Definition at line 133 of file preferences.cpp.

References refactorNames.

134 {
135  refactorNames = yes;
136 }

Member Data Documentation

◆ buf

CharBuffer* PreferencesBase::buf
private

Definition at line 56 of file preferences.h.

Referenced by GetDescription(), PreferencesBase(), and ~PreferencesBase().

◆ digits

int PreferencesBase::digits
private

Definition at line 58 of file preferences.h.

Referenced by GetDigits(), SetDefaults(), and SetDigits().

◆ prompt

char* PreferencesBase::prompt
private

Definition at line 57 of file preferences.h.

Referenced by GetDescription(), GetPrompt(), SetDefaults(), SetPrompt(), and ~PreferencesBase().

◆ refactorNames

bool PreferencesBase::refactorNames
private

Definition at line 59 of file preferences.h.

Referenced by GetRefactorNames(), SetDefaults(), and SetRefactorNames().


The documentation for this class was generated from the following files: