summaryrefslogtreecommitdiff
path: root/src/json.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/json.hpp')
-rw-r--r--src/json.hpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/json.hpp b/src/json.hpp
new file mode 100644
index 0000000..6f19ddd
--- /dev/null
+++ b/src/json.hpp
@@ -0,0 +1,28 @@
+#include "json.h"
+
+#include <stdexcept>
+#include <iostream>
+
+namespace TehJSON
+{
+
+ template<typename T>
+ T& JSON::get()
+ {
+ if(!isLeaf)
+ throw std::runtime_error("Node is not a leaf!");
+
+ return *static_cast<T*>(data.get());
+ }
+
+ template<typename T>
+ void JSON::set(T value)
+ {
+ if(children.size() != 0)
+ throw std::runtime_error("Node is not a leaf (has children already)!");
+ isLeaf = true;
+ dataSerializer = JSON::serializeData<T>;
+ data = std::make_shared<T>(value);
+ }
+
+}