diff options
Diffstat (limited to 'project2/variables.cpp')
-rw-r--r-- | project2/variables.cpp | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/project2/variables.cpp b/project2/variables.cpp index c5907ed..29e6353 100644 --- a/project2/variables.cpp +++ b/project2/variables.cpp @@ -33,8 +33,27 @@ enum VT_typeID { }; static +VT_typeID +getVariableTypeFromName(const std::string & src) +{ + if (src.empty()) return String; + if (src == "string") return String; + if (src == "stringptr") return StringPtr; + if (src == "int") return Int; + if (src == "uint") return UInt; + if (src == "lint") return LInt; + if (src == "luint") return LUInt; + if (src == "llint") return LLInt; + if (src == "lluint") return LLUInt; + if (src == "float") return Float; + if (src == "double") return Double; + if (src == "datetime") return DateTime; + if (src == "datetimeptr") return DateTimePtr; + throw UnknownVariableType(); +} +static VariableType -makeVariableType(const Glib::ustring & src, const std::string & type, const VT_typeID format = DefaultType) +makeVariableType(const Glib::ustring & src, const VT_typeID format = DefaultType) { switch (format) { case DefaultType: @@ -100,8 +119,8 @@ VariableType::operator=(const VariableType & vt) class VariableLiteral : public VariableImpl { public: - VariableLiteral(const Glib::ustring & src, const std::string & type = std::string()) : - val(makeVariableType(src, type)) + VariableLiteral(const Glib::ustring & src, const VT_typeID format = DefaultType) : + val(makeVariableType(src, format)) { } @@ -356,7 +375,7 @@ Variable::Variable(const xmlpp::Element * e, const Glib::ustring & n, bool requi else if (source == "config") var = new VariableConfig(c); else if (source == "literal" || source.empty()) - var = new VariableLiteral(c->get_attribute_value("value"), c->get_attribute_value("type")); + var = new VariableLiteral(c->get_attribute_value("value"), getVariableTypeFromName(c->get_attribute_value("type"))); else throw UnknownVariableSource(); return; |