exprValue Class Reference

A polymorphic typed union of simple primitive and VectorSpace types. It uses a 'fatter' representation that includes standard VectorSpace types, which avoids heap allocations at the expense of more storage. This is mostly not an issue since lists and fields would box/unbox an entire field, not individual values. More...

Public Member Functions

 ClassName ("exprValue")
 Runtime type information. More...
 
 exprValue ()
 Default construct (zero-initialized) as 'none'. More...
 
 exprValue (const exprValue &rhs)
 Copy construct (deep copy) More...
 
template<class Type >
 exprValue (const Type &val)
 Construct from Type. Fatal for unsupported types. More...
 
expressions::valueTypeCode typeCode () const noexcept
 The value type code. More...
 
bool good () const noexcept
 True if the value type is not none/invalid. More...
 
bool is_integral () const noexcept
 True if the value type is an integral (bool or label) More...
 
direction nComponents () const noexcept
 The number of components associated with the value type. More...
 
direction rank () const noexcept
 The vector-space rank associated with the value type. More...
 
word valueTypeName () const
 The name for the value type. Similar to pTraits typeName. More...
 
word listCompoundName () const
 The name for the compound token (for a List of values). Eg, List<scalar>, List<vector> ... More...
 
void clear ()
 Reset to 'none'. More...
 
bool read (Istream &is)
 Read read tokens (if possible) More...
 
bool readTokens (ITstream &is)
 Guess type and read tokens (if possible) More...
 
template<class Type >
const Type * isA () const noexcept
 Return non-null pointer to the data element (if types match). Can also be tested as a bool. More...
 
template<class Type >
bool set (const Type &val)
 Assign from type. Returns false and sets to 'none' for unsupported types. More...
 
template<class Type >
const Type & get () const
 Return the value. Return pTraits zero if the types mismatch. More...
 
bool is_scalar () const noexcept
 
void operator= (const scalar &val)
 
bool is_vector () const noexcept
 
void operator= (const vector &val)
 
bool is_tensor () const noexcept
 
void operator= (const tensor &val)
 
bool is_symmTensor () const noexcept
 
void operator= (const symmTensor &val)
 
bool is_sphericalTensor () const noexcept
 
void operator= (const sphericalTensor &val)
 
bool is_label () const noexcept
 
void operator= (const label &val)
 
bool is_bool () const noexcept
 
void operator= (const bool &val)
 
void operator= (const exprValue &rhs)
 Copy assignment. More...
 
void operator= (const Foam::zero)
 Assign from zero. Changes value but not type. More...
 
const char * cdata_bytes () const noexcept
 Pointer to the data content as byte data. More...
 
char * data_bytes () noexcept
 Pointer to the data content as byte data. More...
 
bool operator== (const exprValue &rhs) const
 Compare (type,value) for equality. More...
 
bool operator!= (const exprValue &rhs) const
 Compare (type,value) for inequality. More...
 
bool operator< (const exprValue &rhs) const
 Compare (type,value) - currently not implemented. More...
 
InfoProxy< exprValueinfo () const
 Return info proxy for printing information to a stream. More...
 
tokenList tokens (bool prune=false) const
 The exprValue as tokens. More...
 
void write (Ostream &os, bool prune=false) const
 Write the (type-specific) content. More...
 

Static Public Member Functions

static bool good (const expressions::valueTypeCode) noexcept
 True if valueTypeCode is not none/invalid. More...
 
static bool is_integral (const expressions::valueTypeCode) noexcept
 True if valueTypeCode is bool/label. More...
 
static direction nComponents (const expressions::valueTypeCode) noexcept
 The number of components associated with the valueTypeCode. More...
 
static direction rank (const expressions::valueTypeCode) noexcept
 The vector-space rank associated with the valueTypeCode. More...
 
template<class Type >
static bool supportedType ()
 True if the specified type is supported. More...
 
