|
@@ -273,7 +273,7 @@ class Value;
|
|
*/
|
|
*/
|
|
class GenValue;
|
|
class GenValue;
|
|
typedef std::map<std::string, GenValue*> ValueSet;
|
|
typedef std::map<std::string, GenValue*> ValueSet;
|
|
-class GenValue{
|
|
|
|
|
|
+class GenValue {
|
|
private:
|
|
private:
|
|
/**
|
|
/**
|
|
* The name of the value.
|
|
* The name of the value.
|
|
@@ -313,11 +313,9 @@ class GenValue{
|
|
*/
|
|
*/
|
|
inline static std::map<std::pair<const std::type_index, const std::string>, GenValue*> aliases;
|
|
inline static std::map<std::pair<const std::type_index, const std::string>, GenValue*> aliases;
|
|
|
|
|
|
- bool logging_enabled;
|
|
|
|
-
|
|
|
|
public:
|
|
public:
|
|
GenValue(const std::type_index&& ti, const std::string& name, const std::string& alias)
|
|
GenValue(const std::type_index&& ti, const std::string& name, const std::string& alias)
|
|
- :name(name), value_valid(false), logging_enabled(false){
|
|
|
|
|
|
+ :name(name), value_valid(false) {
|
|
if (alias != "")
|
|
if (alias != "")
|
|
INFO("Registered value: \"" << name << "\" with alias: \"" << alias << "\"");
|
|
INFO("Registered value: \"" << name << "\" with alias: \"" << alias << "\"");
|
|
else
|
|
else
|
|
@@ -331,15 +329,6 @@ class GenValue{
|
|
return name;
|
|
return name;
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * If logging is enabled for this value, this function should be
|
|
|
|
- * implemented to format the value to a string and place it as an INFO
|
|
|
|
- * entry in the log file. Useful for debugging, but may produce a lot of
|
|
|
|
- * output.
|
|
|
|
- */
|
|
|
|
- virtual void log() = 0;
|
|
|
|
-
|
|
|
|
static void reset(){
|
|
static void reset(){
|
|
for (auto val : values){
|
|
for (auto val : values){
|
|
if (val.second != nullptr){
|
|
if (val.second != nullptr){
|
|
@@ -416,27 +405,14 @@ std::ostream& operator<<(std::ostream& os, GenValue& gv){
|
|
* calling get_value().
|
|
* calling get_value().
|
|
*/
|
|
*/
|
|
template <typename T>
|
|
template <typename T>
|
|
-class Value : public GenValue{
|
|
|
|
- protected:
|
|
|
|
- std::function<std::string(T)> value_to_string;
|
|
|
|
-
|
|
|
|
|
|
+class Value : public GenValue {
|
|
public:
|
|
public:
|
|
Value(const std::string& name, const std::string& alias="")
|
|
Value(const std::string& name, const std::string& alias="")
|
|
- :value_to_string([](T){return "";}),
|
|
|
|
- GenValue(typeid(T), name, alias){ }
|
|
|
|
|
|
+ :GenValue(typeid(T), name, alias){ }
|
|
|
|
|
|
/** Calculate, if necessary, and return the value held by this object.
|
|
/** Calculate, if necessary, and return the value held by this object.
|
|
*/
|
|
*/
|
|
virtual T& get_value() = 0;
|
|
virtual T& get_value() = 0;
|
|
-
|
|
|
|
- void enable_logging(const std::function<std::string(T)>& value_to_string = [](T){return "";}){
|
|
|
|
- logging_enabled = true;
|
|
|
|
- this->value_to_string = value_to_string;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- void disable_logging(){
|
|
|
|
- logging_enabled = false;
|
|
|
|
- }
|
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
@@ -459,23 +435,16 @@ class ObservedValue : public Value<T>{
|
|
:Value<T>(name, alias),
|
|
:Value<T>(name, alias),
|
|
val_ref(val_ref){ }
|
|
val_ref(val_ref){ }
|
|
|
|
|
|
- void log(){
|
|
|
|
- if (util::debug_on) {
|
|
|
|
- std::cout << "Calculating Value: " << this->get_name() << std::endl;
|
|
|
|
- }
|
|
|
|
- if(this->logging_enabled){
|
|
|
|
- INFO(this->get_name() << ": " << this->value_to_string(*val_ref));
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
static std::string fmt_name(const std::string& name){
|
|
static std::string fmt_name(const std::string& name){
|
|
return name;
|
|
return name;
|
|
}
|
|
}
|
|
|
|
|
|
T& get_value(){
|
|
T& get_value(){
|
|
if (!this->value_valid){
|
|
if (!this->value_valid){
|
|
|
|
+ if (util::debug_on) {
|
|
|
|
+ std::cout << "Calculating Value: " << this->get_name() << std::endl;
|
|
|
|
+ }
|
|
this->value_valid = true;
|
|
this->value_valid = true;
|
|
- this->log();
|
|
|
|
}
|
|
}
|
|
return *val_ref;
|
|
return *val_ref;
|
|
}
|
|
}
|
|
@@ -515,21 +484,13 @@ class DerivedValue : public Value<T>{
|
|
DerivedValue(const std::string& name, const std::string& alias="")
|
|
DerivedValue(const std::string& name, const std::string& alias="")
|
|
:Value<T>(name, alias){ }
|
|
:Value<T>(name, alias){ }
|
|
|
|
|
|
- void log(){
|
|
|
|
- if (util::debug_on) {
|
|
|
|
- std::cout << "Calculating Value: " << this->get_name() << std::endl;
|
|
|
|
- }
|
|
|
|
- if(this->logging_enabled){
|
|
|
|
- INFO(this->get_name() << ": " << this->value_to_string(value));
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
T& get_value(){
|
|
T& get_value(){
|
|
- DEBUG("Getting Value: " << this->get_name());
|
|
|
|
if (!this->value_valid){
|
|
if (!this->value_valid){
|
|
|
|
+ if (util::debug_on) {
|
|
|
|
+ std::cout << "Calculating Value: " << this->get_name() << std::endl;
|
|
|
|
+ }
|
|
update_value();
|
|
update_value();
|
|
this->value_valid = true;
|
|
this->value_valid = true;
|
|
- this->log();
|
|
|
|
}
|
|
}
|
|
return value;
|
|
return value;
|
|
}
|
|
}
|
|
@@ -653,6 +614,7 @@ namespace impl {
|
|
return head1->get_name() + "," + zip_fmt_name<Head2, Tail...>(head2, tail...);
|
|
return head1->get_name() + "," + zip_fmt_name<Head2, Tail...>(head2, tail...);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Zips a series of vectors together. Can be combined with Map to
|
|
* Zips a series of vectors together. Can be combined with Map to
|
|
* yield a Value whose elements are individually a function of the
|
|
* yield a Value whose elements are individually a function of the
|