Skip to content

Commit beab124

Browse files
committed
Change all occurrences of String to const char *
This is also to save some memory. See Issue #20
1 parent af9d914 commit beab124

File tree

2 files changed

+77
-77
lines changed

2 files changed

+77
-77
lines changed

plotter/Plotter.cpp

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Plotter::~Plotter()
5656
delete temp;
5757
}
5858

59-
void Plotter::AddGraphHelper( String title, VariableWrapper * wrappers, int sz, bool xvy, int pointsDisplayed )
59+
void Plotter::AddGraphHelper( const char * title, VariableWrapper * wrappers, int sz, bool xvy, int pointsDisplayed )
6060
{
6161
Graph * temp = new Graph( title, wrappers, sz, xvy, pointsDisplayed );
6262
if ( head )
@@ -105,46 +105,46 @@ bool Plotter::Remove( int index )
105105
}
106106
}
107107

108-
bool Plotter::SetColor( int index, String colorA )
108+
bool Plotter::SetColor( int index, const char * colorA )
109109
{
110-
String colors[] = { colorA };
110+
const char * colors[] = { colorA };
111111
return SetColorHelper( index, 1, colors );
112112
}
113113

114-
bool Plotter::SetColor( int index, String colorA, String colorB )
114+
bool Plotter::SetColor( int index, const char * colorA, const char * colorB )
115115
{
116-
String colors[] = { colorA, colorB };
116+
const char * colors[] = { colorA, colorB };
117117
return SetColorHelper( index, 2, colors );
118118
}
119119

120-
bool Plotter::SetColor( int index, String colorA, String colorB, String colorC )
120+
bool Plotter::SetColor( int index, const char * colorA, const char * colorB, const char * colorC )
121121
{
122-
String colors[] = { colorA, colorB, colorC };
122+
const char * colors[] = { colorA, colorB, colorC };
123123
return SetColorHelper( index, 3, colors );
124124
}
125125

126-
bool Plotter::SetColor( int index, String colorA, String colorB, String colorC,
127-
String colorD )
126+
bool Plotter::SetColor( int index, const char * colorA, const char * colorB, const char * colorC,
127+
const char * colorD )
128128
{
129-
String colors[] = { colorA, colorB, colorC, colorD };
129+
const char * colors[] = { colorA, colorB, colorC, colorD };
130130
return SetColorHelper( index, 4, colors );
131131
}
132132

133-
bool Plotter::SetColor( int index, String colorA, String colorB, String colorC,
134-
String colorD, String colorE )
133+
bool Plotter::SetColor( int index, const char * colorA, const char * colorB, const char * colorC,
134+
const char * colorD, const char * colorE )
135135
{
136-
String colors[] = { colorA, colorB, colorC, colorD, colorE };
136+
const char * colors[] = { colorA, colorB, colorC, colorD, colorE };
137137
return SetColorHelper( index, 5, colors );
138138
}
139139

140-
bool Plotter::SetColor( int index, String colorA, String colorB, String colorC,
141-
String colorD, String colorE, String colorF )
140+
bool Plotter::SetColor( int index, const char * colorA, const char * colorB, const char * colorC,
141+
const char * colorD, const char * colorE, const char * colorF )
142142
{
143-
String colors[] = { colorA, colorB, colorC, colorD, colorE, colorF };
143+
const char * colors[] = { colorA, colorB, colorC, colorD, colorE, colorF };
144144
return SetColorHelper( index, 6, colors );
145145
}
146146

