Jpp 20.0.0-27-g39925593c-D
the software that should make you happy
Loading...
Searching...
No Matches
Classes | Public Member Functions | Static Public Member Functions | Protected Attributes | Friends | List of all members
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:

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:317

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 317 of file JEquation.hh.

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

◆ 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 337 of file JEquation.hh.

338 {
339 setEquation(getValue(), facet);
340
341 return *this;
342 }
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 352 of file JEquation.hh.

353 {
354 return JEquation(buffer, facet);
355 }
JEquation()
Default constructor.
Definition JEquation.hh:126

◆ toString()

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

Convert equation to string.

Returns
string

Definition at line 363 of file JEquation.hh.

364 {
365 std::string buffer;
366
367 buffer += getKey();
368 buffer += getSeparator();
369 buffer += getValue();
370
371 return buffer;
372 }
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 out << equation.key;
293 out << facet.getDefaultSeparator();
294 out << equation.value;
295 out << facet.getDefaultEndOfLine();
296
297 } else {
298
299 out << equation.key;
300 out << equation.sep;
301 out << equation.value;
302 out << endl;
303 }
304 }
305
306 return out;
307 }

Member Data Documentation

◆ key

JString JLANG::JEquation::key
protected

Definition at line 375 of file JEquation.hh.

◆ sep

char JLANG::JEquation::sep
protected

Definition at line 376 of file JEquation.hh.

◆ value

JString JLANG::JEquation::value
protected

Definition at line 377 of file JEquation.hh.


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