amath  1.8.5
Simple command line calculator
StandardConsole Class Reference

Encapsulates the IO of a Standard C console. More...

#include <console_stdc.h>

Inheritance diagram for StandardConsole:
Collaboration diagram for StandardConsole:

Public Member Functions

 StandardConsole (const char *prompt)
 
virtual ~StandardConsole ()
 
virtual void Start ()
 
virtual void Exit ()
 
virtual void SetPrompt (const char *string)
 
virtual void WriteString (const char *string)
 
virtual bool SetAnsiMode (bool value)
 
- Public Member Functions inherited from ConsoleBase
 ConsoleBase (const char *prompt)
 
virtual ~ConsoleBase ()
 
const char * GetName ()
 
virtual bool Open ()
 
virtual void Close ()
 
virtual void Clear ()
 
virtual void ShowHelp ()
 
virtual void ShowAbout ()
 
virtual void ShowLicense ()
 
virtual void ShowVersion ()
 
virtual void ResetConsole ()
 

Private Member Functions

void ReadLine ()
 

Private Attributes

bool exit
 
char * line
 

Static Private Attributes

static const unsigned int linesize = 1024
 

Additional Inherited Members

- Protected Member Functions inherited from ConsoleBase
virtual void StartMessage ()
 
void Prompt ()
 
const char * GetVersionText ()
 
const char * GetCompilerText ()
 
- Protected Attributes inherited from ConsoleBase
char * prompt
 
bool ansiMode
 

Detailed Description

Encapsulates the IO of a Standard C console.

Definition at line 48 of file console_stdc.h.

Constructor & Destructor Documentation

◆ StandardConsole()

StandardConsole::StandardConsole ( const char *  prompt)
explicit

Definition at line 37 of file console_stdc.cpp.

37  :
38  ConsoleBase(prompt), exit(false)
39 {
40  line = new char[linesize];
41 }
char * prompt
Definition: console.h:68
ConsoleBase(const char *prompt)
Definition: console.cpp:75
static const unsigned int linesize
Definition: console_stdc.h:63

◆ ~StandardConsole()

StandardConsole::~StandardConsole ( )
virtual

Definition at line 43 of file console_stdc.cpp.

44 {
45  delete line;
46 }

Member Function Documentation

◆ Exit()

void StandardConsole::Exit ( )
virtual

Implements ConsoleBase.

Definition at line 78 of file console_stdc.cpp.

79 {
80  exit = true;
81 }

◆ ReadLine()

void StandardConsole::ReadLine ( )
private

Definition at line 83 of file console_stdc.cpp.

84 {
85  fflush(stdin);
86  fgets(line, linesize, stdin);
87 }
static const unsigned int linesize
Definition: console_stdc.h:63

◆ SetAnsiMode()

bool StandardConsole::SetAnsiMode ( bool  value)
virtual

Reimplemented from ConsoleBase.

Definition at line 48 of file console_stdc.cpp.

49 {
50  return false;
51 }

◆ SetPrompt()

void StandardConsole::SetPrompt ( const char *  string)
virtual

Reimplemented from ConsoleBase.

Definition at line 95 of file console_stdc.cpp.

96 {
97  ConsoleBase::SetPrompt(string);
98 }
virtual void SetPrompt(const char *string)
Definition: console.cpp:214

◆ Start()

void StandardConsole::Start ( )
virtual

Implements ConsoleBase.

Definition at line 53 of file console_stdc.cpp.

54 {
55  exit = false;
56  fflush(stdin);
57  StartMessage();
58 
59  while (!exit)
60  {
61  Prompt();
62  ReadLine();
63 
64  if (*line == '\0')
65  {
66  break;
67  }
68 
69  Evaluator* evaluator = new Evaluator(line);
70  evaluator->Evaluate();
71  const char* out = evaluator->GetResult();
72  WriteString(out);
73  ResetConsole();
74  delete evaluator;
75  }
76 }
char * GetResult() const
Definition: evaluator.cpp:91
virtual void ResetConsole()
Definition: console.cpp:115
void Prompt()
Definition: console.cpp:207
virtual void WriteString(const char *string)
void Evaluate() const
Definition: evaluator.cpp:50
virtual void StartMessage()
Definition: console.cpp:201

◆ WriteString()

void StandardConsole::WriteString ( const char *  string)
virtual

Implements ConsoleBase.

Definition at line 89 of file console_stdc.cpp.

90 {
91  fputs(string, stdout);
92  fflush(stdout);
93 }

Member Data Documentation

◆ exit

bool StandardConsole::exit
private

Definition at line 61 of file console_stdc.h.

◆ line

char* StandardConsole::line
private

Definition at line 62 of file console_stdc.h.

◆ linesize

const unsigned int StandardConsole::linesize = 1024
staticprivate

Definition at line 63 of file console_stdc.h.


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