147-
bool Plotter::SetColorHelper( int index, int sz, String * colors )
147+
bool Plotter::SetColorHelper( int index, int sz, const char * * colors )
148148
{
149149
if ( numGraphs == 0 || index < 0 || numGraphs <= index )
150150
{
@@ -198,7 +198,7 @@ void Plotter::Plot()
198198

199199
// Graph
200200

201-
Plotter::Graph::Graph( String title, VariableWrapper * wrappers, int size, bool xvy, int pointsDisplayed ) :
201+
Plotter::Graph::Graph( const char * title, VariableWrapper * wrappers, int size, bool xvy, int pointsDisplayed ) :
202202
next( NULL ),
203203
xvy( xvy ),
204204
size( size ),
@@ -256,7 +256,7 @@ void Plotter::Graph::Plot( bool config )
256256
Serial.print( "]}" );
257257
}
258258

259-
bool Plotter::Graph::SetColor( int sz, String * colors )
259+
bool Plotter::Graph::SetColor( int sz, const char * * colors )
260260
{
261261
if ( sz != size && !xvy )
262262
{
@@ -284,14 +284,14 @@ Plotter::VariableWrapper::VariableWrapper() :
284284
deref( NULL )
285285
{}
286286

287-
Plotter::VariableWrapper::VariableWrapper( String label, void * ref, double ( * deref )( void * ), String color ) :
287+
Plotter::VariableWrapper::VariableWrapper( const char * label, void * ref, double ( * deref )( void * ), const char * color ) :
288288
label( label ),
289289
color( color ),
290290
ref( ref ),
291291
deref( deref )
292292
{}
293293

294-
String Plotter::VariableWrapper::GetLabel()
294+
const char * Plotter::VariableWrapper::GetLabel()
295295
{
296296
return label;
297297
}
@@ -301,12 +301,12 @@ double Plotter::VariableWrapper::GetValue()
301301
return deref( ref );
302302
}
303303

304-
String Plotter::VariableWrapper::GetColor()
304+
const char * Plotter::VariableWrapper::GetColor()
305305
{
306306
return color;
307307
}
308308

309-
void Plotter::VariableWrapper::SetColor( String col )
309+
void Plotter::VariableWrapper::SetColor( const char * col )
310310
{
311311
color = col;
312312
}

plotter/Plotter.h

Lines changed: 54 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,16 @@ class Plotter
4141
Add a 1-variable graph vs. time
4242
4343
Args:
44-
- title: String with title of graph
44+
- title: const char * with title of graph
4545
- pointsDisplayed: number of points to be shown at a given time. Used to control time-scaling
46-
- labelA: String with label of the plotted variable
46+
- labelA: const char * with label of the plotted variable
4747
- refA: reference to global variable that will be updated throughout program
4848
4949
Similar methods for multi-variable graphing vs. time are declared below and follow the same format
5050
*/
5151
template <typename A>
52-
void AddTimeGraph( String title, int pointsDisplayed,
53-
String labelA, A & refA )
52+
void AddTimeGraph( const char * title, int pointsDisplayed,
53+
const char * labelA, A & refA )
5454
{
5555
VariableWrapper * wrappers = new VariableWrapper[1];
5656
wrappers[0] = VariableWrapper( labelA, static_cast<void *>( &refA ), &Dereference<A>, "green" );
@@ -61,16 +61,16 @@ class Plotter
6161
Add an X vs. Y graph
6262
6363
Args:
64-
- title: String with title of graph
64+
- title: const char * with title of graph
6565
- pointsDisplayed: number of points to be shown at a given time. Determines duration of data persistance
66-
- labelX: String with label of variable to be plotted along X-axis
66+
- labelX: const char * with label of variable to be plotted along X-axis
6767
- refX: reference to global X-variable that will be updated throughout program
68-
- labelY: String with label of variable to be plotted along Y-axis
68+
- labelY: const char * with label of variable to be plotted along Y-axis
6969
- refY: reference to global Y-variable that will be updated throughout program
7070
*/
7171
template <typename X, typename Y>
72-
void AddXYGraph( String title, int pointsDisplayed,
73-
String labelX, X & refX, String labelY, Y & refY )
72+
void AddXYGraph( const char * title, int pointsDisplayed,
73+
const char * labelX, X & refX, const char * labelY, Y & refY )
7474
{
7575
VariableWrapper * wrappers = new VariableWrapper[2];
7676
wrappers[0] = VariableWrapper( labelX, static_cast<void *>( &refX ), &Dereference<X>, "green" );
@@ -107,12 +107,12 @@ class Plotter
107107
Returns:
108108
- true, if successful
109109
*/
110-
bool SetColor( int index, String colorA );
110+
bool SetColor( int index, const char * colorA );
111111

112112
// Add a 2-variable graph vs. time
113113
template <typename A, typename B>
114-
void AddTimeGraph( String title, int pointsDisplayed,
115-
String labelA, A & refA, String labelB, B & refB )
114+
void AddTimeGraph( const char * title, int pointsDisplayed,
115+
const char * labelA, A & refA, const char * labelB, B & refB )
116116
{
117117
VariableWrapper * wrappers = new VariableWrapper[2];
118118
wrappers[0] = VariableWrapper( labelA, static_cast<void *>( &refA ), &Dereference<A>, "green" );
@@ -122,8 +122,8 @@ class Plotter
122122

123123
// Add a 3-variable graph vs. time
124124
template <typename A, typename B, typename C>
125-
void AddTimeGraph( String title, int pointsDisplayed,
126-
String labelA, A & refA, String labelB, B & refB, String labelC, C & refC )
125+
void AddTimeGraph( const char * title, int pointsDisplayed,
126+
const char * labelA, A & refA, const char * labelB, B & refB, const char * labelC, C & refC )
127127
{
128128
VariableWrapper * wrappers = new VariableWrapper[3];
129129
wrappers[0] = VariableWrapper( labelA, static_cast<void *>( &refA ), &Dereference<A>, "green" );
@@ -134,9 +134,9 @@ class Plotter
134134

135135
// Add a 4-variable graph vs. time
136136
template <typename A, typename B, typename C, typename D>
137-
void AddTimeGraph( String title, int pointsDisplayed,
138-
String labelA, A & refA, String labelB, B & refB, String labelC, C & refC,
139-
String labelD, D & refD )
137+
void AddTimeGraph( const char * title, int pointsDisplayed,
138+
const char * labelA, A & refA, const char * labelB, B & refB, const char * labelC, C & refC,
139+
const char * labelD, D & refD )
140140
{
141141
VariableWrapper * wrappers = new VariableWrapper[4];
142142
wrappers[0] = VariableWrapper( labelA, static_cast<void *>( &refA ), &Dereference<A>, "green");
@@ -148,9 +148,9 @@ class Plotter
148148

149149
// Add a 5-variable graph vs. time
150150
template <typename A, typename B, typename C, typename D, typename E>
151-
void AddTimeGraph( String title, int pointsDisplayed,
152-
String labelA, A & refA, String labelB, B & refB, String labelC, C & refC,
153-
String labelD, D & refD, String labelE, E & refE )
151+
void AddTimeGraph( const char * title, int pointsDisplayed,
152+
const char * labelA, A & refA, const char * labelB, B & refB, const char * labelC, C & refC,
153+
const char * labelD, D & refD, const char * labelE, E & refE )
154154
{
155155
VariableWrapper * wrappers = new VariableWrapper[5];
156156
wrappers[0] = VariableWrapper( labelA, static_cast<void *>( &refA ), &Dereference<A>, "green" );
@@ -163,9 +163,9 @@ class Plotter
163163

164164
// Add a 6-variable graph vs. time
165165
template <typename A, typename B, typename C, typename D, typename E, typename F>
166-
void AddTimeGraph( String title, int pointsDisplayed,
167-
String labelA, A & refA, String labelB, B & refB, String labelC, C & refC,
168-
String labelD, D & refD, String labelE, E & refE, String labelF, F & refF )
166+
void AddTimeGraph( const char * title, int pointsDisplayed,
167+
const char * labelA, A & refA, const char * labelB, B & refB, const char * labelC, C & refC,
168+
const char * labelD, D & refD, const char * labelE, E & refE, const char * labelF, F & refF )
169169
{
170170
VariableWrapper * wrappers = new VariableWrapper[6];
171171
wrappers[0] = VariableWrapper( labelA, static_cast<void *>( &refA ), &Dereference<A>, "green" );
@@ -178,14 +178,14 @@ class Plotter
178178
}
179179

180180
// Set Colors for multivariable graphs
181-
bool SetColor( int index, String colorA, String colorB );
182-
bool SetColor( int index, String colorA, String colorB, String colorC );
183-
bool SetColor( int index, String colorA, String colroB, String colorC,
184-
String colorD );
185-
bool SetColor( int index, String colorA, String colroB, String colorC,
186-
String colorD, String colorE );
187-
bool SetColor( int index, String colorA, String colroB, String colorC,
188-
String colorD, String colorE, String colorF );
181+
bool SetColor( int index, const char * colorA, const char * colorB );
182+
bool SetColor( int index, const char * colorA, const char * colorB, const char * colorC );
183+
bool SetColor( int index, const char * colorA, const char * colroB, const char * colorC,
184+
const char * colorD );
185+
bool SetColor( int index, const char * colorA, const char * colroB, const char * colorC,
186+
const char * colorD, const char * colorE );
187+
bool SetColor( int index, const char * colorA, const char * colroB, const char * colorC,
188+
const char * colorD, const char * colorE, const char * colorF );
189189

190190
// Destructor for Plotter class
191191
~Plotter();
@@ -197,17 +197,17 @@ class Plotter
197197
{
198198
public:
199199
VariableWrapper();
200-
VariableWrapper( String label, void * ref, double ( * deref )( void * ), String color );
200+
VariableWrapper( const char * label, void * ref, double ( * deref )( void * ), const char * color );
201201

202-
String GetLabel();
202+
const char * GetLabel();
203203
double GetValue();
204-
String GetColor();
205-
void SetColor( String col );
204+
const char * GetColor();
205+
void SetColor( const char * col );
206206

207207
private:
208208
// Data
209-
String label;
210-
String color;
209+
const char * label;
210+
const char * color;
211211
void * ref;
212212
double ( * deref )( void * );
213213

@@ -219,10 +219,10 @@ class Plotter
219219
class Graph
220220
{
221221
public:
222-
Graph(String title, VariableWrapper * wrappers, int size, bool xvy, int pointsDisplayed);
222+
Graph(const char * title, VariableWrapper * wrappers, int size, bool xvy, int pointsDisplayed);
223223
~Graph();
224224
void Plot( bool config );
225-
bool SetColor( int sz, String * colors );
225+
bool SetColor( int sz, const char * * colors );
226226

227227
// Data
228228
Graph * next;
@@ -231,15 +231,15 @@ class Plotter
231231
bool xvy;
232232
int size;
233233
int pointsDisplayed;
234-
String title;
234+
const char * title;
235235
VariableWrapper * wrappers;
236236

237237
}; //-- Graph
238238

239239
private:
240240
// Helpers
241-
void AddGraphHelper( String title, VariableWrapper * wrappers, int sz, bool xvy, int pointsDisplayed );
242-
bool SetColorHelper( int index, int sz, String * colors );
241+
void AddGraphHelper( const char * title, VariableWrapper * wrappers, int sz, bool xvy, int pointsDisplayed );
242+
bool SetColorHelper( int index, int sz, const char * * colors );
243243

244244
template <typename T>
245245
static double Dereference( void * ref )
@@ -261,17 +261,17 @@ class Plotter
261261
static const int CONFIG_INTERVAL = 50;
262262

263263
// Transmission Keys
264-
static const String OUTER_KEY = "#";
265-
static const String TIME_KEY = "t";
266-
static const String NUM_GRAPH_KEY = "ng";
267-
static const String LAST_UPDATED_KEY = "lu";
268-
static const String GRAPHS_KEY = "g";
269-
static const String TITLE_KEY = "t";
270-
static const String XVY_KEY = "xvy";
271-
static const String POINTS_DISPLAYED_KEY = "pd";
272-
static const String SIZE_KEY = "sz";
273-
static const String LABELS_KEY = "l";
274-
static const String COLORS_KEY = "c";
275-
static const String DATA_KEY = "d";
264+
static const char * OUTER_KEY = "#";
265+
static const char * TIME_KEY = "t";
266+
static const char * NUM_GRAPH_KEY = "ng";
267+
static const char * LAST_UPDATED_KEY = "lu";
268+
static const char * GRAPHS_KEY = "g";
269+
static const char * TITLE_KEY = "t";
270+
static const char * XVY_KEY = "xvy";
271+
static const char * POINTS_DISPLAYED_KEY = "pd";
272+
static const char * SIZE_KEY = "sz";
273+
static const char * LABELS_KEY = "l";
274+
static const char * COLORS_KEY = "c";
275+
static const char * DATA_KEY = "d";
276276

277277
#endif

0 commit comments

Comments
 (0)