summaryrefslogtreecommitdiff
path: root/src/json.hpp
blob: 6f19ddd06c4cfdac68b6ec3173e711ef79ff4ace (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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);
	}

}