A simple scripting language in C++
Ferenc Szontágh
2025-04-18 6cc2945c1d1e6ca7bad0542c79de423df5e2db8b
src/Symbols/Value.hpp
@@ -4,6 +4,7 @@
#include <algorithm>
#include <stdexcept>
#include <string>
#include <map>
#include <variant>
#include "VariableTypes.hpp"
@@ -12,7 +13,8 @@
class Value {
  public:
    using Variant = std::variant<int, double, float, std::string, bool>;
    using ObjectMap = std::map<std::string, Value>;
    using Variant = std::variant<int, double, float, std::string, bool, ObjectMap>;
    Value() = default;
@@ -27,6 +29,10 @@
    Value(const char * v) : value_(std::string(v)) { type_ = Symbols::Variables::Type::STRING; }
    Value(bool v) : value_(v) { type_ = Symbols::Variables::Type::BOOLEAN; }
    /**
     * @brief Construct an object value from a map of member names to Values.
     */
    Value(const ObjectMap & v) : value_(v) { type_ = Symbols::Variables::Type::OBJECT; }
    Value(const std::string & str, bool autoDetectType) { *this = fromString(str, autoDetectType); }
@@ -70,6 +76,8 @@
                    return val ? "true" : "false";
                } else if constexpr (std::is_same_v<T, std::string>) {
                    return val;
                } else if constexpr (std::is_same_v<T, ObjectMap>) {
                    return "[object]";
                } else {
                    return std::to_string(val);
                }