static expressions::valueTypeCode peekType (const ITstream &is)
 Detect the type from the available tokens. More...
 
static bool read (const std::string &str, exprValue &val)
 Read entire string as a exprValue, skipping leading/trailing whitespace. More...
 
static constexpr unsigned size_bytes () noexcept
 Size of the (contiguous) data content as byte data is compile-time constant. More...
 

Detailed Description

A polymorphic typed union of simple primitive and VectorSpace types. It uses a 'fatter' representation that includes standard VectorSpace types, which avoids heap allocations at the expense of more storage. This is mostly not an issue since lists and fields would box/unbox an entire field, not individual values.

Source files

Definition at line 164 of file exprValue.H.

Constructor & Destructor Documentation

◆ exprValue() [1/3]

exprValue ( )
inline

Default construct (zero-initialized) as 'none'.

Definition at line 92 of file exprValueI.H.

References clear().

Here is the call graph for this function:

◆ exprValue() [2/3]

exprValue ( const exprValue rhs)
inline

Copy construct (deep copy)

Definition at line 98 of file exprValueI.H.

◆ exprValue() [3/3]

exprValue ( const Type &  val)
inlineexplicit

Construct from Type. Fatal for unsupported types.

Definition at line 105 of file exprValueI.H.

References Foam::abort(), clear(), Foam::FatalError, FatalErrorInFunction, Foam::name(), and Foam::nl.

Here is the call graph for this function:

Member Function Documentation

◆ ClassName()

ClassName ( "exprValue"  )

Runtime type information.

◆ good() [1/2]

bool good ( const expressions::valueTypeCode  valTypeCode)
inlinestaticnoexcept

True if valueTypeCode is not none/invalid.

Definition at line 26 of file exprValueI.H.

◆ is_integral() [1/2]

bool is_integral ( const expressions::valueTypeCode  valTypeCode)
inlinestaticnoexcept

True if valueTypeCode is bool/label.

Definition at line 39 of file exprValueI.H.

◆ nComponents() [1/2]

Foam::direction nComponents ( const expressions::valueTypeCode  valTypeCode)
inlinestaticnoexcept

The number of components associated with the valueTypeCode.

Definition at line 52 of file exprValueI.H.

References Foam::expressions::Detail::nComponents().

Here is the call graph for this function:

◆ rank() [1/2]

Foam::direction rank ( const expressions::valueTypeCode  valTypeCode)
inlinestaticnoexcept

The vector-space rank associated with the valueTypeCode.

Definition at line 61 of file exprValueI.H.

References Foam::expressions::Detail::rank().

Here is the call graph for this function:

◆ supportedType()

bool supportedType ( )
inlinestatic

True if the specified type is supported.

Definition at line 70 of file exprValueI.H.

References Foam::expressions::INVALID.

◆ peekType()

Foam::expressions::valueTypeCode peekType ( const ITstream is)
static

Detect the type from the available tokens.

Possible ambiguity between label and scalar.

Returns
INVALID for unsupported type

InfoErr << "check token: " << (endCmpti-firstCmpti) << " : " << is[endCmpti].name() << nl;

InfoErr<< "check token: " << tok0.info() << nl;

Definition at line 99 of file exprValue.C.

References token::BEGIN_LIST, token::END_LIST, Switch::good(), token::good(), ITstream::hasPutback(), Foam::expressions::INVALID, token::isLabel(), token::isNumber(), token::isPunctuation(), token::isScalar(), Foam::expressions::NONE, ITstream::peek(), UList< T >::size(), and ITstream::tokenIndex().

Referenced by exprValue::readTokens().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ read() [1/2]

bool read ( const std::string &  str,
exprValue val 
)
static

Read entire string as a exprValue, skipping leading/trailing whitespace.

Returns
True if successful.

Definition at line 197 of file exprValue.C.

References ITstream::nRemainingTokens(), and exprValue::readTokens().

Referenced by Foam::operator>>().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ typeCode()

