Numworks Epsilon  1.4.1
Graphing Calculator Operating System
console_store.h
Go to the documentation of this file.
1 #ifndef CODE_CONSOLE_STORE_H
2 #define CODE_CONSOLE_STORE_H
3 
4 #include "console_line.h"
5 #include <stddef.h>
6 
7 namespace Code {
8 
9 class ConsoleStore {
10 public:
11  ConsoleStore();
12  void clear();
13  void startNewSession();
14  ConsoleLine lineAtIndex(int i) const;
15  int numberOfLines() const;
16  void pushCommand(const char * text, size_t length);
17  void pushResult(const char * text, size_t length);
18  void deleteLastLineIfEmpty();
19  int deleteCommandAndResultsAtIndex(int index);
20 private:
21  static constexpr char CurrentSessionCommandMarker = 0x01;
22  static constexpr char CurrentSessionResultMarker = 0x02;
23  static constexpr char PreviousSessionCommandMarker = 0x03;
24  static constexpr char PreviousSessionResultMarker = 0x04;
25  static constexpr int k_historySize = 1024;
26  static char makePrevious(char marker) {
27  if (marker == CurrentSessionCommandMarker || marker == CurrentSessionResultMarker) {
28  return marker + 0x02;
29  }
30  return marker;
31  }
32  void push(const char marker, const char * text, size_t length);
33  ConsoleLine::Type lineTypeForMarker(char marker) const;
34  int indexOfNullMarker() const;
35  void deleteLineAtIndex(int index);
36  void deleteFirstLine();
37  /* When there is no room left to store a new ConsoleLine, we have to delete
38  * old ConsoleLines. deleteFirstLine() deletes the first ConsoleLine of
39  * m_history and shifts the rest of the ConsoleLines towards the beginning of
40  * m_history. */
41  void deleteLastLine();
42  char m_history[k_historySize];
43  /* The m_history variable sequentially stores an array of ConsoleLine objects.
44  * Each ConsoleLine is stored as follow:
45  * - First, a char that says whether the ConsoleLine is a Command or a Result
46  * - Then, the text content of the ConsoleLine
47  * - Last but not least, a null byte.
48  * The buffer ends whenever the marker char is null. */
49 };
50 
51 }
52 
53 #endif
int deleteCommandAndResultsAtIndex(int index)
int numberOfLines() const
Definition: app.cpp:7
void pushCommand(const char *text, size_t length)
void pushResult(const char *text, size_t length)
ConsoleLine lineAtIndex(int i) const