|
@@ -63,8 +63,18 @@
|
|
|
*/
|
|
|
namespace fv {
|
|
|
|
|
|
+ class GenValue; // Forward declaration
|
|
|
template<typename T>
|
|
|
- class Value;
|
|
|
+ class Value; // Forward declaration
|
|
|
+
|
|
|
+ /**
|
|
|
+ * A static mapping containing all created Value objects.
|
|
|
+ * Every value object must have a unique name, and this name is used as
|
|
|
+ * a key in values to that object. This is used to enable more dynamic
|
|
|
+ * creation of objects as well as avoiding the uneccesary passing of
|
|
|
+ * pointers.
|
|
|
+ */
|
|
|
+ std::map<std::pair<const std::type_index, const std::string>, GenValue *> values;
|
|
|
|
|
|
/**
|
|
|
* A type-agnostic value.
|
|
@@ -72,10 +82,6 @@ namespace fv {
|
|
|
* it is possible to handle collections of them. GenValue also provides the
|
|
|
* rest of the type-independent interface to Value.
|
|
|
*/
|
|
|
- class GenValue;
|
|
|
-
|
|
|
- typedef std::map<std::string, GenValue *> ValueSet;
|
|
|
-
|
|
|
class GenValue {
|
|
|
private:
|
|
|
/**
|
|
@@ -98,34 +104,11 @@ namespace fv {
|
|
|
this->value_valid = false;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * A static mapping containing all created Value objects.
|
|
|
- * Every value object must have a unique name, and this name is used as
|
|
|
- * a key in values to that object. This is used to enable more dynamic
|
|
|
- * creation of objects as well as avoiding the uneccesary passing of
|
|
|
- * pointers.
|
|
|
- */
|
|
|
- inline static std::map<std::pair<const std::type_index, const std::string>, GenValue *> values;
|
|
|
-
|
|
|
- /**
|
|
|
- * Composite value names are typically nested. This makes complex
|
|
|
- * values have rather unwieldy names. Therefore, one can declare
|
|
|
- * aliases which allow for more human-usable names to be used. When a
|
|
|
- * value is requested by name, an alias with that value takes precidence
|
|
|
- * over a name with that value.
|
|
|
- */
|
|
|
- inline static std::map<std::pair<const std::type_index, const std::string>, GenValue *> aliases;
|
|
|
-
|
|
|
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)
|
|
|
: name(name), value_valid(false) {
|
|
|
- if (alias != "")
|
|
|
- INFO("Registered value: \"" << name << "\" with alias: \"" << alias << "\"");
|
|
|
- else
|
|
|
- INFO("Registered value: \"" << name);
|
|
|
+ INFO("Registered value: \"" << name);
|
|
|
values[std::make_pair(ti, name)] = this;
|
|
|
- if (alias != "")
|
|
|
- GenValue::alias(ti, alias, this);
|
|
|
}
|
|
|
|
|
|
const std::string &get_name() {
|
|
@@ -144,24 +127,7 @@ namespace fv {
|
|
|
static Value<T> *get_value(const std::string &name) {
|
|
|
const std::type_index &ti = typeid(T);
|
|
|
auto lookup_id = std::make_pair(ti, name);
|
|
|
- if (aliases[lookup_id] != nullptr)
|
|
|
- return (Value<T> *) aliases[lookup_id];
|
|
|
- else
|
|
|
- return (Value<T> *) values[lookup_id];
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- static void alias(const std::type_index &ti, const std::string &name, GenValue *value) {
|
|
|
- auto lookup_id = std::make_pair(ti, name);
|
|
|
- if (aliases[lookup_id] != nullptr) {
|
|
|
- WARNING("WARNING: alias \"" << name << "\" overrides previous entry.");
|
|
|
- }
|
|
|
- aliases[lookup_id] = value;
|
|
|
- }
|
|
|
-
|
|
|
- template<typename T>
|
|
|
- static void alias(const std::string &name, Value<T> *value) {
|
|
|
- alias(typeid(T), name, value);
|
|
|
+ return (Value<T> *) values[lookup_id];
|
|
|
}
|
|
|
|
|
|
static std::string summary() {
|
|
@@ -173,21 +139,6 @@ namespace fv {
|
|
|
if (value == nullptr) continue;
|
|
|
ss << "\tVALUE::\"" << key.second << "\" at address " << value << std::endl;
|
|
|
}
|
|
|
- ss << "And these aliases:" << std::endl;
|
|
|
- for (auto item : aliases) {
|
|
|
- auto &key = item.first;
|
|
|
- auto &value = item.second;
|
|
|
- std::string orig("VOID");
|
|
|
- if (value == nullptr) continue;
|
|
|
- for (auto v_item : values) {
|
|
|
- auto &v_value = v_item.second;
|
|
|
- if (v_value == value) {
|
|
|
- orig = v_value->get_name();
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- ss << "\tALIAS::\"" << key.second << "\" referring to \"" << orig << "\"" << std::endl;
|
|
|
- }
|
|
|
return ss.str();
|
|
|
}
|
|
|
|
|
@@ -212,8 +163,8 @@ namespace fv {
|
|
|
template<typename T>
|
|
|
class Value : public GenValue {
|
|
|
public:
|
|
|
- Value(const std::string &name, const std::string &alias = "")
|
|
|
- : GenValue(typeid(T), name, alias) {}
|
|
|
+ Value(const std::string &name)
|
|
|
+ : GenValue(typeid(T), name) {}
|
|
|
|
|
|
/** Calculate, if necessary, and return the value held by this object.
|
|
|
*/
|
|
@@ -221,7 +172,7 @@ namespace fv {
|
|
|
|
|
|
/** Alias to get
|
|
|
*/
|
|
|
- virtual T &operator() () = 0;
|
|
|
+ virtual T &operator()() = 0;
|
|
|
};
|
|
|
|
|
|
|
|
@@ -240,9 +191,8 @@ namespace fv {
|
|
|
T *val_ref;
|
|
|
|
|
|
public:
|
|
|
- ObservedValue(const std::string &name, T *val_ref, const std::string &alias = "")
|
|
|
- : Value<T>(name, alias),
|
|
|
- val_ref(val_ref) {}
|
|
|
+ ObservedValue(const std::string &name, T *val_ref)
|
|
|
+ : Value<T>(name), val_ref(val_ref) {}
|
|
|
|
|
|
static std::string fmt_name(const std::string &name) {
|
|
|
return name;
|
|
@@ -258,7 +208,7 @@ namespace fv {
|
|
|
return *val_ref;
|
|
|
}
|
|
|
|
|
|
- T &operator() (){
|
|
|
+ T &operator()() {
|
|
|
return this->get();
|
|
|
}
|
|
|
};
|
|
@@ -295,8 +245,8 @@ namespace fv {
|
|
|
virtual void update_value() = 0;
|
|
|
|
|
|
public:
|
|
|
- DerivedValue(const std::string &name, const std::string &alias = "")
|
|
|
- : Value<T>(name, alias) {}
|
|
|
+ DerivedValue(const std::string &name)
|
|
|
+ : Value<T>(name) {}
|
|
|
|
|
|
T &get() {
|
|
|
if (!this->value_valid) {
|
|
@@ -309,7 +259,7 @@ namespace fv {
|
|
|
return value;
|
|
|
}
|
|
|
|
|
|
- T &operator() () {
|
|
|
+ T &operator()() {
|
|
|
return this->get();
|
|
|
}
|
|
|
};
|
|
@@ -325,8 +275,8 @@ namespace fv {
|
|
|
void update_value() {}
|
|
|
|
|
|
public:
|
|
|
- PointerValue(const std::string &name, T *ptr, const std::string alias = "")
|
|
|
- : DerivedValue<T *>(name, alias) {
|
|
|
+ PointerValue(const std::string &name, T *ptr)
|
|
|
+ : DerivedValue<T *>(name) {
|
|
|
this->value = ptr;
|
|
|
}
|
|
|
};
|
|
@@ -348,8 +298,8 @@ namespace fv {
|
|
|
}
|
|
|
|
|
|
public:
|
|
|
- ObjectValue(const std::string &name, T **ptr, const std::string alias = "")
|
|
|
- : DerivedValue<T>(name, alias),
|
|
|
+ ObjectValue(const std::string &name, T **ptr)
|
|
|
+ : DerivedValue<T>(name),
|
|
|
obj_pointer(ptr) {}
|
|
|
};
|
|
|
|
|
@@ -367,11 +317,10 @@ namespace fv {
|
|
|
return "const::" + name;
|
|
|
}
|
|
|
|
|
|
- ConstantValue(const std::string &name, T const_value, const std::string alias = "")
|
|
|
- : DerivedValue<T>(fmt_name(name), alias) {
|
|
|
+ ConstantValue(const std::string &name, T const_value)
|
|
|
+ : DerivedValue<T>(fmt_name(name)) {
|
|
|
this->value = const_value;
|
|
|
}
|
|
|
};
|
|
|
-
|
|
|
}
|
|
|
#endif // value_hpp
|