Classdesc 3.44
xml_pack_epilogue.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_XML_PACK_EPILOGUE_H
10#define CLASSDESC_XML_PACK_EPILOGUE_H
11#include <typeName_epilogue.h>
12#include "polyAccessXMLPack.h"
13#include "xml_pack-allCDs.h"
14
15namespace classdesc
16{
17 class xml_pack_t;
18 class xml_unpack_t;
19}
20
21namespace classdesc_access
22{
23#ifdef CLASSDESC_XML_PACK_BASE_H
24 template <class T> struct access_xml_pack
25 {
26 //This routine uses operator << if defined
27 void operator()(classdesc::xml_pack_t& t,const classdesc::string& d, const T& a)
28 {t.pack_notag(d,a);}
29 };
30#endif
31
32#ifdef CLASSDESC_XML_UNPACK_BASE_H
33 //This routine uses operator >> if defined
34 template <class T> struct access_xml_unpack
35 {
36 void operator()(classdesc::xml_unpack_t& t,const classdesc::string& d,T& a)
37 {t.unpack(d,a);}
38 };
39 // partial specialisation to discard unpacking to constant data types
40 template <class T> struct access_xml_unpack<const T>
41 {
42 void operator()(classdesc::xml_unpack_t& t,const classdesc::string& d, const T& a)
43 {
44 T tmp;
45 t.unpack(d,tmp);
46 }
47 };
48#endif
49}
50
51namespace classdesc
52{
53 template <class T>
54 struct AllOtherXMLPackpTypes: public
55 Not<
56 Or<
57 Or<
58 Or< is_sequence<T>, is_associative_container<T> >,
59 is_fundamental<T>
60 >,
61 is_enum<T>
62 >
63 >
64 {};
65}
66
67namespace classdesc
68{
69#ifdef CLASSDESC_XML_PACK_BASE_H
70 template <class T> typename
71 enable_if<AllOtherXMLPackpTypes<T>, void >::T
72 xml_packp(xml_pack_t& t,const string& d, T& a, dummy<0> dum=0)
73 {
74 xml_pack_t::Tag tag(t,d);
76 }
77#endif
78
79#ifdef CLASSDESC_XML_UNPACK_BASE_H
80 template <class T> typename
82 xml_unpackp(xml_unpack_t& t,const string& d,T& a, dummy<0> dum=0)
83 {
84 classdesc_access::access_xml_unpack<T>()(t,d,a);
85 }
86
87 template <class T> typename
88 enable_if<is_enum<T>, void >::T
89 xml_unpackp(xml_unpack_t& t,const string& d,T& a, dummy<1> dum=0)
90 {
91 classdesc_access::access_xml_unpack<T>()(t,d,a);
92 }
93
94 // handle const arguments
95 template <class T>
96 void xml_unpackp(xml_unpack_t& t,const string& d, const T& a)
97 {}
98#endif
99
100#ifdef CLASSDESC_XML_PACK_BASE_H
101 template <class T> void xml_pack(xml_pack_t& t,const string& d, T& a)
102 {
103 xml_packp(t,d,a);
104 }
105
106 template <class T> void xml_pack(xml_pack_t& t,const string& d, const T& a)
107 {
108 xml_packp(t,d,const_cast<T&>(a));
109 }
110
111 template <class T> xml_pack_t& operator<<(xml_pack_t& t, const T& a)
112 {xml_pack(t,"root",const_cast<T&>(a)); return t;}
113
114#endif
115
116#ifdef CLASSDESC_XML_UNPACK_BASE_H
117 template <class T> void xml_unpack(xml_unpack_t& t,const string& d,T& a)
118 {
119 xml_unpackp(t,d,a);
120 }
121
122 template <class T> xml_unpack_t& operator>>(xml_unpack_t& t, T& a)
123 {xml_unpack(t,"root",a); return t;}
124#endif
125}
126
127namespace classdesc_access
128{
129 namespace cd=classdesc;
130
131 template <> struct access_xml_pack<cd::CDATA>
132 {
133 void operator()(cd::xml_pack_t& p,const std::string& d,const cd::CDATA& c)
134 {
135 p.pack_notag(d,c);
136 }
137 };
138
139#ifdef CLASSDESC_POLYPACKBASE_H
140#ifdef CLASSDESC_XML_PACK_BASE_H
141 template <> struct access_xml_pack<cd::PolyPackBase>:
142 public cd::NullDescriptor<cd::xml_pack_t> {};
143 template <class T> struct access_xml_pack<cd::PolyPack<T> >:
144 public cd::NullDescriptor<cd::xml_pack_t> {};
145#endif
146#ifdef CLASSDESC_XML_UNPACK_BASE_H
147 template <> struct access_xml_unpack<cd::PolyPackBase>:
148 public cd::NullDescriptor<cd::xml_unpack_t> {};
149 template <class T> struct access_xml_unpack<cd::PolyPack<T> >:
150 public cd::NullDescriptor<cd::xml_unpack_t> {};
151#endif
152#endif
153
154#ifdef CLASSDESC_POLYJSONBASE_H
155#ifdef CLASSDESC_XML_PACK_BASE_H
156 template <> struct access_xml_pack<cd::PolyJsonBase>:
157 public cd::NullDescriptor<cd::xml_pack_t> {};
158 template <class T> struct access_xml_pack<cd::PolyJson<T> >:
159 public cd::NullDescriptor<cd::xml_pack_t> {};
160#endif
161#ifdef CLASSDESC_XML_UNPACK_BASE_H
162 template <> struct access_xml_unpack<cd::PolyJsonBase>:
163 public cd::NullDescriptor<cd::xml_unpack_t> {};
164 template <class T> struct access_xml_unpack<cd::PolyJson<T> >:
165 public cd::NullDescriptor<cd::xml_unpack_t> {};
166#endif
167#endif
168
169#ifdef CLASSDESC_POLYXMLBASE_H
170//#ifdef CLASSDESC_XML_PACK_BASE_H
171// template <> struct access_xml_pack<cd::PolyXMLBase>:
172// public cd::NullDescriptor<cd::xml_pack_t> {};
173// template <class T> struct access_xml_pack<cd::PolyXML<T> >:
174// public cd::NullDescriptor<cd::xml_pack_t> {};
175//#endif
176//#ifdef CLASSDESC_XML_UNPACK_BASE_H
177// template <> struct access_xml_unpack<cd::PolyXMLBase>:
178// public cd::NullDescriptor<cd::xml_unpack_t> {};
179// template <class T> struct access_xml_unpack<cd::PolyXML<T> >:
180// public cd::NullDescriptor<cd::xml_unpack_t> {};
181//#endif
182#endif
183
184#ifdef CLASSDESC_REF_H
185#ifdef CLASSDESC_XML_PACK_BASE_H
186 template <class T> struct access_xml_pack<cd::ref<T> >
187 {
188 void operator()(cd::xml_pack_t& x, const cd::string& d, cd::ref<T>& a)
189 {
190 if (a) xml_pack(x,d,*a);
191 }
192 };
193#endif
194
195#ifdef CLASSDESC_XML_UNPACK_BASE_H
196 template <class T> struct access_xml_unpack<cd::ref<T> >
197 {
198 void operator()(cd::xml_unpack_t& x, const cd::string& d, cd::ref<T>& a)
199 {
200 if (x.exists(d))
201 xml_unpack(x,d,*a);
202 }
203 };
204#endif
205#endif
206
207#ifdef CLASSDESC_XML_PACK_BASE_H
208 template<class T>
209 struct access_xml_pack<T*>
210 {
211 void operator()(cd::xml_pack_t& targ, const cd::string& desc, T*&)
212 {
213 throw cd::exception("xml_pack of pointers not supported");
214 }
215 };
216#endif
217
218#ifdef CLASSDESC_XML_UNPACK_BASE_H
219 template<class T>
220 struct access_xml_unpack<T*>
221 {
222 void operator()(cd::xml_unpack_t& targ, const cd::string& desc, T*&)
223 {
224 throw cd::exception("xml_unpack of pointers not supported");
225 }
226 };
227#endif
228}
229
230#endif
Definition xml_pack_base.h:56
void pack_notag(const string &d, const T &x)
Definition xml_pack_base.h:161
Definition xml_unpack_base.h:317
void unpack(std::string key, T &var)
simple data type deserialisation
Definition xml_unpack_base.h:410
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 xml_pack_epilogue.h:64
Definition classdesc.h:405
helper for constructing null descriptors
Definition classdesc.h:1106
Definition classdesc.h:299
controlled template specialisation: stolen from boost::enable_if.
Definition classdesc.h:282
base class for exceptions thrown by classdesc
Definition classdesc.h:546
Definition classdesc_access.h:23
Definition classdesc_access.h:24