A map of references to base type scalars, arrays or std::string; changing values in either are equivalent operations. A class designed for objects returned by CastableIterator. Contains a pointer to external object.
#include <iostream>
#include <stdexcept>
#include <vector>
#include "drain/util/ReferenceMap.h"
#include "drain/util/Rectangle.h"
int main(int argc, char **argv){
int i = 6;
float f;
std::string s="Hello, world!";
struct person {
std::string name;
int id;
};
person p;
p.name = "Smith";
p.id = 18267;
p.tuple.set(1.0, 2.0, 3.0);
p.rect.set(20, 60, 30, 70);
p.range.min = 0.1;
p.range.max = 4.7;
r.link("f", f=4.56f, "float");
r.link("s", s, "name");
r.link("v", tuple, "params").fillArray = true;
r.link("name", p.name);
r.link("id", p.id);
r.link("vect", p.tuple);
r.link("range",p.range.tuple());
p.tuple = {1.1, 2.1, 3.1};
std::cout << "ReferenceMap rCopy\n";
person pCopy;
pCopy.tuple = {333, 222, 111};
ref.link(p.range.tuple());
std::cout << "ReferenceMap rCopy\n";
std::cout << ref << '\n';
if (argc < 2){
std::cout << "ReferenceMap demo\n";
std::cerr << "map: " << r << '\n';
std::cout << "See also: SmartMap-example\n";
std::cout << "Example: " << argv[0] << " 123,0.25,hello s=hello i=5.67,hello s=1,s=test\n";
struct record {
std::string s = "Hello, world!";
int i = 123;
float f = 4.567f;
bool flag = true;
std::vector<float> fv;
};
record orig;
orig.fv.push_back(1.23);
orig.fv.push_back(4.56);
refOrig.link("i", orig.i = 56);
refOrig.link("f", orig.f = 78.9);
refOrig.link("s", orig.s = "ABC");
refOrig.link("flag", orig.flag = false);
int raimo = 12345;
refOrig.link("outlier", i);
refOrig.link("raymond", raimo);
record copy;
refCopy["outlier"] = 129;
std::cout << copy.s << ',' << copy.i << ','<< copy.f << ','<< copy.flag << '\n';
std::cout << refOrig << '\n';
std::cout << refCopy << '\n';
return 1;
}
std::cerr << "map: " << r << '\n';
std::cerr <<
"keys: " << r.
getKeys() <<
'\n';
std::cerr << "map: " << r << '\n';
std::cerr << "copy: " << r2 << '\n';
r3 = r;
std::cerr << "assign: " << r3 << '\n';
std::cout << "Initial values: " << i << ',' << f << ',' << s << '\n';
std::cout << '\n';
std::cout << "--- Traversing user parameters --- \n";
std::cout << '\n';
for (int i = 1; i < argc; ++i) {
std::cout << "assign:" << argv[i] << '\n';
try {
const char * v = argv[i];
}
catch (std::runtime_error & e) {
std::cerr << '\t' << e.what() << std::endl;
std::cout << "\t(leaving remaining values unassigned)\n";
}
std::cout << "result: " << r << '\n';
std::cout << '\n';
}
drain::getLog().
setVerbosity(i);
mout.
debug3() <<
"map: " << r << mout.
endl;
mout.
debug2() <<
"map: " << r << mout.endl;
mout.
debug() <<
"map: " << r << mout.endl;
mout.
info() <<
"map: " << r << mout.endl;
mout.
note() <<
"map: " << r << mout.endl;
mout.
warn() <<
"map: " << r << mout.endl;
return 0;
}
LogSourc e is the means for a function or any program segment to "connect" to a Log.
Definition: Log.h:308
Logger & note(const TT &... args)
For top-level information.
Definition: Log.h:485
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
Logger & debug2(const TT &... args)
Debug information.
Definition: Log.h:686
Definition: ReferenceMap.h:207
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
@ LINK
Definition: ReferenceMap.h:384
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...
Definition: SmartMap.h:311
VariableT is a final class applied through typedefs Variable, Reference and FlexibleVariable.
Definition: VariableT.h:87