-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpolyAccessXMLPack.h
222 lines (200 loc) · 5.78 KB
/
polyAccessXMLPack.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
/*
@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_POLY_ACCESS_XML_PACK_H
#define CLASSDESC_POLY_ACCESS_XML_PACK_H
namespace classdesc
{
#ifdef CLASSDESC_XML_PACK_BASE_H
#ifdef CLASSDESC_POLYXMLBASE_H
// polymorphic version
template <class T>
typename enable_if<is_base_of<PolyXMLBase, typename T::element_type>, void>::T
xml_pack_smart_ptr(xml_pack_t& x, const string& d, const T& a)
{
if (a.get())
{
// requires a bit of jiggery-pokery to get the tag wrappers
// happening in the right order
xml_pack_t::Tag t(x,d);
::xml_pack(x,d+".type",a->type());
a->xml_pack(x,d);
}
}
// non polymorphic version
template <class T>
typename enable_if<Not<is_base_of<PolyXMLBase, typename T::element_type> >, void>::T
#else
template <class T>
void
#endif
xml_pack_smart_ptr(xml_pack_t& x, const string& d, const T& a)
{
if (a)
::xml_pack(x,d,*a);
}
// special handling of shared pointers to avoid a double wrapping problem
template<class T>
void xml_pack(xml_pack_t& x, const string& d, shared_ptr<T>& a)
{xml_pack_smart_ptr(x,d,a);}
#if defined(__cplusplus) && __cplusplus<=201402
#if defined(__GNUC__) && !defined(__ICC) && !defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
template<class T>
void xml_pack(xml_pack_t& x, const string& d, std::auto_ptr<T>& a)
{xml_pack_smart_ptr(x,d,a);}
#if defined(__GNUC__) && !defined(__ICC) && !defined(__clang__)
#pragma GCC diagnostic pop
#endif
#endif
#if defined(__cplusplus) && __cplusplus >= 201103L
template<class T, class D>
void xml_pack(xml_pack_t& x, const string& d, std::unique_ptr<T,D>& a)
{xml_pack_smart_ptr(x,d,a);}
#endif
#endif
#ifdef CLASSDESC_XML_UNPACK_BASE_H
#ifdef CLASSDESC_POLYXMLBASE_H
// polymorphic version
template <class T>
typename enable_if<is_base_of<PolyXMLBase, typename T::element_type>, void>::T
xml_unpack_smart_ptr(xml_unpack_t& x, const string& d, T& a,
dummy<0> dum=0)
{
if (x.exists(d+".type"))
{
typename T::element_type::Type type;
::xml_unpack(x,d+".type",type);
a.reset(T::element_type::create(type));
a->xml_unpack(x,d);
}
else
a.reset();
}
// non polymorphic version
template <class T>
typename enable_if<Not<is_base_of<PolyXMLBase, typename T::element_type> >, void>::T
#else
template <class T>
void
#endif
xml_unpack_smart_ptr(xml_unpack_t& x, const string& d,
T& a, dummy<1> dum=0)
{
if (x.exists(d))
{
a.reset(new typename T::element_type);
::xml_unpack(x,d,*a);
}
else
a.reset();
}
// const argument versions of above
#ifdef CLASSDESC_POLYXMLBASE_H
// polymorphic version
template <class T>
typename enable_if<is_base_of<PolyXMLBase, typename T::element_type>, void>::T
xml_unpack_smart_ptr(xml_unpack_t& x, const string& d, const T& a,
dummy<0> dum=0)
{
if (x.exists(d+".type"))
{
typename T::element_type::Type type;
::xml_unpack(x,d+".type",type);
T tmp(T::element_type::create(type));
tmp->xml_unpack(x,d);
}
}
// non polymorphic version
template <class T>
typename enable_if<Not<is_base_of<PolyXMLBase, typename T::element_type> >, void>::T
#else
template <class T>
void
#endif
xml_unpack_smart_ptr(xml_unpack_t& x, const string& d,
const T& a, dummy<1> dum=0)
{
if (x.exists(d))
{
T tmp(new typename T::element_type);
::xml_unpack(x,d,*tmp);
}
}
#endif
}
namespace classdesc_access
{
namespace cd = classdesc;
#ifdef CLASSDESC_XML_PACK_BASE_H
template <class T>
struct access_xml_pack<cd::shared_ptr<T> >
{
void operator()(cd::xml_pack_t& x, const cd::string& d, const cd::shared_ptr<T>& a)
{xml_pack_smart_ptr(x,d,a);}
};
#if defined(__cplusplus) && __cplusplus<=201402
#if defined(__GNUC__) && !defined(__ICC) && !defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
template <class T>
struct access_xml_pack<std::auto_ptr<T> >
{
void operator()(cd::xml_pack_t& x, const cd::string& d, const std::auto_ptr<T>& a)
{xml_pack_smart_ptr(x,d,a);}
};
#if defined(__GNUC__) && !defined(__ICC) && !defined(__clang__)
#pragma GCC diagnostic pop
#endif
#endif
#if defined(__cplusplus) && __cplusplus >= 201103L
template <class T>
struct access_xml_pack<std::unique_ptr<T> >
{
void operator()(cd::xml_pack_t& x, const cd::string& d, const std::unique_ptr<T>& a)
{xml_pack_smart_ptr(x,d,a);}
};
#endif
#endif
#ifdef CLASSDESC_XML_UNPACK_BASE_H
template <class T>
struct access_xml_unpack<cd::shared_ptr<T> >
{
template <class U>
void operator()(cd::xml_unpack_t& x, const cd::string& d, U& a)
{xml_unpack_smart_ptr(x,d,a);}
};
#if defined(__cplusplus) && __cplusplus<=201402
#if defined(__GNUC__) && !defined(__ICC) && !defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
template <class T>
struct access_xml_unpack<std::auto_ptr<T> >
{
template <class U>
void operator()(cd::xml_unpack_t& x, const cd::string& d, U& a)
{xml_unpack_smart_ptr(x,d,a);}
};
#if defined(__GNUC__) && !defined(__ICC) && !defined(__clang__)
#pragma GCC diagnostic pop
#endif
#endif
#if defined(__cplusplus) && __cplusplus >= 201103L
template <class T>
struct access_xml_unpack<std::unique_ptr<T> >
{
template <class U>
void operator()(cd::xml_unpack_t& x, const cd::string& d, U& a)
{xml_unpack_smart_ptr(x,d,a);}
};
#endif
#endif
}
#endif