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

#include <tsExpressions.h>

Public Member Functions

 Expressions (Report &report, int debug_level=Severity::Debug, const UString &debug_prefix=UString())
bool define (const UString &symbol, const UString &context=UString())
bool error () const
bool evaluate (const UString &expression, const UString &context=UString())
bool isDefined (const UString &symbol) const
bool isValidSymbolName (const UString &symbol, const UString &context=UString())
void resetError ()
void setMaxNested (size_t max)
size_t symbolCount () const
bool undefine (const UString &symbol, const UString &context=UString())
void undefineAll ()

Static Public Member Functions

static bool IsValidSymbolName (const UString &symbol)

Static Public Attributes

static constexpr size_t DEFAULT_MAX_NESTED = 256

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.

◆ undefineAll()

void ts::Expressions::undefineAll ( )
inline

Undefine all symbols, clear the symbol database.

◆ 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()

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.

◆ setMaxNested()

void ts::Expressions::setMaxNested ( size_t max)
inline

Set the maximum number of nested levels of parentheses in an expression.

Parameters
[in]maxMaximum number of nested levels of parentheses in an expression.
See also
DEFAULT_MAX_NESTED

◆ 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()

Member Data Documentation

◆ DEFAULT_MAX_NESTED

size_t ts::Expressions::DEFAULT_MAX_NESTED = 256
staticconstexpr

Default maximum number of nested levels of parentheses in an expression.

See also
setMaxNested()

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