Jpp 19.3.0-rc.3
the software that should make you happy
Loading...
Searching...
No Matches
JEquationParameters.hh
Go to the documentation of this file.
1#ifndef __JLANG__JEQUATIONPARAMETERS__
2#define __JLANG__JEQUATIONPARAMETERS__
3
4#include <string>
5
6
7/**
8 * \author mdejong
9 */
10
11namespace JLANG {}
12namespace JPP { using namespace JLANG; }
13
14namespace JLANG {
15
16
17 /**
18 * Simple data structure to support I/O of equations (see class JLANG::JEquation).
19 */
21 public:
22 /**
23 * Default constructor.
24 */
26 {
27 this->sep = "=";
28 this->eol = "\n\r;";
29 this->div = "./";
30 this->skip = "#";
31 this->left = '(';
32 this->right = ')';
33 this->ws = " \t\n\v\f\r";
34 this->comment = "";
35 }
36
37
38 /**
39 * Constructor.
40 *
41 * \param sep separator characters
42 * \param eol end of line characters
43 * \param div division characters
44 * \param skip skip line characters
45 * \param left left bracket
46 * \param right right bracket
47 * \param ws white space characters
48 * \param comment inline comment characters
49 */
50 JEquationParameters(const std::string& sep,
51 const std::string& eol,
52 const std::string& div,
53 const std::string& skip,
54 const char left = '(',
55 const char right = ')',
56 const std::string& ws = " \t\n\v\f\r",
57 const std::string& comment = "")
58 {
59 this->sep = sep;
60 this->eol = eol;
61 this->div = div;
62 this->skip = skip;
63 this->left = left;
64 this->right = right;
65 this->ws = ws;
66 this->comment = comment;
67 }
68
69
70 /**
71 * Get equation parameters.
72 *
73 * \return equation parameters
74 */
76 {
77 return *this;
78 }
79
80
81 /**
82 * Set equation parameters.
83 *
84 * \param buffer equation parameters
85 */
87 {
88 static_cast<JEquationParameters&>(*this) = buffer;
89 }
90
91
92 /**
93 * Get default separator character.
94 *
95 * \return separator between parameter and its value
96 */
97 const char getDefaultSeparator() const
98 {
99 if (sep.empty())
100 return '=';
101 else
102 return sep[0];
103 }
104
105
106 /**
107 * Get separator characters.
108 *
109 * \return separator between parameter and its value
110 */
111 const std::string& getSeparator() const
112 {
113 return sep;
114 }
115
116
117 /**
118 * Get separator characters.
119 *
120 * \return separator between parameter and its value
121 */
122 std::string& getSeparator()
123 {
124 return sep;
125 }
126
127
128 /**
129 * Set separator character(s).
130 *
131 * \param sep separator between parameter and its value
132 */
133 void setSeparator(const std::string& sep)
134 {
135 this->sep = sep;
136 }
137
138
139 /**
140 * Get default end of line character.
141 *
142 * \return end of line character
143 */
144 const char getDefaultEndOfLine() const
145 {
146 if (eol.empty())
147 return '\n';
148 else
149 return eol[0];
150 }
151
152
153 /**
154 * Get preferred end of line character.
155 *
156 * \param index index
157 * \return end of line character
158 */
159 const char getPreferredEndOfLine(const unsigned int index) const
160 {
161 if (eol.empty())
162 return '\n';
163 else if (index < eol.size())
164 return eol[index];
165 else
166 return eol[0];
167 }
168
169
170 /**
171 * Get end of line characters.
172 *
173 * \return end of line characters
174 */
175 const std::string& getEndOfLine() const
176 {
177 return eol;
178 }
179
180
181 /**
182 * Get end of line characters.
183 *
184 * \return end of line characters
185 */
186 std::string& getEndOfLine()
187 {
188 return eol;
189 }
190
191
192 /**
193 * Set end of line characters.
194 *
195 * \param eol end of line character
196 */
197 void setEndOfLine(const std::string& eol)
198 {
199 this->eol = eol;
200 }
201
202
203 /**
204 * Get default division character.
205 *
206 * \return division character
207 */
208 const char getDefaultDivision() const
209 {
210 if (div.empty())
211 return '.';
212 else
213 return div[0];
214 }
215
216
217 /**
218 * Get division characters.
219 *
220 * \return division characters
221 */
222 const std::string& getDivision() const
223 {
224 return div;
225 }
226
227
228 /**
229 * Get division characters.
230 *
231 * \return division characters
232 */
233 std::string& getDivision()
234 {
235 return div;
236 }
237
238
239 /**
240 * Set division characters.
241 *
242 * \param div division characters
243 */
244 void setDivision(const std::string& div)
245 {
246 this->div = div;
247 }
248
249
250 /**
251 * Get default skip line character.
252 *
253 * \return skip line character
254 */
255 const char getDefaultSkipLine() const
256 {
257 if (skip.empty())
258 return '#';
259 else
260 return skip[0];
261 }
262
263
264 /**
265 * Get skip line characters.
266 *
267 * \return skip line characters
268 */
269 const std::string& getSkipLine() const
270 {
271 return skip;
272 }
273
274
275 /**
276 * Get skip line characters.
277 *
278 * \return skip line characters
279 */
280 std::string& getSkipLine()
281 {
282 return skip;
283 }
284
285
286 /**
287 * Set skip line characters.
288 *
289 * \param skip skip line characters
290 */
291 void setSkipLine(const std::string& skip)
292 {
293 this->skip = skip;
294 }
295
296
297 /**
298 * Set brackets.
299 *
300 * \param left left bracket
301 * \param right right bracket
302 */
303 void setBrackets(const char left, const char right)
304 {
305 this->left = left;
306 this->right = right;
307 }
308
309
310 /**
311 * Get left bracket.
312 *
313 * \return left bracket
314 */
315 char getLeftBracket() const
316 {
317 return left;
318 }
319
320
321 /**
322 * Get left bracket.
323 *
324 * \return left bracket
325 */
327 {
328 return left;
329 }
330
331
332 /**
333 * Get right bracket.
334 *
335 * \return right bracket
336 */
337 char getRightBracket() const
338 {
339 return right;
340 }
341
342
343 /**
344 * Get right bracket.
345 *
346 * \return right bracket
347 */
349 {
350 return right;
351 }
352
353
354 /**
355 * Get default white space character.
356 *
357 * \return white space character
358 */
359 const char getDefaultWhiteSpace() const
360 {
361 if (ws.empty())
362 return ' ';
363 else
364 return ws[0];
365 }
366
367
368 /**
369 * Get white space characters.
370 *
371 * \return white space characters
372 */
373 const std::string& getWhiteSpace() const
374 {
375 return ws;
376 }
377
378
379 /**
380 * Get white space characters.
381 *
382 * \return white space characters
383 */
384 std::string& getWhiteSpace()
385 {
386 return ws;
387 }
388
389
390 /**
391 * Set white space characters.
392 *
393 * \param ws white space characters
394 */
395 void setWhiteSpace(const std::string& ws)
396 {
397 this->ws = ws;
398 }
399
400
401 /**
402 * Get comment string.
403 *
404 * \return comment string
405 */
406 const std::string& getComment() const
407 {
408 return comment;
409 }
410
411
412 /**
413 * Get comment string.
414 *
415 * \return comment string
416 */
417 std::string& getComment()
418 {
419 return comment;
420 }
421
422
423 /**
424 * Set comment string.
425 *
426 * \param comment comment string
427 */
428 void setComment(const std::string& comment)
429 {
430 this->comment = comment;
431 }
432
433
434 /**
435 * Join equation parameters.
436 *
437 * \param value equation parameters
438 */
440 {
441 using namespace std;
442
443 for (string::const_iterator i = value.sep.begin(); i != value.sep.end(); ++i) {
444 if (!isSeparator(*i)) {
445 sep += *i;
446 }
447 }
448
449 for (string::const_iterator i = value.eol.begin(); i != value.eol.end(); ++i) {
450 if (!isEndOfLine(*i)) {
451 eol += *i;
452 }
453 }
454
455 for (string::const_iterator i = value.div.begin(); i != value.div.end(); ++i) {
456 if (!isDivision(*i)) {
457 div += *i;
458 }
459 }
460
461 for (string::const_iterator i = value.skip.begin(); i != value.skip.end(); ++i) {
462 if (!isSkipLine(*i)) {
463 skip += *i;
464 }
465 }
466
467 for (string::const_iterator i = value.ws.begin(); i != value.ws.end(); ++i) {
468 if (!isWhiteSpace(*i)) {
469 ws += *i;
470 }
471 }
472
473 return *this;
474 }
475
476
477 /**
478 * Test for separator character.
479 *
480 * \param c character
481 * \result true if separator; else false
482 */
483 inline bool isSeparator(const char c) const
484 {
485 return sep .find(c) != std::string::npos;
486 }
487
488
489 /**
490 * Test for end of line character.
491 *
492 * \param c character
493 * \result true if end of line; else false
494 */
495 inline bool isEndOfLine (const char c) const { return eol .find(c) != std::string::npos; }
496
497
498 /**
499 * Test for division character.
500 *
501 * \param c character
502 * \result true if division; else false
503 */
504 inline bool isDivision(const char c) const
505 {
506 return div .find(c) != std::string::npos;
507 }
508
509
510 /**
511 * Test for skip line character.
512 *
513 * \param c character
514 * \result true if skip line; else false
515 */
516 inline bool isSkipLine(const char c) const
517 {
518 return skip.find(c) != std::string::npos;
519 }
520
521
522 /**
523 * Test for left bracket character.
524 *
525 * \param c character
526 * \result true if left bracket; else false
527 */
528 inline bool isLeftBracket(const char c) const
529 {
530 return c == left;
531 }
532
533
534 /**
535 * Test for right bracket character.
536 *
537 * \param c character
538 * \result true if right bracket; else false
539 */
540 inline bool isRightBracket(const char c) const
541 {
542 return c == right;
543 }
544
545
546 /**
547 * Test for white space character.
548 *
549 * \param c character
550 * \result true if white space; else false
551 */
552 inline bool isWhiteSpace(const char c) const
553 {
554 return ws .find(c) != std::string::npos;
555 }
556
557 protected:
558 std::string sep;
559 std::string eol;
560 std::string div;
561 std::string skip;
562 char left;
563 char right;
564 std::string ws;
565 std::string comment;
566 };
567}
568
569#endif
Simple data structure to support I/O of equations (see class JLANG::JEquation).
char & getRightBracket()
Get right bracket.
std::string & getSeparator()
Get separator characters.
std::string & getDivision()
Get division characters.
const std::string & getSkipLine() const
Get skip line characters.
const char getDefaultSkipLine() const
Get default skip line character.
const JEquationParameters & getEquationParameters() const
Get equation parameters.
JEquationParameters(const std::string &sep, const std::string &eol, const std::string &div, const std::string &skip, const char left='(', const char right=')', const std::string &ws=" \t\n\v\f\r", const std::string &comment="")
Constructor.
bool isSeparator(const char c) const
Test for separator character.
const std::string & getComment() const
Get comment string.
void setBrackets(const char left, const char right)
Set brackets.
const std::string & getEndOfLine() const
Get end of line characters.
void setEquationParameters(const JEquationParameters &buffer)
Set equation parameters.
bool isDivision(const char c) const
Test for division character.
void setWhiteSpace(const std::string &ws)
Set white space characters.
const char getDefaultSeparator() const
Get default separator character.
const std::string & getSeparator() const
Get separator characters.
JEquationParameters & join(const JEquationParameters &value)
Join equation parameters.
bool isEndOfLine(const char c) const
Test for end of line character.
void setSeparator(const std::string &sep)
Set separator character(s).
void setDivision(const std::string &div)
Set division characters.
std::string & getWhiteSpace()
Get white space characters.
char & getLeftBracket()
Get left bracket.
const char getDefaultEndOfLine() const
Get default end of line character.
char getLeftBracket() const
Get left bracket.
std::string & getEndOfLine()
Get end of line characters.
void setComment(const std::string &comment)
Set comment string.
bool isRightBracket(const char c) const
Test for right bracket character.
bool isSkipLine(const char c) const
Test for skip line character.
void setSkipLine(const std::string &skip)
Set skip line characters.
std::string & getComment()
Get comment string.
JEquationParameters()
Default constructor.
bool isLeftBracket(const char c) const
Test for left bracket character.
void setEndOfLine(const std::string &eol)
Set end of line characters.
const char getDefaultWhiteSpace() const
Get default white space character.
char getRightBracket() const
Get right bracket.
const char getPreferredEndOfLine(const unsigned int index) const
Get preferred end of line character.
const std::string & getDivision() const
Get division characters.
const std::string & getWhiteSpace() const
Get white space characters.
bool isWhiteSpace(const char c) const
Test for white space character.
std::string & getSkipLine()
Get skip line characters.
const char getDefaultDivision() const
Get default division character.
Auxiliary classes and methods for language specific functionality.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).