osgEarth 2.1.1
Public Types | Public Member Functions | Private Types | Private Member Functions | Private Attributes

osgEarth::Symbology::StringExpression Class Reference

Collaboration diagram for osgEarth::Symbology::StringExpression:

List of all members.

Public Types

typedef std::pair< std::string,
unsigned > 
Variable
typedef std::vector< VariableVariables

Public Member Functions

 StringExpression ()
 StringExpression (const Config &conf)
 StringExpression (const std::string &expr)
 StringExpression (const StringExpression &rhs)
const Variablesvariables () const
void set (const Variable &var, const std::string &value)
const std::string & eval () const
const std::string & expr () const
bool empty () const
void setURIContext (const URIContext &uriContext)
const URIContexturiContext () const
Config getConfig () const
void mergeConfig (const Config &conf)

Private Types

enum  Op { OPERAND, VARIABLE }
typedef std::pair< Op,
std::string > 
Atom
typedef std::vector< AtomAtomVector

Private Member Functions

void init ()

Private Attributes

std::string _src
AtomVector _infix
Variables _vars
std::string _value
bool _dirty
URIContext _uriContext

Detailed Description

Simple string expression evaluator with variables.

Definition at line 92 of file Expression.


Member Typedef Documentation

typedef std::pair<Op,std::string> osgEarth::Symbology::StringExpression::Atom [private]

Definition at line 133 of file Expression.

Definition at line 134 of file Expression.

typedef std::pair<std::string,unsigned> osgEarth::Symbology::StringExpression::Variable

Definition at line 95 of file Expression.

Definition at line 96 of file Expression.


Member Enumeration Documentation

Enumerator:
OPERAND 
VARIABLE 

Definition at line 132 of file Expression.

{ OPERAND, VARIABLE }; // in low-high precedence order

Constructor & Destructor Documentation

osgEarth::Symbology::StringExpression::StringExpression ( ) [inline]

Definition at line 99 of file Expression.

{ }
StringExpression::StringExpression ( const Config conf)

Definition at line 305 of file Expression.cpp.

{
    mergeConfig( conf );
    init();
}

Here is the call graph for this function:

StringExpression::StringExpression ( const std::string &  expr)

Construct a new expression from the infix string.

Definition at line 287 of file Expression.cpp.

                                                          : 
_src( expr ),
_dirty( true )
{
    init();
}

Here is the call graph for this function:

StringExpression::StringExpression ( const StringExpression rhs)

Copy ctor.

Definition at line 294 of file Expression.cpp.

                                                                :
_src( rhs._src ),
_vars( rhs._vars ),
_value( rhs._value ),
_infix( rhs._infix ),
_dirty( rhs._dirty ),
_uriContext( rhs._uriContext )
{
    //nop
}

Member Function Documentation

bool osgEarth::Symbology::StringExpression::empty ( ) const [inline]

Whether the expression is empty

Definition at line 122 of file Expression.

{ return _src.empty(); }

Here is the caller graph for this function:

const std::string & StringExpression::eval ( ) const

Evaluate the expression.

Definition at line 368 of file Expression.cpp.

{
    if ( _dirty )
    {
        std::stringstream buf;
        for( AtomVector::const_iterator i = _infix.begin(); i != _infix.end(); ++i )
            buf << i->second;

        const_cast<StringExpression*>(this)->_value = buf.str();
        const_cast<StringExpression*>(this)->_dirty = false;
    }

    return _value;
}

Here is the caller graph for this function:

const std::string& osgEarth::Symbology::StringExpression::expr ( ) const [inline]

Gets the expression string.

Definition at line 119 of file Expression.

{ return _src; }
Config StringExpression::getConfig ( ) const

Definition at line 319 of file Expression.cpp.

{
    return Config( "string_expression", _src );
}
void StringExpression::init ( ) [private]

Definition at line 325 of file Expression.cpp.

{
    StringTokenizer izer("", "");
    izer.addDelims( "[]", true );
    izer.addQuotes( "'\"", false );
    izer.keepEmpties() = false;
    izer.trimTokens() = false;

    StringVector t;
    izer.tokenize( _src, t );
    //tokenize(_src, t, "[]", "'\"", false, true, false);

    // identify tokens:
    bool invar = false;
    for( unsigned i=0; i<t.size(); ++i )
    {
        if ( t[i] == "[" && !invar )
        {
            invar = true;
        }
        else if ( t[i] == "]" && invar )
        {
            invar = false;
            _infix.push_back( Atom(VARIABLE,"") );
            _vars.push_back( Variable(t[i-1],0) );
        }
        else
            _infix.push_back( Atom(OPERAND,t[i]) );
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void StringExpression::mergeConfig ( const Config conf)

Definition at line 312 of file Expression.cpp.

{
    _src = conf.value();
    _dirty = true;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void StringExpression::set ( const Variable var,
const std::string &  value 
)

Set the value of a variable.

Definition at line 357 of file Expression.cpp.

{
    Atom& a = _infix[var.second];
    if ( a.second != value )
    {
        a.second = value;
        _dirty = true;
    }
}

Here is the caller graph for this function:

void osgEarth::Symbology::StringExpression::setURIContext ( const URIContext uriContext) [inline]

Definition at line 124 of file Expression.

const URIContext& osgEarth::Symbology::StringExpression::uriContext ( ) const [inline]

Definition at line 125 of file Expression.

{ return _uriContext; }

Here is the caller graph for this function:

const Variables& osgEarth::Symbology::StringExpression::variables ( ) const [inline]

Access the expression variables.

Definition at line 110 of file Expression.

{ return _vars; }

Here is the caller graph for this function:


Member Data Documentation

Definition at line 140 of file Expression.

Definition at line 137 of file Expression.

Definition at line 136 of file Expression.

Definition at line 141 of file Expression.

Definition at line 139 of file Expression.

Definition at line 138 of file Expression.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines