32 #include <drain/Log.h>
42 #include <drain/Reference.h>
43 #include <drain/String.h>
66 template <
class T=Reference>
82 ref_t &
link(
const std::string & key, F &x){
84 ref_t & r = (*this)[key];
105 ref_t &
link(
const std::string & key,
void *ptr,
const std::type_info &type,
size_t count=1){
107 ref_t & r = (*this)[key];
109 r.link(ptr, type, count);
148 Logger mout(__FILE__, __FUNCTION__);
156 typedef unsigned long addr_t;
157 typedef long addr_diff_t;
159 const addr_t srcAddr = (addr_t)(&src);
160 const addr_t dstAddr = (addr_t)(&dst);
162 for (
const std::string & key: m.
getKeyList()){
164 const ref_t & srcRef = m[key];
165 addr_t srcVarAddr = (addr_t)srcRef.getPtr();
166 addr_diff_t relativeAddr = srcVarAddr - srcAddr;
167 if ((relativeAddr >= 0) && (relativeAddr < s)){
169 ref_t & dstMemberRef =
link(key, (
void *)(dstAddr + relativeAddr), srcRef.getType(), srcRef.getElementCount());
171 dstMemberRef.copyFormat(srcRef);
172 dstMemberRef.assignCastable(srcRef);
178 link(key, (
void *)srcVarAddr, srcRef.getType(), srcRef.getElementCount()).copyFormat(srcRef);
187 mout.
debug(
"skipping external variable: '" , key ,
'=' , srcRef ,
"' relative addr=" , relativeAddr );
190 mout.
error(
"external variable: '" , key ,
'=' , srcRef ,
"' relative addr=" , relativeAddr );
193 mout.
warn(
"unknown enum option in handling external variable '" , key ,
'=' , srcRef ,
"' relative addr=" , relativeAddr );
228 Reference & link(
const std::string & key, Range<F> &x,
const std::string & unit = std::string()){
229 Logger mout(__FILE__, __FUNCTION__);
230 mout.deprecating(
" type drain::Range<> use .tuple() instead: ", key,
'[', unit,
']');
231 return link(key, &x,
typeid(F), 2, unit);
240 Reference &
link(
const std::string & key, F &x,
const std::string & unit = std::string()){
242 if (find(key) == end()){
246 std::cerr <<
"empty key referencing to " << x <<
" unit=" << unit << std::endl;
248 else if (key.at(0) ==
'_'){
249 throw std::runtime_error(key +
": hidden parameters can be added only after visible");
252 else if ((
keyList.back().at(0) ==
'_') && (key.at(0) !=
'_')){
253 throw std::runtime_error(key +
": cannot add visible parameters after hidden");
262 Reference & r = std::map<std::string,Reference>::operator[](key);
271 Reference & link(
const std::string & key,
Reference &x,
const std::string & unit = std::string()){
272 return link(key, x.getPtr(), x.getType(), x.getElementCount(), unit);
278 Reference &
link(
const std::string & key,
void *ptr,
const std::type_info &type,
size_t count,
const std::string & unit = std::string()){
280 if (find(key) == end())
283 Reference & r = std::map<std::string,Reference>::operator[](key);
285 r.link(ptr, type, count);
293 Reference &
link(
const std::string & key,
void *ptr,
const std::type_info &type,
const std::string & unit = std::string()){
294 return link(key, ptr, type, 1, unit);
305 if (find(key) != end())
309 Reference & r = std::map<std::string,Reference>::operator[](key);
322 const std::list<std::string> & keys = rMap.
getKeyList();
324 for (
const std::string & key: keys){
326 if (replace || !hasKey(key)){
331 item.setFill(srcItem.fillArray);
332 item.setInputSeparator(srcItem.getInputSeparator());
333 item.setOutputSeparator(srcItem.getOutputSeparator());
343 std::map<std::string,Reference>::erase(key);
344 for (std::list<std::string>::iterator it =
keyList.begin(); it !=
keyList.end(); ++it)
359 if (find(key) == end())
364 std::map<std::string,Reference>::operator[](key);
402 Logger mout(__FILE__, __FUNCTION__);
410 typedef unsigned long addr_t;
411 typedef long addr_diff_t;
413 const addr_t srcAddr = (addr_t)(&src);
414 const addr_t dstAddr = (addr_t)(&dst);
416 for (
const std::string & key: m.
getKeyList()){
419 addr_t srcVarAddr = (addr_t)srcRef.getPtr();
420 addr_diff_t relativeAddr = srcVarAddr - srcAddr;
421 if ((relativeAddr >= 0) && (relativeAddr < s)){
422 Reference & dstMemberRef = link(key, (
void *)(dstAddr + relativeAddr), srcRef.getType(), srcRef.getElementCount());
424 dstMemberRef.copyFormat(srcRef);
425 dstMemberRef = srcRef;
431 link(key, (
void *)srcVarAddr, srcRef.getType(), srcRef.getElementCount()).copyFormat(srcRef);
439 mout.
debug(
"skipping external variable: '" , key ,
'=' , srcRef ,
"' relative addr=" , relativeAddr );
442 mout.
error(
"external variable: '" , key ,
'=' , srcRef ,
"' relative addr=" , relativeAddr );
445 mout.
warn(
"unknown enum option in handling external variable '" , key ,
'=' , srcRef ,
"' relative addr=" , relativeAddr );
473 Logger mout(__FILE__, __FUNCTION__);
476 if (it != this->end()) {
480 mout.
warn(
"current contents: " , *
this );
482 mout.
error(
"key '" , key ,
"' not declared (referenced)" );
484 static mapped_type empty;
492 const mapped_type &
operator[](
const std::string &key)
const {
494 Logger mout(__FILE__, __FUNCTION__);
496 const_iterator it = this->find(key);
497 if (it != this->end()) {
501 mout.
error(
"key '" , key ,
"' not declared (referenced)" );
503 static const mapped_type empty;
508 typedef std::map<std::string,std::string> unitmap_t;
LogSourc e is the means for a function or any program segment to "connect" to a Log.
Definition: Log.h:308
Logger & error(const TT &... args)
Echoes.
Definition: Log.h:412
Logger & warn(const TT &... args)
Possible error, but execution can continue.
Definition: Log.h:426
Logger & debug(const TT &... args)
Public, yet typically used "internally", when TIMING=true.
Definition: Log.h:676
A map of references to base type scalars, arrays or std::string; changing values in either are equiva...
Definition: ReferenceMap.h:67
void copyStruct(const ReferenceMap2< T > &m, const T2 &src, T2 &dst, extLinkPolicy policy=RESERVE)
Experimental. Copies references and values of a structure to another.
Definition: ReferenceMap.h:145
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.)
Definition: ReferenceMap.h:105
extLinkPolicy
Definition: ReferenceMap.h:128
@ ERROR
Definition: ReferenceMap.h:132
@ SKIP
Definition: ReferenceMap.h:130
@ LINK
Definition: ReferenceMap.h:129
@ RESERVE
Definition: ReferenceMap.h:131
ref_t & link(const std::string &key, F &x)
Associates a map entry with a variable.
Definition: ReferenceMap.h:82
Definition: ReferenceMap.h:207
unitmap_t unitMap
Creating a common segment for.
Definition: ReferenceMap.h:512
virtual const mapped_type & operator[](const std::string &key) const
Calling unreferenced key throws an exception.
Definition: ReferenceMap.h:492
ReferenceMap & operator=(const SmartMap< T > &v)
Import map, adopting the element types.
Definition: ReferenceMap.h:462
void append(ReferenceMap &rMap, bool replace=true)
Adopts the references of r. If replace==false, only new entries are appended.
Definition: ReferenceMap.h:320
Reference & referenceTop(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.
Definition: ReferenceMap.h:303
Reference & link(const std::string &key, void *ptr, const std::type_info &type, size_t count, const std::string &unit=std::string())
For arrays.
Definition: ReferenceMap.h:278
ReferenceMap(char separator=',')
Default constructor.
Definition: ReferenceMap.h:216
Reference & link(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.
Definition: ReferenceMap.h:293
virtual mapped_type & operator[](const std::string &key)
Return element associated with key.
Definition: ReferenceMap.h:471
void copyStruct(const ReferenceMap &m, const T &src, T &dst, extLinkPolicy policy=RESERVE)
Experimental. Copies references and values of a structure to another.
Definition: ReferenceMap.h:399
Reference & link(const std::string &key, F &x, const std::string &unit=std::string())
Associates a map entry with a variable.
Definition: ReferenceMap.h:240
void reserve(const std::string &key)
Adds a null entry, expecting the link later.
Definition: ReferenceMap.h:357
virtual void clear()
Removes all the elements of the map.
Definition: ReferenceMap.h:374
void delink(const std::string &key)
Removes an entry from the map.
Definition: ReferenceMap.h:342
ReferenceMap(const ReferenceMap &rmap)
Copy constructor copies only the separators; does not copy the items.
Definition: ReferenceMap.h:220
extLinkPolicy
Definition: ReferenceMap.h:383
@ ERROR
Definition: ReferenceMap.h:387
@ SKIP
Definition: ReferenceMap.h:386
@ LINK
Definition: ReferenceMap.h:384
@ RESERVE
Definition: ReferenceMap.h:385
const unitmap_t & getUnitMap() const
Returns measurement unit information of the actual map entries.
Definition: ReferenceMap.h:512
A base class for smart maps providing methods for importing and exporting values, among others.
Definition: SmartMap.h:66
map_t::iterator iterator
Needed?
Definition: SmartMap.h:80
char arraySeparator
Default separator character for array elements (std::vector's)
Definition: SmartMap.h:88
std::list< std::string > keyList
Assigns values from std::string of type "value,value2,...valueN".
Definition: SmartMap.h:438
char separator
Default character used for splitting input and output. See setValues.
Definition: SmartMap.h:85
virtual const keylist_t & getKeyList() const
Derived versions may produce an ordered set of keys.
Definition: SmartMap.h:200
void importMap(const std::map< std::string, S > &m)
Assign values from a map, overriding existing entries.
Definition: SmartMap.h:252
VariableT is a final class applied through typedefs Variable, Reference and FlexibleVariable.
Definition: VariableT.h:87
Definition: DataSelector.cpp:1277
VariableT< ReferenceT< Castable > > Reference
Variable-like that is linked to a standard variable: double, int, std::string . Supports multi-elemen...
Definition: Reference.h:78