expressions::valueTypeCode typeCode ( ) const
inlinenoexcept

The value type code.

Definition at line 284 of file exprValue.H.

◆ good() [2/2]

bool good ( ) const
inlinenoexcept

True if the value type is not none/invalid.

Definition at line 123 of file exprValueI.H.

◆ is_integral() [2/2]

bool is_integral ( ) const
inlinenoexcept

True if the value type is an integral (bool or label)

Definition at line 129 of file exprValueI.H.

◆ nComponents() [2/2]

Foam::direction nComponents ( ) const
inlinenoexcept

The number of components associated with the value type.

Definition at line 136 of file exprValueI.H.

References Foam::expressions::Detail::nComponents().

Here is the call graph for this function:

◆ rank() [2/2]

Foam::direction rank ( ) const
inlinenoexcept

The vector-space rank associated with the value type.

Definition at line 143 of file exprValueI.H.

References Foam::expressions::Detail::rank().

Here is the call graph for this function:

◆ valueTypeName()

Foam::word valueTypeName ( ) const
inline

The name for the value type. Similar to pTraits typeName.

Definition at line 150 of file exprValueI.H.

References Foam::name().

Here is the call graph for this function:

◆ listCompoundName()

Foam::word listCompoundName ( ) const
inline

The name for the compound token (for a List of values). Eg, List<scalar>, List<vector> ...

Definition at line 156 of file exprValueI.H.

References Foam::name().

Here is the call graph for this function:

◆ clear()

void clear ( )

Reset to 'none'.

Definition at line 211 of file exprValue.C.

◆ read() [2/2]

bool read ( Istream is)

Read read tokens (if possible)

Returns
True on success

Definition at line 328 of file exprValue.C.

References ITstream::add_tokens(), token::BEGIN_LIST, token::END_LIST, IOstream::fatalCheck(), FUNCTION_NAME, token::good(), token::isPunctuation(), List< T >::resize(), ITstream::seek(), and ITstream::tokenIndex().

Here is the call graph for this function:

◆ readTokens()

bool readTokens ( ITstream is)

Guess type and read tokens (if possible)

Returns
True on success

Definition at line 377 of file exprValue.C.

References IOstream::bad(), clear(), doLocalCode, FOR_ALL_EXPR_VALUE_TYPES, Foam::expressions::INVALID, token::isWord(), Foam::expressions::NONE, ITstream::peek(), exprValue::peekType(), and ITstream::skip().

Referenced by exprValue::read().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isA()

const Type * isA ( ) const
inlinenoexcept

Return non-null pointer to the data element (if types match). Can also be tested as a bool.

Definition at line 209 of file exprValueI.H.

◆ set()

bool set ( const Type &  val)
inline

Assign from type. Returns false and sets to 'none' for unsupported types.

Definition at line 169 of file exprValueI.H.

References clear(), Foam::expressions::INVALID, and Foam::expressions::NONE.

Here is the call graph for this function:

◆ get()

const Type & get ( ) const
inline

Return the value. Return pTraits zero if the types mismatch.

Definition at line 191 of file exprValueI.H.

◆ is_scalar()

bool is_scalar ( ) const
inlinenoexcept

True if value is a scalar

Definition at line 377 of file exprValue.H.

◆ operator=() [1/9]

void operator= ( const scalar &  val)
inline

Assign from scalar

Definition at line 377 of file exprValue.H.

◆ is_vector()

bool is_vector ( ) const
inlinenoexcept

True if value is a vector

Definition at line 377 of file exprValue.H.

◆ operator=() [2/9]

void operator= ( const vector val)
inline

Assign from vector

Definition at line 377 of file exprValue.H.

◆ is_tensor()

bool is_tensor ( ) const
inlinenoexcept

True if value is a tensor

Definition at line 377 of file exprValue.H.

◆ operator=() [3/9]

void operator= ( const tensor val)
inline

Assign from tensor

Definition at line 377 of file exprValue.H.

