Jpp 20.0.0-195-g190c9e876
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 * Auxiliary data structure to handle I/O of escape characters.
24 */
25 struct string_type :
26 public std::string
27 {
28 /**
29 * Read string from imput stream.
30 *
31 * \param in input stream
32 * \param object string
33 * \return input stream
34 */
35 friend inline std::istream& operator>>(std::istream& in, string_type& object)
36 {
37 in >> static_cast<std::string&>(object);
38
39 object.translate();
40
41 return in;
42 }
43
44
45 /**
46 * Assigment operator.
47 *
48 * \param buffer string
49 * \return this string
50 */
51 string_type& operator=(const std::string& buffer)
52 {
53 static_cast<std::string&>(*this) = buffer;
54
55 translate();
56
57 return *this;
58 }
59
60
61 /**
62 * Translate escape characters.
63 */
64 void translate()
65 {
66 iterator out = this->begin();
67
68 for (const_iterator p = this->begin(); p != this->end(); ++p, ++out) {
69
70 if (*p == '\\') {
71
72 if (++p != this->end()) {
73
74 switch (*p) {
75 case 'a': *out = '\a'; break;
76 case 'b': *out = '\b'; break;
77 case 'e': *out = '\e'; break;
78 case 'f': *out = '\f'; break;
79 case 'n': *out = '\n'; break;
80 case 'r': *out = '\r'; break;
81 case 't': *out = '\t'; break;
82 case 'v': *out = '\v'; break;
83 }
84 }
85
86 } else {
87
88 *out = *p;
89 }
90 }
91
92 this->erase(out, this->end());
93 }
94 };
95
96
97 /**
98 * Default constructor.
99 */
101 {
102 this->sep = "=";
103 this->eol = "\n;";
104 this->div = "./";
105 this->skip = "#";
106 this->left = '(';
107 this->right = ')';
108 this->ws = " \t\n\v\f\r";
109 this->comment = "";
110 }
111
112
113 /**
114 * Constructor.
115 *
116 * \param sep separator characters
117 * \param eol end of line characters
118 * \param div division characters
119 * \param skip skip line characters
120 * \param left left bracket
121 * \param right right bracket
122 * \param ws white space characters
123 * \param comment inline comment characters
124 */
125 JEquationParameters(const std::string& sep,
126 const std::string& eol,
127 const std::string& div,
128 const std::string& skip,
129 const char left = '(',
130 const char right = ')',
131 const std::string& ws = " \t\n\v\f\r",
132 const std::string& comment = "")
133 {
134 this->sep = sep;
135 this->eol = eol;
136 this->div = div;
137 this->skip = skip;
138 this->left = left;
139 this->right = right;
140 this->ws = ws;
141 this->comment = comment;
142 }
143
144
145 /**
146 * Get equation parameters.
147 *
148 * \return equation parameters
149 */
151 {
152 return *this;
153 }
154
155
156 /**
157 * Set equation parameters.
158 *
159 * \param buffer equation parameters
160 */
162 {
163 static_cast<JEquationParameters&>(*this) = buffer;
164 }
165
166
167 /**
168 * Get default separator character.
169 *
170 * \return separator between parameter and its value
171 */
172 const char getDefaultSeparator() const
173 {
174 if (sep.empty())
175 return '=';
176 else
177 return sep[0];
178 }
179
180
181 /**
182 * Get separator characters.
183 *
184 * \return separator between parameter and its value
185 */
186 const std::string& getSeparator() const
187 {
188 return sep;
189 }
190
191
192 /**
193 * Get separator characters.
194 *
195 * \return separator between parameter and its value
196 */
197 std::string& getSeparator()
198 {
199 return sep;
200 }
201
202
203 /**
204 * Set separator character(s).
205 *
206 * \param sep separator between parameter and its value
207 */
208 void setSeparator(const std::string& sep)
209 {
210 this->sep = sep;
211 }
212
213
214 /**
215 * Get default end of line character.
216 *
217 * \return end of line character
218 */
219 const char getDefaultEndOfLine() const
220 {
221 if (eol.empty())
222 return '\n';
223 else
224 return eol[0];
225 }
226
227
228 /**
229 * Get preferred end of line character.
230 *
231 * \param index index
232 * \return end of line character
233 */
234 const char getPreferredEndOfLine(const unsigned int index) const
235 {
236 if (eol.empty())
237 return '\n';
238 else if (index < eol.size())
239 return eol[index];
240 else
241 return eol[0];
242 }
243
244
245 /**
246 * Get end of line characters.
247 *
248 * \return end of line characters
249 */
251 {
252 return eol;
253 }
254
255
256 /**
257 * Get end of line characters.
258 *
259 * \return end of line characters
260 */
262 {
263 return eol;
264 }
265
266
267 /**
268 * Set end of line characters.
269 *
270 * \param eol end of line character
271 */
272 void setEndOfLine(const std::string& eol)
273 {
274 this->eol = eol;
275 }
276
277
278 /**
279 * Get default division character.
280 *
281 * \return division character
282 */
283 const char getDefaultDivision() const
284 {
285 if (div.empty())
286 return '.';
287 else
288 return div[0];
289 }
290
291
292 /**
293 * Get division characters.
294 *
295 * \return division characters
296 */
297 const std::string& getDivision() const
298 {
299 return div;
300 }
301
302
303 /**
304 * Get division characters.
305 *
306 * \return division characters
307 */
308 std::string& getDivision()
309 {
310 return div;
311 }
312
313
314 /**
315 * Set division characters.
316 *
317 * \param div division characters
318 */
319 void setDivision(const std::string& div)
320 {
321 this->div = div;
322 }
323
324
325 /**
326 * Get default skip line character.
327 *
328 * \return skip line character
329 */
330 const char getDefaultSkipLine() const
331 {
332 if (skip.empty())
333 return '#';
334 else
335 return skip[0];
336 }
337
338
339 /**
340 * Get skip line characters.
341 *
342 * \return skip line characters
343 */
344 const std::string& getSkipLine() const
345 {
346 return skip;
347 }
348
349
350 /**
351 * Get skip line characters.
352 *
353 * \return skip line characters
354 */
355 std::string& getSkipLine()
356 {
357 return skip;
358 }
359
360
361 /**
362 * Set skip line characters.
363 *
364 * \param skip skip line characters
365 */
366 void setSkipLine(const std::string& skip)
367 {
368 this->skip = skip;
369 }
370
371
372 /**
373 * Set brackets.
374 *
375 * \param left left bracket
376 * \param right right bracket
377 */
378 void setBrackets(const char left, const char right)
379 {
380 this->left = left;
381 this->right = right;
382 }
383
384
385 /**
386 * Get left bracket.
387 *
388 * \return left bracket
389 */
390 char getLeftBracket() const
391 {
392 return left;
393 }
394
395
396 /**
397 * Get left bracket.
398 *
399 * \return left bracket
400 */
402 {
403 return left;
404 }
405
406
407 /**
408 * Get right bracket.
409 *
410 * \return right bracket
411 */
412 char getRightBracket() const
413 {
414 return right;
415 }
416
417
418 /**
419 * Get right bracket.
420 *
421 * \return right bracket
422 */
424 {
425 return right;
426 }
427
428
429 /**
430 * Get default white space character.
431 *
432 * \return white space character
433 */
434 const char getDefaultWhiteSpace() const
435 {
436 if (ws.empty())
437 return ' ';
438 else
439 return ws[0];
440 }
441
442
443 /**
444 * Get white space characters.
445 *
446 * \return white space characters
447 */
449 {
450 return ws;
451 }
452
453
454 /**
455 * Get white space characters.
456 *
457 * \return white space characters
458 */
460 {
461 return ws;
462 }
463
464
465 /**
466 * Set white space characters.
467 *
468 * \param ws white space characters
469 */
470 void setWhiteSpace(const std::string& ws)
471 {
472 this->ws = ws;
473 }
474
475
476 /**
477 * Get comment string.
478 *
479 * \return comment string
480 */
481 const std::string& getComment() const
482 {
483 return comment;
484 }
485
486
487 /**
488 * Get comment string.
489 *
490 * \return comment string
491 */
492 std::string& getComment()
493 {
494 return comment;
495 }
496
497
498 /**
499 * Set comment string.
500 *
501 * \param comment comment string
502 */
503 void setComment(const std::string& comment)
504 {
505 this->comment = comment;
506 }
507
508
509 /**
510 * Join equation parameters.
511 *
512 * \param value equation parameters
513 */
515 {
516 using namespace std;
517
518 for (string::const_iterator i = value.sep.begin(); i != value.sep.end(); ++i) {
519 if (!isSeparator(*i)) {
520 sep += *i;
521 }
522 }
523
524 for (string::const_iterator i = value.eol.begin(); i != value.eol.end(); ++i) {
525 if (!isEndOfLine(*i)) {
526 eol += *i;
527 }
528 }
529
530 for (string::const_iterator i = value.div.begin(); i != value.div.end(); ++i) {
531 if (!isDivision(*i)) {
532 div += *i;
533 }
534 }
535
536 for (string::const_iterator i = value.skip.begin(); i != value.skip.end(); ++i) {
537 if (!isSkipLine(*i)) {
538 skip += *i;
539 }
540 }
541
542 for (string::const_iterator i = value.ws.begin(); i != value.ws.end(); ++i) {
543 if (!isWhiteSpace(*i)) {
544 ws += *i;
545 }
546 }
547
548 return *this;
549 }
550
551
552 /**
553 * Test for separator character.
554 *
555 * \param c character
556 * \result true if separator; else false
557 */
558 inline bool isSeparator(const char c) const
559 {
560 return sep .find(c) != std::string::npos;
561 }
562
563
564 /**
565 * Test for end of line character.
566 *
567 * \param c character
568 * \result true if end of line; else false
569 */
570 inline bool isEndOfLine (const char c) const { return eol .find(c) != std::string::npos; }
571
572
573 /**
574 * Test for division character.
575 *
576 * \param c character
577 * \result true if division; else false
578 */
579 inline bool isDivision(const char c) const
580 {
581 return div .find(c) != std::string::npos;
582 }
583
584
585 /**
586 * Test for skip line character.
587 *
588 * \param c character
589 * \result true if skip line; else false
590 */
591 inline bool isSkipLine(const char c) const
592 {
593 return skip.find(c) != std::string::npos;
594 }
595
596
597 /**
598 * Test for left bracket character.
599 *
600 * \param c character
601 * \result true if left bracket; else false
602 */
603 inline bool isLeftBracket(const char c) const
604 {
605 return c == left;
606 }
607
608
609 /**
610 * Test for right bracket character.
611 *
612 * \param c character
613 * \result true if right bracket; else false
614 */
615 inline bool isRightBracket(const char c) const
616 {
617 return c == right;
618 }
619
620
621 /**
622 * Test for white space character.
623 *
624 * \param c character
625 * \result true if white space; else false
626 */
627 inline bool isWhiteSpace(const char c) const
628 {
629 return ws .find(c) != std::string::npos;
630 }
631
632 protected:
633 std::string sep;
635 std::string div;
636 std::string skip;
637 char left;
638 char right;
640 std::string comment;
641 };
642}
643
644#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.
string_type & getWhiteSpace()
Get white space 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.
string_type & getEndOfLine()
Get end of line characters.
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.
char & getLeftBracket()
Get left bracket.
const char getDefaultEndOfLine() const
Get default end of line character.
char getLeftBracket() const
Get left bracket.
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 string_type & getEndOfLine() const
Get 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 string_type & 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).
Auxiliary data structure to handle I/O of escape characters.
friend std::istream & operator>>(std::istream &in, string_type &object)
Read string from imput stream.
void translate()
Translate escape characters.
string_type & operator=(const std::string &buffer)
Assigment operator.