/** * jsonPrimitive.hh for jsonstroller * * Author: isundil **/ #pragma once #include "jsonElement.hh" class Null {}; //Null primitive class AJSonPrimitive { public: virtual ~AJSonPrimitive(); virtual std::string getTypeStr() const =0; bool sameType(const AJSonPrimitive *other) const; }; template class JSonPrimitive: public JSonElement, public AJSonPrimitive { public: JSonPrimitive(JSonContainer *parent, T const &v); virtual ~JSonPrimitive(); /** * get value as raw type **/ T getValue() const; /** * get stringified value **/ std::string stringify() const; std::string getTypeStr() const; bool operator<(const JSonPrimitive &other) const; bool operator==(const JSonPrimitive &other) const; protected: /** * convert raw type to string **/ virtual std::string toString() const; /** * raw value **/ const T value; /** * stringified value **/ const std::string stringValue; }; template JSonPrimitive::JSonPrimitive(JSonContainer *parent, T const &v): JSonElement(parent), value(v), stringValue(toString()) { } template T JSonPrimitive::getValue() const { return value; } template std::string JSonPrimitive::stringify() const { return stringValue; } template bool JSonPrimitive::operator<(const JSonPrimitive &other) const { return value < other.value; } template bool JSonPrimitive::operator==(const JSonPrimitive &other) const { return value == other.value; }