Snorktracker
 All Data Structures Files Functions Variables Macros Pages
Public Member Functions | Data Fields
StringList Class Reference

#include <StringList.h>

Public Member Functions

bool isEmpty ()
 
int count ()
 
int rolledOut ()
 
void removeAll ()
 
String getAt (int idx)
 
void addTail (String newInfo)
 
String removeHead ()
 
String removeTail ()
 

Data Fields

String infos
 All the items in one string.
 
int infosCount
 Number of items in the list.
 
int infosRolledOut
 Number of items rolled out.
 

Detailed Description

String List class. Internally all items are stored in one string with '\1' as separator. The list has a maximum internal storage. While appending items it deletes automatically from the beginning until it fits. The performance could be optimized.

Definition at line 34 of file StringList.h.

Member Function Documentation

void StringList::addTail ( String  newInfo)

Append one item at the end of the list. If the list-string is too big then first items are deleted until it fits.

Definition at line 112 of file StringList.h.

References infos, infosCount, MAX_LOG_INFOS_SIZE, and removeHead().

Referenced by MyWebServer::handleLoadConsoleInfo(), myDebugInfo(), MySerial::read(), and MySerial::write().

113 {
114  while (infos.length() + newInfo.length() + 1 > MAX_LOG_INFOS_SIZE) {
115  removeHead();
116  }
117  infos += newInfo;
118  infos += '\1';
119  infosCount++;
120 }
String removeHead()
Definition: StringList.h:123
#define MAX_LOG_INFOS_SIZE
Maximum bytes of the complete list items + separators.
Definition: StringList.h:25
int infosCount
Number of items in the list.
Definition: StringList.h:38
String infos
All the items in one string.
Definition: StringList.h:37
int StringList::count ( )

How many items are in the list?

Definition at line 72 of file StringList.h.

References infosCount.

Referenced by MyWebServer::handleLoadConsoleInfo().

73 {
74  return infosCount;
75 }
int infosCount
Number of items in the list.
Definition: StringList.h:38
String StringList::getAt ( int  idx)

Returns the n'th item from the list.

Definition at line 92 of file StringList.h.

References infos.

Referenced by MyWebServer::handleLoadConsoleInfo().

93 {
94  int currIdx = 0;
95  int lastPos = 0;
96 
97  for(int i = 0; i < infos.length(); i++) {
98  if (infos[i] == '\1') {
99  if (currIdx == idx) {
100  return infos.substring(lastPos, i);
101  }
102  lastPos = i + 1;
103  currIdx++;
104  }
105  }
106  return "";
107 }
String infos
All the items in one string.
Definition: StringList.h:37
bool StringList::isEmpty ( )

Is the list empty?

Definition at line 66 of file StringList.h.

References infosCount.

Referenced by loop().

67 {
68  return infosCount == 0;
69 }
int infosCount
Number of items in the list.
Definition: StringList.h:38
void StringList::removeAll ( )

Removes all items from the list.

Definition at line 84 of file StringList.h.

References infos, infosCount, and infosRolledOut.

Referenced by MyWebServer::loadConsole().

85 {
86  infos = "";
87  infosCount = 0;
88  infosRolledOut = 0;
89 }
int infosRolledOut
Number of items rolled out.
Definition: StringList.h:39
int infosCount
Number of items in the list.
Definition: StringList.h:38
String infos
All the items in one string.
Definition: StringList.h:37
String StringList::removeHead ( )

Remove the first item from the list.

Definition at line 123 of file StringList.h.

References infos, infosCount, and infosRolledOut.

Referenced by addTail(), and loop().

124 {
125  String ret;
126  int idx = infos.indexOf('\1');
127 
128  if (idx != -1) {
129  ret = infos.substring(0, idx);
130  infos = infos.substring(idx + 1);
131  infosCount--;
132  infosRolledOut++;
133  }
134  return ret;
135 }
int infosRolledOut
Number of items rolled out.
Definition: StringList.h:39
int infosCount
Number of items in the list.
Definition: StringList.h:38
String infos
All the items in one string.
Definition: StringList.h:37
String StringList::removeTail ( )

Removes the last item from the list.

Definition at line 138 of file StringList.h.

References infos, and infosCount.

Referenced by myDebugInfo().

139 {
140  String ret;
141 
142  for (int i = infos.length() - 1; i >= 0; i--) {
143  if (infos[i] == '\1') {
144  ret = infos.substring(i + 1);
145  infos = infos.substring(0, i);
146  infosCount--;
147  break;
148  }
149  }
150  return ret;
151 }
int infosCount
Number of items in the list.
Definition: StringList.h:38
String infos
All the items in one string.
Definition: StringList.h:37
int StringList::rolledOut ( )

How many items are in the list?

Definition at line 78 of file StringList.h.

References infosRolledOut.

Referenced by MyWebServer::handleLoadConsoleInfo().

79 {
80  return infosRolledOut;
81 }
int infosRolledOut
Number of items rolled out.
Definition: StringList.h:39

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