Public Types | Public Member Functions | Protected Attributes | List of all members
ReferenceMap Class Reference
Inheritance diagram for ReferenceMap:
Inheritance graph
[legend]
Collaboration diagram for ReferenceMap:
Collaboration graph
[legend]

Public Types

enum  extLinkPolicy { LINK , RESERVE , SKIP , ERROR }
 
typedef std::map< std::string, std::string > unitmap_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

 ReferenceMap (char separator=',')
 Default constructor. More...
 
 ReferenceMap (const ReferenceMap &rmap)
 Copy constructor copies only the separators; does not copy the items. More...
 
template<class F >
Referencelink (const std::string &key, Range< F > &x, const std::string &unit=std::string())
 
template<class F >
Referencelink (const std::string &key, F &x, const std::string &unit=std::string())
 Associates a map entry with a variable. More...
 
Referencelink (const std::string &key, Reference &x, const std::string &unit=std::string())
 
Referencelink (const std::string &key, void *ptr, const std::type_info &type, size_t count, const std::string &unit=std::string())
 For arrays.
 
Referencelink (const std::string &key, void *ptr, const std::type_info &type, const std::string &unit=std::string())
 Convenience: create a reference to a scalar. For arrays, use the.
 
template<class F >
ReferencereferenceTop (const std::string &key, F &x, const std::string &unit=std::string())
 Associates a map entry with a variable, adding key in the beginning of key list. More...
 
void append (ReferenceMap &rMap, bool replace=true)
 Adopts the references of r. If replace==false, only new entries are appended.
 
void delink (const std::string &key)
 Removes an entry from the map.
 
void reserve (const std::string &key)
 Adds a null entry, expecting the link later. More...
 
virtual void clear ()
 Removes all the elements of the map. More...
 
template<class T >
void copyStruct (const ReferenceMap &m, const T &src, T &dst, extLinkPolicy policy=RESERVE)
 Experimental. Copies references and values of a structure to another. More...
 
template<class T >
ReferenceMapoperator= (const SmartMap< T > &v)
 Import map, adopting the element types.
 
virtual mapped_type & operator[] (const std::string &key)
 Return element associated with key.
 
virtual const mapped_type & operator[] (const std::string &key) const
 Calling unreferenced key throws an exception.
 
const unitmap_t & getUnitMap () const
 Returns measurement unit information of the actual map entries.
 
- Public Member Functions inherited from SmartMap< Reference >
 SmartMap (char separator='\0', char arraySeparator=':')
 
 SmartMap (const SmartMap &smap)
 
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 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...
 

Protected Attributes

unitmap_t unitMap
 Creating a common segment for. More...
 
- Protected Attributes inherited from SmartMap< Reference >
std::list< std::string > keyList
 Assigns values from std::string of type "value,value2,...valueN". 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)
 

Detailed Description

Examples
ReferenceMap-example.cpp.

Member Enumeration Documentation

◆ extLinkPolicy

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

Enumerator
LINK 

Link also external targets

RESERVE 

No not link, but add entry (void)

SKIP 

No action

ERROR 

Throw exception

Constructor & Destructor Documentation

◆ ReferenceMap() [1/2]

ReferenceMap ( char  separator = ',')
inline

Default constructor.

\strictness - if true, allow attempts of assigning to non-existing entries; otherways throw exception on attempt.

◆ ReferenceMap() [2/2]

ReferenceMap ( const ReferenceMap rmap)
inline

Copy constructor copies only the separators; does not copy the items.

See also
copy()

Member Function Documentation

◆ clear()

virtual void clear ( )
inlinevirtual

Removes all the elements of the map.

Clears the map and its ordered keylist (and units).

Reimplemented from SmartMap< Reference >.

Reimplemented in EncodingODIM.

◆ copyStruct()

void copyStruct ( const ReferenceMap m,
const T &  src,
T &  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?

Examples
ReferenceMap-example.cpp.

◆ link()

Reference& link ( const std::string &  key,
F &  x,
const std::string &  unit = std::string() 
)
inline

Associates a map entry with a variable.

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

◆ referenceTop()

Reference& referenceTop ( const std::string &  key,
F &  x,
const std::string &  unit = std::string() 
)
inline

Associates a map entry with a variable, adding key in the beginning of key list.

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

◆ reserve()

void reserve ( const std::string &  key)
inline

Adds a null entry, expecting the link later.

The key will be added in the key list.

Member Data Documentation

◆ unitMap

unitmap_t unitMap
protected

Creating a common segment for.

Associates a map entry with a variable

Parameters
key- variable name in a map
x- target variable to be linked Defines the units of each element.

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