amath  1.8.5
Simple command line calculator
PlotStatement Class Reference

#include <plot.h>

Inheritance diagram for PlotStatement:
Collaboration diagram for PlotStatement:

Public Member Functions

 PlotStatement (const char *name, const char *parameter, const char *file)
 
 PlotStatement (const char *name, const char *parameter)
 
 ~PlotStatement ()
 
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

char * name
 
char * parameter
 
char * file
 

Additional Inherited Members

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

Detailed Description

Definition at line 35 of file plot.h.

Constructor & Destructor Documentation

◆ PlotStatement() [1/2]

PlotStatement::PlotStatement ( const char *  name,
const char *  parameter,
const char *  file 
)

Definition at line 38 of file plot.cpp.

References AllocAndCopy(), file, name, parameter, and StatementNode::StatementNode().

38  :
40 {
41  AllocAndCopy(&this->name, name);
43  AllocAndCopy(&this->file, file);
44 }
char * file
Definition: plot.h:46
unsigned int AllocAndCopy(char **destination, const char *source)
Allocate memory and copy a string into the array.
Definition: alloccpy.c:40
char * parameter
Definition: plot.h:45
StatementNode()
Definition: node.cpp:34
char * name
Definition: plot.h:44
Here is the call graph for this function:

◆ PlotStatement() [2/2]

PlotStatement::PlotStatement ( const char *  name,
const char *  parameter 
)

Definition at line 46 of file plot.cpp.

References AllocAndCopy(), file, name, parameter, and StatementNode::StatementNode().

Referenced by Parser::ParseDrawStatement().

46  :
48 {
49  AllocAndCopy(&this->name, name);
51  file = nullptr;
52 }
char * file
Definition: plot.h:46
unsigned int AllocAndCopy(char **destination, const char *source)
Allocate memory and copy a string into the array.
Definition: alloccpy.c:40
char * parameter
Definition: plot.h:45
StatementNode()
Definition: node.cpp:34
char * name
Definition: plot.h:44
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ~PlotStatement()

PlotStatement::~PlotStatement ( )

Definition at line 54 of file plot.cpp.

References file, name, and parameter.

55 {
56  delete [] name;
57  delete [] parameter;
58 
59  if (file != nullptr)
60  {
61  delete [] file;
62  }
63 }
char * file
Definition: plot.h:46
char * parameter
Definition: plot.h:45
char * name
Definition: plot.h:44

Member Function Documentation

◆ Execute()

char * PlotStatement::Execute ( )
virtual

Implements StatementNode.

Definition at line 65 of file plot.cpp.

References CharBuffer::Append(), DecimalSystem::DecimalSystem(), CharBuffer::Empty(), CharBuffer::EnsureGrowth(), Program::Functions, FunctionList::GetFunctionDef(), Grid::GetHorizontalResolution(), Grid::GetScreenCoordinates(), CharBuffer::GetString(), NumeralSystem::GetText(), Grid::Grid(), name, SyntaxNode::output, parameter, RealNumber::RealNumber(), Grid::SetFunctionBounderies(), RealNumber::SetRealValue(), and Grid::SetScreenBounderues().

66 {
68 
69  if (function == nullptr)
70  {
71  return (char*)("Function does not exists." NEWLINE);
72  }
73 
74  output->Empty();
75 
76  Grid* grid = new Grid(function);
77  static const int width = 400;
78  static const int height = 300;
79 
80  grid->SetScreenBounderues(0, width, 20, height);
81  bool first = true;
82 
83  static const double min = -5.0;
84  static const double max = +5.0;
85  grid->SetFunctionBounderies(min, max);
86 
87  double x = min;
88  double step = grid->GetHorizontalResolution();
89 
90  int screenX;
91  int screenY;
92 
93  RealNumber* n = new RealNumber();
94  NumeralSystem* ns = new DecimalSystem(5);
95 
96  while (x < max)
97  {
98  grid->GetScreenCoordinates(x, &screenX, &screenY);
99 
100  output->EnsureGrowth(32);
101 
102  if (screenX != -1 && screenY != -1)
103  {
104  if (first)
105  {
106  output->Append('(');
107  n->SetRealValue(screenX);
108  output->Append(ns->GetText(n));
109  output->Append(',');
110  n->SetRealValue(height - screenY);
111  output->Append(ns->GetText(n));
112  output->Append(')');
114  first = false;
115  }
116  else
117  {
118  output->Append('(');
119  n->SetRealValue(screenX);
120  output->Append(ns->GetText(n));
121  output->Append(',');
122  n->SetRealValue(height - screenY);
123  output->Append(ns->GetText(n));
124  output->Append(')');
126  }
127  }
128 
129  x = x + step;
130  }
131 
132  delete n;
133  delete ns;
134  delete grid;
135 
136  return output->GetString();
137 }
#define NEWLINE
Definition: amath.h:222
Master control class.
Definition: program.h:55
void SetScreenBounderues(int minX, int maxX, int minY, int maxY)
Definition: fgrid.cpp:72
void Empty()
Definition: charbuf.cpp:218
char * GetString() const
Definition: charbuf.cpp:306
Definition: fgrid.h:42
void Append(const char *source)
Definition: charbuf.cpp:262
virtual const char * GetText(Number *number)=0
void SetFunctionBounderies(double minX, double maxX)
Definition: fgrid.cpp:51
class FunctionList * Functions
Definition: program.h:78
Represent a real number with 15 significant digits.
Definition: real.h:45
char * parameter
Definition: plot.h:45
double GetHorizontalResolution() const
Definition: fgrid.cpp:46
void GetScreenCoordinates(double value, int *x, int *y) const
Definition: fgrid.cpp:92
char * name
Definition: plot.h:44
void EnsureGrowth(unsigned int size)
Definition: charbuf.cpp:169
A user defined function.
Definition: userfunction.h:44
Base class for all numeral systems.
Definition: ntext.h:49
void SetRealValue(double value)
Definition: real.cpp:100
CharBuffer * output
Definition: nodes.h:85
UserFunction * GetFunctionDef(const char *name)
Here is the call graph for this function:

Member Data Documentation

◆ file

char* PlotStatement::file
private

Definition at line 46 of file plot.h.

Referenced by PlotStatement(), and ~PlotStatement().

◆ name

char* PlotStatement::name
private

Definition at line 44 of file plot.h.

Referenced by Execute(), PlotStatement(), and ~PlotStatement().

◆ parameter

char* PlotStatement::parameter
private

Definition at line 45 of file plot.h.

Referenced by Execute(), PlotStatement(), and ~PlotStatement().


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