InFact
Interpreter and factory for easily creating C++ objects at run-time
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Public Member Functions | Protected Member Functions | List of all members
infact::VarMapImpl< T, Derived > Class Template Reference

A partial implementation of the VarMapBase interface that is common to both VarMap<T> and the VarMap<vector<T> > partial specialization. More...

#include <environment.h>

Inheritance diagram for infact::VarMapImpl< T, Derived >:
infact::VarMapBase

Public Member Functions

 VarMapImpl (const string &name, Environment *env, bool is_primitive=true)
 
virtual ~VarMapImpl ()
 
bool Get (const string &varname, T *value) const
 Assigns the value of the specified variable to the object pointed to by the value parameter. More...
 
virtual bool Defined (const string &varname) const
 Returns whether the specified variable has a definition in this environment. More...
 
void Set (const string &varname, T value)
 Sets the specified variable to the specified value. More...
 
virtual void Print (ostream &os) const
 Prints out a human-readable string to the specified output stream containing the variables, their type and, if primitive, their values. More...
 
virtual VarMapBaseCopy (Environment *env) const
 Returns a newly constructed copy of this VarMap. More...
 
- Public Member Functions inherited from infact::VarMapBase
 VarMapBase (const string &name, Environment *env, bool is_primitive)
 Constructs a base class for a concrete implementation providing a mapping from variables of a particular type to their values. More...
 
virtual ~VarMapBase ()
 
virtual bool IsPrimitive () const
 Returns whether this instance contains primitive or primtive vector variables. More...
 
virtual const string & Name () const
 Returns the type name of the variables of this instance. More...
 
virtual void ReadAndSet (const string &varname, StreamTokenizer &st)=0
 Reads the next value (primitive or spec for constructing a Factory-constructible object) from the specified stream tokenizer and sets the specified variable to that value. More...
 

Protected Member Functions

bool ReadAndSetFromExistingVariable (const string &varname, StreamTokenizer &st)
 Checks if the next token is an identifier and is a variable in the environment, and, if so, sets varname to the variable’s value. More...
 
Environmentenv ()
 A protected method to access the environment contained by this VarMapBase instance, for the two concrete VarMap implementations, below. More...
 
- Protected Member Functions inherited from infact::VarMapBase
void SetMembers (const string &name, Environment *env, bool is_primitive)
 To allow proper implementation of Copy in VarMapBase implementation, since we don't get copying of base class' members for free. More...
 

Additional Inherited Members

- Protected Attributes inherited from infact::VarMapBase
string name_
 The type name of this VarMap. More...
 
Environmentenv_
 The Environment that holds this VarMap instance. More...
 
bool is_primitive_
 Whether this VarMap instance holds variables of primitive type or vector of primitives. More...
 

Detailed Description

template<typename T, typename Derived>
class infact::VarMapImpl< T, Derived >

A partial implementation of the VarMapBase interface that is common to both VarMap<T> and the VarMap<vector<T> > partial specialization.

In a delightful twist, this partial implementation of VarMapBase uses the curiously recurring template pattern (CRTP) in order to implement the VarMapBase::Copy method, as well as the protected method ReadAndSetFromExistingVariable.

Template Parameters
Tthe type of variables stored in this (partial implementation of a) variable map
Derivedthe type of the class using this as its base class (a.k.a. CRTP, or the "curiously recurring template pattern")

Definition at line 266 of file environment.h.

Constructor & Destructor Documentation

template<typename T, typename Derived>
infact::VarMapImpl< T, Derived >::VarMapImpl ( const string &  name,
Environment env,
bool  is_primitive = true 
)
inline

Definition at line 268 of file environment.h.

template<typename T, typename Derived>
virtual infact::VarMapImpl< T, Derived >::~VarMapImpl ( )
inlinevirtual

Definition at line 271 of file environment.h.

Member Function Documentation

template<typename T, typename Derived>
virtual VarMapBase* infact::VarMapImpl< T, Derived >::Copy ( Environment env) const
inlinevirtual

Returns a newly constructed copy of this VarMap.

Implements infact::VarMapBase.

Definition at line 316 of file environment.h.

template<typename T, typename Derived>
virtual bool infact::VarMapImpl< T, Derived >::Defined ( const string &  varname) const
inlinevirtual

Returns whether the specified variable has a definition in this environment.

Implements infact::VarMapBase.

Definition at line 291 of file environment.h.

template<typename T, typename Derived>
Environment* infact::VarMapImpl< T, Derived >::env ( )
inlineprotected

A protected method to access the environment contained by this VarMapBase instance, for the two concrete VarMap implementations, below.

Definition at line 373 of file environment.h.

template<typename T, typename Derived>
bool infact::VarMapImpl< T, Derived >::Get ( const string &  varname,
T *  value 
) const
inline

Assigns the value of the specified variable to the object pointed to by the value parameter.

Returns
whether the specified variable exists and the assignment was successful

Definition at line 280 of file environment.h.

template<typename T, typename Derived>
virtual void infact::VarMapImpl< T, Derived >::Print ( ostream &  os) const
inlinevirtual

Prints out a human-readable string to the specified output stream containing the variables, their type and, if primitive, their values.

Implements infact::VarMapBase.

Definition at line 301 of file environment.h.

template<typename T, typename Derived>
bool infact::VarMapImpl< T, Derived >::ReadAndSetFromExistingVariable ( const string &  varname,
StreamTokenizer st 
)
inlineprotected

Checks if the next token is an identifier and is a variable in the environment, and, if so, sets varname to the variable’s value.

Definition at line 329 of file environment.h.

template<typename T, typename Derived>
void infact::VarMapImpl< T, Derived >::Set ( const string &  varname,
value 
)
inline

Sets the specified variable to the specified value.

Definition at line 296 of file environment.h.


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