Jpp 20.0.0-195-g190c9e876
the software that should make you happy
Loading...
Searching...
No Matches
JLANG::JEquation Class Reference

General purpose equation class. More...

#include <JEquation.hh>

Inheritance diagram for JLANG::JEquation:
JLANG::JEquation_t

Classes

struct  equation_type
 Auxiliary data structure for equation. More...
 

Public Member Functions

 JEquation ()
 Default constructor.
 
 JEquation (const std::string &key, const std::string &value)
 Constructor.
 
 JEquation (const std::string &buffer, const JEquationFacet &facet)
 Constructor.
 
const std::string & getKey () const
 Get key.
 
const char getSeparator () const
 Get separator.
 
const std::string & getValue () const
 Get value.
 
JEquationsetEquation (const std::string &buffer, const JEquationFacet &facet)
 Set equation.
 
JEquationsetEquation (const JEquationFacet &facet)
 Set this equation to its value.
 
std::string toString () const
 Convert equation to string.
 

Static Public Member Functions

template<class T >
static equation_type< T > make_equation (const std::string &key, const T &value)
 Auxiliary method to create equation type.
 
static JEquation valueOf (const std::string &buffer, const JEquationFacet &facet)
 Extract equation.
 

Protected Attributes

JString key
 
char sep
 
JString value
 

Friends

std::istream & operator>> (std::istream &in, JEquation &equation)
 Read equation from input stream.
 
std::ostream & operator<< (std::ostream &out, const JEquation &equation)
 Write equation to output stream.
 

Detailed Description

General purpose equation class.

An equation could have the following formats:

      <skip line>  "comment"  <end of line>
      <skip line>  "comment"  <end of line>
      <key> <separator> <value> <comment> "comment" <end of line>
      <key> <separator> <left bracket> <value> <value> <right bracket> <end of line>
      <key><division><key> <separator> <value> <end of line>

In this:

  • lines starting with one of the skip line characters are ignored;
  • key is the key of the equation;
  • value is the value of the equation;
  • comment marks the start of an inline comment (which is not part of the value); and
  • ' ' could be any of the specified white space characters. In case of a division of the key, the value of the equation will include the following key up to the end of line. The special characters are defined in the JEquationParameters class. The use of this class for I/O is handled via the JEquationFacet class.

Definition at line 47 of file JEquation.hh.

Constructor & Destructor Documentation

◆ JEquation() [1/3]

JLANG::JEquation::JEquation ( )
inline

Default constructor.

Definition at line 126 of file JEquation.hh.

126 :
127 key (),
128 sep ('\0'),
129 value()
130 {}

◆ JEquation() [2/3]

JLANG::JEquation::JEquation ( const std::string & key,
const std::string & value )
inline

Constructor.

Parameters
keykey
valuevalue

Definition at line 139 of file JEquation.hh.

139 :
140 key (key),
141 sep ('\0'),
142 value(value)
143 {}

◆ JEquation() [3/3]

JLANG::JEquation::JEquation ( const std::string & buffer,
const JEquationFacet & facet )
inline

Constructor.

Parameters
bufferinput
facetfacet

Definition at line 152 of file JEquation.hh.

153 {
154 setEquation(buffer, facet);
155 }
JEquation & setEquation(const std::string &buffer, const JEquationFacet &facet)
Set equation.
Definition JEquation.hh:320

Member Function Documentation

◆ make_equation()

template<class T >
static equation_type< T > JLANG::JEquation::make_equation ( const std::string & key,
const T & value )
inlinestatic

Auxiliary method to create equation type.

Parameters
keykey
valuevalue

Definition at line 117 of file JEquation.hh.

118 {
119 return equation_type<T>(key, value);
120 }

◆ getKey()

const std::string & JLANG::JEquation::getKey ( ) const
inline

Get key.

Returns
key

Definition at line 163 of file JEquation.hh.

164 {
165 return key;
166 }

◆ getSeparator()

const char JLANG::JEquation::getSeparator ( ) const
inline

Get separator.

Returns
separator

Definition at line 174 of file JEquation.hh.

175 {
176 return sep;
177 }

◆ getValue()

const std::string & JLANG::JEquation::getValue ( ) const
inline

Get value.

Returns
value

Definition at line 185 of file JEquation.hh.

186 {
187 return value;
188 }

◆ setEquation() [1/2]

JEquation & JLANG::JEquation::setEquation ( const std::string & buffer,
const JEquationFacet & facet )
inline

Set equation.

Parameters
bufferinput
facetfacet
Returns
this equation

Definition at line 320 of file JEquation.hh.

321 {
322 using namespace std;
323
324 istringstream in(buffer);
325
326 in.imbue(locale(in.getloc(), facet.clone()));
327
328 in >> *this;
329
330 return *this;
331 }

◆ setEquation() [2/2]

JEquation & JLANG::JEquation::setEquation ( const JEquationFacet & facet)
inline

Set this equation to its value.

Parameters
facetfacet
Returns
this equation

Definition at line 340 of file JEquation.hh.

341 {
342 setEquation(getValue(), facet);
343
344 return *this;
345 }
const std::string & getValue() const
Get value.
Definition JEquation.hh:185

◆ valueOf()

static JEquation JLANG::JEquation::valueOf ( const std::string & buffer,
const JEquationFacet & facet )
inlinestatic

Extract equation.

Parameters
bufferinput
facetfacet
Returns
equation

Definition at line 355 of file JEquation.hh.

356 {
357 return JEquation(buffer, facet);
358 }
JEquation()
Default constructor.
Definition JEquation.hh:126

◆ toString()

std::string JLANG::JEquation::toString ( ) const
inline

Convert equation to string.

Returns
string

Definition at line 366 of file JEquation.hh.

367 {
368 std::string buffer;
369
370 buffer += getKey();
371 buffer += getSeparator();
372 buffer += getValue();
373
374 return buffer;
375 }
const std::string & getKey() const
Get key.
Definition JEquation.hh:163
const char getSeparator() const
Get separator.
Definition JEquation.hh:174

Friends And Related Symbol Documentation

◆ operator>>

std::istream & operator>> ( std::istream & in,
JEquation & equation )
friend

Read equation from input stream.

Parameters
ininput stream
equationequation
Returns
input stream

Definition at line 198 of file JEquation.hh.

199 {
200 using namespace std;
201
202 istream::sentry sentry(in, false);
203
204 if (sentry) {
205
206 equation = JEquation();
207
208 const locale& loc = in.getloc();
209
210 if (has_facet<JEquationFacet>(loc)) {
211
212 const JEquationFacet& facet = use_facet<JEquationFacet>(loc);
213
214 ios_base::iostate state = in.rdstate();
215
216
217 for (int c; (c = in.peek()) != EOF && facet.isSkipLine((char) c); ) {
218 facet.ignore(in);
219 }
220
221
222 if (state == ios_base::goodbit) facet.get(in, istreambuf_iterator<char>(), in, state, equation.key);
223 if (state == ios_base::goodbit) facet.get(in, istreambuf_iterator<char>(), in, state, equation.sep);
224 if (state == ios_base::goodbit) facet.getline(in, equation.value);
225
226
227 // remove white spaces and brackets before evaluation
228
229 if (facet.isSeparator(equation.sep)) {
230
231 JString::const_iterator p = equation.value. begin();
232 JString::const_reverse_iterator q = equation.value.rbegin();
233
234 for ( ; ; ++p, ++q) {
235
236 for ( ; p != equation.value. end() && facet.isWhiteSpace(*p); ++p) {}
237 for ( ; q != equation.value.rend() && facet.isWhiteSpace(*q); ++q) {}
238
239 if (p == equation.value. end() || *p != facet.getLeftBracket() ||
240 q == equation.value.rend() || *q != facet.getRightBracket()) {
241 break;
242 }
243 }
244
245 if (p != equation.value.begin() || q != equation.value.rbegin()) {
246 equation.value = string(p, q.base());
247 }
248 }
249
250 if (state != ios_base::goodbit && state != ios_base::eofbit) {
251 in.setstate(state);
252 }
253
254 if (!(state & ios_base::eofbit)) {
255 if (!facet.isDivision (equation.sep) &&
256 !facet.isSeparator(equation.sep)) {
257 in.setstate(ios_base::badbit);
258 }
259 }
260
261 } else {
262
263 in.setstate(ios_base::failbit);
264 }
265 }
266
267 return in;
268 }
char * loc(char *orig)

◆ operator<<

std::ostream & operator<< ( std::ostream & out,
const JEquation & equation )
friend

Write equation to output stream.

Parameters
outoutput stream
equationequation
Returns
output stream

Definition at line 278 of file JEquation.hh.

279 {
280 using namespace std;
281
282 ostream::sentry sentry(out);
283
284 if (sentry) {
285
286 const locale& loc = out.getloc();
287
288 if (has_facet<JEquationFacet>(loc)) {
289
290 const JEquationFacet& facet = use_facet<JEquationFacet>(loc);
291
292 // conform with as many as possible equation parsers.
293
294 out << equation.key;
295 out << facet.getDefaultSeparator();
296 out << facet.getDefaultWhiteSpace();
297 out << equation.value;
298 out << facet.getDefaultEndOfLine();
299
300 } else {
301
302 out << equation.key;
303 out << equation.sep;
304 out << equation.value;
305 out << endl;
306 }
307 }
308
309 return out;
310 }

Member Data Documentation

◆ key

JString JLANG::JEquation::key
protected

Definition at line 378 of file JEquation.hh.

◆ sep

char JLANG::JEquation::sep
protected

Definition at line 379 of file JEquation.hh.

◆ value

JString JLANG::JEquation::value
protected

Definition at line 380 of file JEquation.hh.


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