amath  1.8.5
Simple command line calculator
DigitsStatement Class Reference

Set number of significant digits to show. More...

#include <digits.h>

Inheritance diagram for DigitsStatement:
Collaboration diagram for DigitsStatement:

Public Member Functions

 DigitsStatement ()
 Constructor used to show number of active digits. More...
 
 DigitsStatement (unsigned int digits)
 Constructor used to show number of active digits. More...
 
 ~DigitsStatement ()
 
char * Execute ()
 
- Public Member Functions inherited from StatementNode
 StatementNode ()
 
 StatementNode (const char *text)
 
virtual ~StatementNode ()
 
NodeType GetNodeType ()
 
virtual SyntaxNodeGetNext ()
 
virtual char * GetTextCode ()
 
void Attach (SyntaxNode *node)
 
void Detach (SyntaxNode *node)
 
void Replace (SyntaxNode *n, SyntaxNode *x)
 
- Public Member Functions inherited from SyntaxNode
 SyntaxNode ()
 
virtual ~SyntaxNode ()
 
void SetFirstNode ()
 
bool GetFirstNode () const
 
SyntaxNodeGetParent () const
 
void SetParent (SyntaxNode *node)
 
virtual ReductionType GetReductionType ()
 
virtual void ResetIterator ()
 

Private Attributes

bool show
 
unsigned int digits
 

Additional Inherited Members

- Protected Attributes inherited from StatementNode
char * statementText
 
- Protected Attributes inherited from SyntaxNode
CharBufferoutput
 
SyntaxNodeparent
 
SyntaxNodeiterator
 
bool leftBottom
 

Detailed Description

Set number of significant digits to show.

Definition at line 39 of file digits.h.

Constructor & Destructor Documentation

◆ DigitsStatement() [1/2]

DigitsStatement::DigitsStatement ( )

Constructor used to show number of active digits.

Definition at line 42 of file digits.cpp.

References digits, show, and StatementNode::StatementNode().

Referenced by Parser::ParseDigistStatement().

43  : StatementNode()
44 {
45  show = true;
46  digits = 0;
47 }
StatementNode()
Definition: node.cpp:34
unsigned int digits
Definition: digits.h:49
Here is the call graph for this function:
Here is the caller graph for this function:

◆ DigitsStatement() [2/2]

DigitsStatement::DigitsStatement ( unsigned int  digits)
explicit

Constructor used to show number of active digits.

Definition at line 53 of file digits.cpp.

References digits, show, and StatementNode::StatementNode().

Referenced by Parser::ParseDigistStatement().

53  :
55 {
56  show = false;
57 }
StatementNode()
Definition: node.cpp:34
unsigned int digits
Definition: digits.h:49
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ~DigitsStatement()

DigitsStatement::~DigitsStatement ( )

Definition at line 59 of file digits.cpp.

60 {
61 }

Member Function Documentation

◆ Execute()

char * DigitsStatement::Execute ( )
virtual

Implements StatementNode.

Definition at line 63 of file digits.cpp.

References CharBuffer::Append(), DecimalSystem::DecimalSystem(), digits, CharBuffer::Empty(), CharBuffer::EnsureSize(), NumeralSystem::GetDigits(), CharBuffer::GetString(), NumeralSystem::GetText(), Program::Input, Program::Output, SyntaxNode::output, Program::Preferences, RealNumber::RealNumber(), PreferencesBase::SetDigits(), NumeralSystem::SetDigits(), show, and StrLen().

64 {
65  const char* text;
66 
67  if (!show)
68  {
72  text = HELPDIGISETT;
73  }
74  else
75  {
76  text = HELPDIGISHOW;
78  }
79 
80  Number* d = new RealNumber(digits);
81  NumeralSystem* ns = new DecimalSystem(2);
82  const char* dtext = ns->GetText(d);
83  delete d;
84 
85  output->Empty();
86  output->EnsureSize(StrLen(text) + StrLen(dtext) + StrLen(NEWLINE) + 1);
87  output->Append(text);
88  output->Append(dtext);
90 
91  delete ns;
92  return output->GetString();
93 }
#define NEWLINE
Definition: amath.h:222
Master control class.
Definition: program.h:55
virtual void SetDigits(unsigned int digits)=0
#define HELPDIGISHOW
Definition: text.h:90
void Empty()
Definition: charbuf.cpp:218
char * GetString() const
Definition: charbuf.cpp:306
void Append(const char *source)
Definition: charbuf.cpp:262
Definition: numb.h:66
virtual const char * GetText(Number *number)=0
void SetDigits(int digits)
Represent a real number with 15 significant digits.
Definition: real.h:45
virtual unsigned int GetDigits()=0
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
CharBuffer * output
Definition: nodes.h:85
#define HELPDIGISETT
Definition: text.h:89
class NumeralSystem * Input
Definition: program.h:75
void EnsureSize(unsigned int size)
Ensure a memory block of specified size is allocated.
Definition: charbuf.cpp:114
unsigned int digits
Definition: digits.h:49
class PreferencesBase * Preferences
Definition: program.h:73
class NumeralSystem * Output
Definition: program.h:76
Here is the call graph for this function:

Member Data Documentation

◆ digits

unsigned int DigitsStatement::digits
private

Definition at line 49 of file digits.h.

Referenced by DigitsStatement(), and Execute().

◆ show

bool DigitsStatement::show
private

Definition at line 48 of file digits.h.

Referenced by DigitsStatement(), and Execute().


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