◆ is_symmTensor()

bool is_symmTensor ( ) const
inlinenoexcept

True if value is a symmTensor

Definition at line 377 of file exprValue.H.

◆ operator=() [4/9]

void operator= ( const symmTensor val)
inline

Assign from symmTensor

Definition at line 377 of file exprValue.H.

◆ is_sphericalTensor()

bool is_sphericalTensor ( ) const
inlinenoexcept

True if value is a sphericalTensor

Definition at line 377 of file exprValue.H.

◆ operator=() [5/9]

void operator= ( const sphericalTensor val)
inline

Assign from sphericalTensor

Definition at line 377 of file exprValue.H.

◆ is_label()

bool is_label ( ) const
inlinenoexcept

True if value is a label

Definition at line 377 of file exprValue.H.

◆ operator=() [6/9]

void operator= ( const label &  val)
inline

Assign from label

Definition at line 377 of file exprValue.H.

◆ is_bool()

bool is_bool ( ) const
inlinenoexcept

True if value is a bool

Definition at line 377 of file exprValue.H.

◆ operator=() [7/9]

void operator= ( const bool &  val)
inline

Assign from bool

Definition at line 377 of file exprValue.H.

◆ operator=() [8/9]

void operator= ( const exprValue rhs)
inline

Copy assignment.

Definition at line 383 of file exprValue.H.

◆ operator=() [9/9]

void operator= ( const Foam::zero  )
inline

Assign from zero. Changes value but not type.

Definition at line 388 of file exprValue.H.

◆ cdata_bytes()

const char* cdata_bytes ( ) const
inlinenoexcept

Pointer to the data content as byte data.

Definition at line 396 of file exprValue.H.

◆ data_bytes()

char* data_bytes ( )
inlinenoexcept

Pointer to the data content as byte data.

Definition at line 404 of file exprValue.H.

◆ size_bytes()

static constexpr unsigned size_bytes ( )
inlinestaticnoexcept

Size of the (contiguous) data content as byte data is compile-time constant.

Definition at line 413 of file exprValue.H.

◆ operator==()

bool operator== ( const exprValue rhs) const

Compare (type,value) for equality.

Definition at line 434 of file exprValue.C.

References doLocalCode, and FOR_ALL_EXPR_VALUE_TYPES.

◆ operator!=()

bool operator!= ( const exprValue rhs) const
inline

Compare (type,value) for inequality.

Definition at line 429 of file exprValue.H.

◆ operator<()

bool operator< ( const exprValue rhs) const

Compare (type,value) - currently not implemented.

Definition at line 470 of file exprValue.C.

◆ info()

InfoProxy<exprValue> info ( ) const
inline

Return info proxy for printing information to a stream.

Definition at line 442 of file exprValue.H.

◆ tokens()

Foam::tokenList tokens ( bool  prune = false) const

The exprValue as tokens.

For none : emits pair of brackets. For invalid : emits "bad".

Parameters
prunesuppress the output for none/invalid

Definition at line 228 of file exprValue.C.

References UList< T >::back(), token::BEGIN_LIST, doLocalCode, List< T >::emplace_back(), token::END_LIST, FOR_ALL_EXPR_VALUE_TYPES, UList< T >::front(), Foam::expressions::INVALID, Foam::expressions::NONE, and List< T >::resize().

Here is the call graph for this function:

◆ write()

void write ( Ostream os,
bool  prune = false 
) const

Write the (type-specific) content.

For none : emits pair of brackets. For invalid : emits "bad".

Parameters
prunesuppress the output for none/invalid

Definition at line 281 of file exprValue.C.

References token::BEGIN_LIST, doLocalCode, token::END_LIST, FOR_ALL_EXPR_VALUE_TYPES, Foam::expressions::INVALID, Foam::expressions::NONE, and os().

Referenced by Foam::operator<<().

Here is the call graph for this function:
Here is the caller graph for this function:

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