jsonPrimitive.hh 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /**
  2. * jsonPrimitive.hh for jsonstroller
  3. *
  4. * Author: isundil <isundill@gmail.com>
  5. **/
  6. #pragma once
  7. #include "jsonElement.hh"
  8. class AJSonPrimitive
  9. {
  10. public:
  11. virtual ~AJSonPrimitive();
  12. };
  13. template <typename T>
  14. class JSonPrimitive: public JSonElement, public AJSonPrimitive
  15. {
  16. public:
  17. JSonPrimitive(JSonContainer *parent, T const &v);
  18. virtual ~JSonPrimitive();
  19. T getValue() const;
  20. virtual std::string stringify() const;
  21. bool operator<(const JSonPrimitive<T> &other) const;
  22. bool operator==(const JSonPrimitive<T> &other) const;
  23. protected:
  24. const T value;
  25. };
  26. template<typename T>
  27. JSonPrimitive<T>::JSonPrimitive(JSonContainer *parent, T const &v): JSonElement(parent), value(v)
  28. { }
  29. template<typename T>
  30. T JSonPrimitive<T>::getValue() const
  31. {
  32. return value;
  33. }
  34. template<typename T>
  35. bool JSonPrimitive<T>::operator<(const JSonPrimitive<T> &other) const
  36. {
  37. return value < other.value;
  38. }
  39. template<typename T>
  40. bool JSonPrimitive<T>::operator==(const JSonPrimitive<T> &other) const
  41. {
  42. return value == other.value;
  43. }