-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpolyJsonBase.h
51 lines (40 loc) · 1.11 KB
/
polyJsonBase.h
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*
@copyright Russell Standish 2000-2013
@author Russell Standish
This file is part of Classdesc
Open source licensed under the MIT license. See LICENSE for details.
*/
#ifndef CLASSDESC_POLYJSONBASE_H
#define CLASSDESC_POLYJSONBASE_H
namespace classdesc
{
struct PolyJsonBase
{
virtual void json_pack(json_pack_t&, const string&) const=0;
virtual void json_unpack(json_unpack_t&, const string&)=0;
virtual ~PolyJsonBase() {}
};
template <class T>
struct PolyJson: virtual public PolyJsonBase
{
void json_pack(json_pack_t& x, const string& d) const
{::json_pack(x,d,dynamic_cast<const T&>(*this));}
void json_unpack(json_unpack_t& x, const string& d)
{::json_unpack(x,d,static_cast<T&>(*this));}
};
template <> struct tn<PolyJsonBase>
{
static std::string name()
{return "classdesc::PolyJsonBase";}
};
template <class T> struct tn<PolyJson<T> >
{
static std::string name()
{return "classdesc::PolyJson<"+typeName<T>()+">";}
};
#ifdef _CLASSDESC
#pragma omit typeName PolyJsonBase
#pragma omit typeName PolyJson<T>
#endif
}
#endif