TSDuck v3.46-4819
MPEG Transport Stream Toolkit
Loading...
Searching...
No Matches
ts::Expressions Class Reference

Expression resolver based on the definition of symbols. More...

#include <tsExpressions.h>

Public Member Functions

 Expressions (Report &report, int debug_level=Severity::Debug, const UString &debug_prefix=UString())
 Constructor.
 
bool define (const UString &symbol, const UString &context=UString())
 Define a symbol in the internal repository.
 
bool error () const
 Check if errors occured (invalid symbols, invalid expressions).
 
bool evaluate (const UString &expression, const UString &context=UString())
 Evaluate a boolean expression using symbols.
 
bool isDefined (const UString &symbol) const
 Check if a symbol is defined in the internal repository.
 
bool isValidSymbolName (const UString &symbol, const UString &context=UString())
 Check if a string is valid symbol name and report an error if not.
 
void resetError ()
 Reset the error indicator.
 
size_t symbolCount () const
 Get the number of defined symbols.
 
bool undefine (const UString &symbol, const UString &context=UString())
 Undefine a symbol from the internal repository.
 
void undefineAll ()
 Undefine all symbols, clear the symbol database.
 

Static Public Member Functions

static bool IsValidSymbolName (const UString &symbol)
 Check if a string is valid symbol name.
 

Detailed Description

Expression resolver based on the definition of symbols.

Symbols are words starting with a letter and made of alphanumerical characters and underscores. Symbol names are case sensitive. Symbols can be defined and undefined in an internal repository of the Expressions object.

Boolean expressions are evaluated based on the definition of symbols. A symbol evaluates to true when it is defined and false when it is not. The unary operator '!' is the negation. The binary operators '&&' and '||' can be used. Parentheses can be used to group sub-expressions.

Constructor & Destructor Documentation

◆ Expressions()

ts::Expressions::Expressions ( Report &  report,
int  debug_level = Severity::Debug,
const UString &  debug_prefix = UString() 
)
explicit

Constructor.

Parameters
[in,out]reportWhere to report errors.
[in]debug_levelSeverity level for debug messages.
[in]debug_prefixPrefix string for debug messages.

Member Function Documentation

◆ define()

bool ts::Expressions::define ( const UString &  symbol,
const UString &  context = UString() 
)

Define a symbol in the internal repository.

Parameters
[in]symbolThe symbol to add in the internal repository.
[in]contextOptional context of the symbol, for error message only.
Returns
True if symbol is valid, false if it is not. A message is reported in error.

◆ undefine()

bool ts::Expressions::undefine ( const UString &  symbol,
const UString &  context = UString() 
)

Undefine a symbol from the internal repository.

Parameters
[in]symbolThe symbol to remove from the internal repository.
[in]contextOptional context of the symbol, for error message only.
Returns
True if symbol is valid, false if it is not. A message is reported in error. Undefining a non-existent symbol is not an error, the function returns true.

◆ symbolCount()

size_t ts::Expressions::symbolCount ( ) const
inline

Get the number of defined symbols.

Returns
The number of defined symbols.

◆ isDefined()

bool ts::Expressions::isDefined ( const UString &  symbol) const
inline

Check if a symbol is defined in the internal repository.

Parameters
[in]symbolThe symbol to check.
Returns
True if symbol is defined, false if it is not.

◆ isValidSymbolName()

bool ts::Expressions::isValidSymbolName ( const UString &  symbol,
const UString &  context = UString() 
)

Check if a string is valid symbol name and report an error if not.

Parameters
[in]symbolThe symbol to check.
[in]contextOptional context of the symbol, for error message only.
Returns
True if symbol is valid, false if it is not. A message is reported in error.

◆ IsValidSymbolName()

static bool ts::Expressions::IsValidSymbolName ( const UString &  symbol)
static

Check if a string is valid symbol name.

Parameters
[in]symbolThe name to check.
Returns
True if symbol is a valid name, false if it is not.

◆ evaluate()

bool ts::Expressions::evaluate ( const UString &  expression,
const UString &  context = UString() 
)

Evaluate a boolean expression using symbols.

Parameters
[in]expressionThe expression to evaluate.
[in]contextOptional context of the symbol, for error message only.
Returns
The boolean result of expression. In case of error, a message is reported and false is returned.

◆ error()

bool ts::Expressions::error ( ) const
inline

Check if errors occured (invalid symbols, invalid expressions).

Returns
True if some error occurred.
See also
resetError()

◆ resetError()

void ts::Expressions::resetError ( )
inline

Reset the error indicator.

See also
error()

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