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