Public Types | Public Member Functions | List of all members
ReferenceMap2< T > Class Template Reference

A map of references to base type scalars, arrays or std::string; changing values in either are equivalent operations. More...

#include <ReferenceMap.h>

Inheritance diagram for ReferenceMap2< T >:
Inheritance graph
[legend]
Collaboration diagram for ReferenceMap2< T >:
Collaboration graph
[legend]

Public Types

enum  extLinkPolicy { LINK , SKIP , RESERVE , ERROR }
 
typedef T ref_t
 
typedef SmartMap< T > map_t
 
- Public Types inherited from SmartMap< Reference >
typedef SmartMap< Referencesmap_t
 
typedef std::map< std::string, Referencemap_t
 
typedef map_t::key_type key_t
 
typedef map_t::mapped_type value_t
 
typedef map_t::value_type entry_t
 
typedef std::list< std::string > keylist_t
 
typedef map_t::iterator iterator
 Needed?
 
typedef map_t::const_iterator const_iterator
 

Public Member Functions

template<class F >
ref_t & link (const std::string &key, F &x)
 Associates a map entry with a variable. More...
 
ref_t & link (const std::string &key, void *ptr, const std::type_info &type, size_t count=1)
 Create a reference to a basic type or std::string. (Also for basetype arrays.)
 
template<class T2 >
void copyStruct (const ReferenceMap2< T > &m, const T2 &src, T2 &dst, extLinkPolicy policy=RESERVE)
 Experimental. Copies references and values of a structure to another. More...
 
- Public Member Functions inherited from SmartMap< Reference >
 SmartMap (char separator='\0', char arraySeparator=':')
 
 SmartMap (const SmartMap &smap)
 
virtual void clear ()
 
bool hasKey (const std::string &key) const
 
std::string get (const std::string &key, const std::string &defaultValue) const
 Retrieves a value, or default value if value is unset. More...
 
std::string get (const std::string &key, const char *defaultValue) const
 
T2 get (const std::string &key, const T2 &defaultValue) const
 Retrieves a value, if set, else returns the given default value. More...
 
virtual Referenceoperator[] (const std::string &key)
 Returns an element. Creates one, conditionally. More...
 
virtual const Referenceoperator[] (const std::string &key) const
 Unlike with std::map, operator[] const is defined, returning reference to a static empty instance.
 
virtual const keylist_t & getKeyList () const
 Derived versions may produce an ordered set of keys.
 
const map_t & getMap () const
 
void exportMap (std::map< std::string, T2 > &m) const
 Copies the contents to another map.
 
void importEntries (const std::string &entries, char assignmentSymbol='=', char separatorSymbol=0)
 Assigns a value to given key; if the entry does not exist, tries to create it with directly with operator[]. More...
 
void importEntries (const std::list< std::string > &entries, char assignmentSymbol='=')
 
void importMap (const std::map< std::string, S > &m)
 Assign values from a map, overriding existing entries. More...
 
void importCastableMap (const drain::SmartMap< T2 > &m)
 Assign values from a map, possibly extending the map. More...
 
void updateFromMap (const std::map< std::string, T2 > &m)
 Assign values from a map. Updates existing entries only. More...
 
void updateFromCastableMap (const drain::SmartMap< T2 > &m)
 Convenience.
 
void setValues (const std::string &entries, char assignmentSymbol='=', char separatorSymbol=0)
 Sets values. If strictness==STRICTLY_CLOSED, throws exception if tries to assign a non-existing entry.
 
void setValues (const char *entries, char assignmentSymbol='=', char separatorSymbol=0)
 
void setValuesSEQ (const S &sequence)
 
void updateValues (const std::string &entries, char assignmentSymbol='=', char separatorSymbol=0)
 Sets applicable values ie. modifies existing entries only. In ordered maps, skips extra entries silently.
 
void getKeys (std::ostream &ostr) const
 
std::string getKeys () const
 Convenience function for std::string output.
 
void getValues (std::ostream &ostr) const
 Dumps the values.
 
std::string getValues () const
 Convenience function for std::string output.
 
std::ostream & toStream (std::ostream &ostr, char equal='=', char startChar='{', char endChar='}', char separatorChar=',') const
 Note: parameters discarded.
 
std::string toStr (char equal='=', char start=0, char end=0, char separator=0) const
 
void dump (std::ostream &ostr=std::cout) const
 Write map as a JSON code. More...
 

Additional Inherited Members

- Public Attributes inherited from SmartMap< Reference >
char separator
 Default character used for splitting input and output. See setValues.
 
char arraySeparator
 Default separator character for array elements (std::vector's)
 
- Protected Attributes inherited from SmartMap< Reference >
std::list< std::string > keyList
 Assigns values from std::string of type "value,value2,...valueN". More...
 

Detailed Description

template<class T = Reference>
class drain::ReferenceMap2< T >

A map of references to base type scalars, arrays or std::string; changing values in either are equivalent operations.

New, templated implementation.

Template Parameters
TSmartVariable: Reference or FlexibleVariable; in future, also Parameter<Reference> or Parameter<FlexibleVariable>. Must implement link()

Member Enumeration Documentation

◆ extLinkPolicy

Alternatives in handling a link which is outside the source object.

Enumerator
LINK 

Link also external targets

SKIP 

No action

RESERVE 

No not link, but add a void entry as a placeholder

ERROR 

Throw exception

Member Function Documentation

◆ copyStruct()

void copyStruct ( const ReferenceMap2< T > &  m,
const T2 &  src,
T2 &  dst,
extLinkPolicy  policy = RESERVE 
)
inline

Experimental. Copies references and values of a structure to another.

Parameters
m- links to the members of the source object
src- the source object
dst- the destination object

Also updates key list and unit map?

◆ link()

ref_t& link ( const std::string &  key,
F &  x 
)
inline

Associates a map entry with a variable.

Parameters
key- variable name in a map
x- target variable to be linked

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