Classdesc 3.44
polyAccessXMLPack.h
1/*
2 @copyright Russell Standish 2000-2013
3 @author Russell Standish
4 This file is part of Classdesc
5
6 Open source licensed under the MIT license. See LICENSE for details.
7*/
8
9#ifndef CLASSDESC_POLY_ACCESS_XML_PACK_H
10#define CLASSDESC_POLY_ACCESS_XML_PACK_H
11
12namespace classdesc
13{
14#ifdef CLASSDESC_XML_PACK_BASE_H
15#ifdef CLASSDESC_POLYXMLBASE_H
16 // polymorphic version
17 template <class T>
19 xml_pack_smart_ptr(xml_pack_t& x, const string& d, const T& a)
20 {
21 if (a.get())
22 {
23 // requires a bit of jiggery-pokery to get the tag wrappers
24 // happening in the right order
25 xml_pack_t::Tag t(x,d);
26 ::xml_pack(x,d+".type",a->type());
27 a->xml_pack(x,d);
28 }
29 }
30
31 // non polymorphic version
32 template <class T>
34#else
35 template <class T>
36 void
37#endif
38 xml_pack_smart_ptr(xml_pack_t& x, const string& d, const T& a)
39 {
40 if (a)
41 ::xml_pack(x,d,*a);
42 }
43
44
45 // special handling of shared pointers to avoid a double wrapping problem
46 template<class T>
47 void xml_pack(xml_pack_t& x, const string& d, shared_ptr<T>& a)
48 {xml_pack_smart_ptr(x,d,a);}
49
50#if defined(__cplusplus) && __cplusplus<=201402
51#if defined(__GNUC__) && !defined(__ICC) && !defined(__clang__)
52#pragma GCC diagnostic push
53#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
54#endif
55 template<class T>
56 void xml_pack(xml_pack_t& x, const string& d, std::auto_ptr<T>& a)
57 {xml_pack_smart_ptr(x,d,a);}
58#if defined(__GNUC__) && !defined(__ICC) && !defined(__clang__)
59#pragma GCC diagnostic pop
60#endif
61#endif
62
63#if defined(__cplusplus) && __cplusplus >= 201103L
64 template<class T, class D>
65 void xml_pack(xml_pack_t& x, const string& d, std::unique_ptr<T,D>& a)
66 {xml_pack_smart_ptr(x,d,a);}
67#endif
68
69#endif
70
71#ifdef CLASSDESC_XML_UNPACK_BASE_H
72#ifdef CLASSDESC_POLYXMLBASE_H
73 // polymorphic version
74 template <class T>
76 xml_unpack_smart_ptr(xml_unpack_t& x, const string& d, T& a,
77 dummy<0> dum=0)
78 {
79 if (x.exists(d+".type"))
80 {
81 typename T::element_type::Type type;
82 ::xml_unpack(x,d+".type",type);
83 a.reset(T::element_type::create(type));
84 a->xml_unpack(x,d);
85 }
86 else
87 a.reset();
88 }
89
90 // non polymorphic version
91 template <class T>
93#else
94 template <class T>
95 void
96#endif
97 xml_unpack_smart_ptr(xml_unpack_t& x, const string& d,
98 T& a, dummy<1> dum=0)
99 {
100 if (x.exists(d))
101 {
102 a.reset(new typename T::element_type);
103 ::xml_unpack(x,d,*a);
104 }
105 else
106 a.reset();
107 }
108
109 // const argument versions of above
110#ifdef CLASSDESC_POLYXMLBASE_H
111 // polymorphic version
112 template <class T>
114 xml_unpack_smart_ptr(xml_unpack_t& x, const string& d, const T& a,
115 dummy<0> dum=0)
116 {
117 if (x.exists(d+".type"))
118 {
119 typename T::element_type::Type type;
120 ::xml_unpack(x,d+".type",type);
121 T tmp(T::element_type::create(type));
122 tmp->xml_unpack(x,d);
123 }
124 }
125
126 // non polymorphic version
127 template <class T>
129#else
130 template <class T>
131 void
132#endif
133 xml_unpack_smart_ptr(xml_unpack_t& x, const string& d,
134 const T& a, dummy<1> dum=0)
135 {
136 if (x.exists(d))
137 {
138 T tmp(new typename T::element_type);
139 ::xml_unpack(x,d,*tmp);
140 }
141 }
142#endif
143}
144
145namespace classdesc_access
146{
147 namespace cd = classdesc;
148
149#ifdef CLASSDESC_XML_PACK_BASE_H
150 template <class T>
151 struct access_xml_pack<cd::shared_ptr<T> >
152 {
153 void operator()(cd::xml_pack_t& x, const cd::string& d, const cd::shared_ptr<T>& a)
154 {xml_pack_smart_ptr(x,d,a);}
155 };
156
157#if defined(__cplusplus) && __cplusplus<=201402
158#if defined(__GNUC__) && !defined(__ICC) && !defined(__clang__)
159#pragma GCC diagnostic push
160#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
161#endif
162 template <class T>
163 struct access_xml_pack<std::auto_ptr<T> >
164 {
165 void operator()(cd::xml_pack_t& x, const cd::string& d, const std::auto_ptr<T>& a)
166 {xml_pack_smart_ptr(x,d,a);}
167 };
168#if defined(__GNUC__) && !defined(__ICC) && !defined(__clang__)
169#pragma GCC diagnostic pop
170#endif
171#endif
172
173#if defined(__cplusplus) && __cplusplus >= 201103L
174 template <class T>
175 struct access_xml_pack<std::unique_ptr<T> >
176 {
177 void operator()(cd::xml_pack_t& x, const cd::string& d, const std::unique_ptr<T>& a)
178 {xml_pack_smart_ptr(x,d,a);}
179 };
180#endif
181#endif
182
183#ifdef CLASSDESC_XML_UNPACK_BASE_H
184 template <class T>
185 struct access_xml_unpack<cd::shared_ptr<T> >
186 {
187 template <class U>
188 void operator()(cd::xml_unpack_t& x, const cd::string& d, U& a)
189 {xml_unpack_smart_ptr(x,d,a);}
190 };
191
192#if defined(__cplusplus) && __cplusplus<=201402
193#if defined(__GNUC__) && !defined(__ICC) && !defined(__clang__)
194#pragma GCC diagnostic push
195#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
196#endif
197 template <class T>
198 struct access_xml_unpack<std::auto_ptr<T> >
199 {
200 template <class U>
201 void operator()(cd::xml_unpack_t& x, const cd::string& d, U& a)
202 {xml_unpack_smart_ptr(x,d,a);}
203 };
204#if defined(__GNUC__) && !defined(__ICC) && !defined(__clang__)
205#pragma GCC diagnostic pop
206#endif
207#endif
208
209#if defined(__cplusplus) && __cplusplus >= 201103L
210 template <class T>
211 struct access_xml_unpack<std::unique_ptr<T> >
212 {
213 template <class U>
214 void operator()(cd::xml_unpack_t& x, const cd::string& d, U& a)
215 {xml_unpack_smart_ptr(x,d,a);}
216 };
217#endif
218#endif
219}
220
221
222#endif
<utility structure for handling tag/endtag
Definition xml_pack_base.h:110
Definition xml_pack_base.h:56
Definition xml_unpack_base.h:317
Contains access_* structs, and nothing else. These structs are used to gain access to private members...
Definition classdesc_access.h:20
Contains definitions related to classdesc functionality.
Definition classdesc.h:299
controlled template specialisation: stolen from boost::enable_if.
Definition classdesc.h:282
Definition classdesc_access.h:23
Definition classdesc_access.h:24