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 PACK_EPILOGUE_H
10 #define PACK_EPILOGUE_H
11 
12 namespace classdesc_access
13 {
14  namespace cd=classdesc;
15 
16  // const arg versions
17  template <class T>
18  struct access_pack<const T>
19  {
20  void operator()(cd::pack_t& buf, const cd::string& desc, const T& arg)
21  {access_pack<T>()(buf,desc,arg);}
22  };
23 
24 
25  template <class T>
26  struct access_unpack<const T>
27  {
28  void operator()(cd::pack_t& buf, const cd::string& desc, const T& arg)
29  {access_unpack<T>()(buf,desc,arg);}
30  };
31 
32  template <class T> typename
34  pack_container(cd::pack_t& buf,const cd::string& desc, T& arg,
35  cd::dummy<0> dum=0)
36  {access_pack<cd::sequence<T> >()(buf,desc,arg);}
37 
38  template <class T> typename
40  pack_container(cd::pack_t& buf,const cd::string& desc, T& arg,
41  cd::dummy<1> dum=0)
42  {access_pack<cd::associative_container<T> >()(buf,desc,arg);}
43 
44 
45  // handle containers from the generic access_ classes
46  template <class T>
47  struct access_pack
48  {
49  template <class U>
50  void operator()(cd::pack_t& buf,const cd::string& desc, U& arg)
51  {pack_container(buf,desc,arg);}
52  };
53 
54  template <class T> typename
56  unpack_container(cd::pack_t& buf,const cd::string& desc, T& arg,
57  cd::dummy<0> dum=0)
58  {access_unpack<classdesc::sequence<T> >()(buf,desc,arg);}
59 
60  template <class T> typename
62  unpack_container(cd::pack_t& buf,const cd::string& desc, T& arg,
63  cd::dummy<1> dum=0)
65 
66  template <class T>
67  struct access_unpack
68  {
69  template <class U>
70  void operator()(cd::pack_t& buf,const cd::string& desc, U& arg)
71  {unpack_container(buf,desc,arg);}
72  };
73 
74  // support for polymorphic types, if loaded
75 //#ifdef NEW_POLY_H
76 // template <class T> struct access_pack<cd::PolyBase<T> >:
77 // public cd::NullDescriptor<cd::pack_t> {};
78 // template <class T> struct access_unpack<cd::PolyBase<T> >:
79 // public cd::NullDescriptor<cd::pack_t> {};
80 // template <class T, class B> struct access_pack<cd::Poly<T,B> >
81 // {
82 // template <class U>
83 // void operator()(cd::pack_t& t, const cd::string& d, U& a)
84 // {
85 // pack(t,d,cd::base_cast<B>::cast(a));
86 // }
87 // };
88 // template <class T, class B> struct access_unpack<cd::Poly<T,B> >
89 // {
90 // template <class U>
91 // void operator()(cd::pack_t& t, const cd::string& d, U& a)
92 // {
93 // unpack(t,d,cd::base_cast<B>::cast(a));
94 // }
95 // };
96 //#endif
97 
98 #ifdef POLYPACKBASE_H
99  template <> struct access_pack<cd::PolyPackBase>:
100  public cd::NullDescriptor<cd::pack_t> {};
101  template <> struct access_unpack<cd::PolyPackBase>:
102  public cd::NullDescriptor<cd::unpack_t> {};
103  template <class T> struct access_pack<cd::PolyPack<T> >:
104  public cd::NullDescriptor<cd::pack_t> {};
105  template <class T> struct access_unpack<cd::PolyPack<T> >:
106  public cd::NullDescriptor<cd::unpack_t> {};
107 #endif
108 
109 #ifdef POLYJSONBASE_H
110  template <> struct access_pack<cd::PolyJsonBase>:
111  public cd::NullDescriptor<cd::pack_t> {};
112  template <> struct access_unpack<cd::PolyJsonBase>:
113  public cd::NullDescriptor<cd::unpack_t> {};
114  template <class T> struct access_pack<cd::PolyJson<T> >:
115  public cd::NullDescriptor<cd::pack_t> {};
116  template <class T> struct access_unpack<cd::PolyJson<T> >:
117  public cd::NullDescriptor<cd::unpack_t> {};
118 #endif
119 
120 #ifdef POLYXMLBASE_H
121  template <> struct access_pack<cd::PolyXMLBase>:
122  public cd::NullDescriptor<cd::pack_t> {};
123  template <> struct access_unpack<cd::PolyXMLBase>:
124  public cd::NullDescriptor<cd::unpack_t> {};
125  template <class T> struct access_pack<cd::PolyXML<T> >:
126  public cd::NullDescriptor<cd::pack_t> {};
127  template <class T> struct access_unpack<cd::PolyXML<T> >:
128  public cd::NullDescriptor<cd::unpack_t> {};
129 #endif
130 
131 #ifdef FACTORY_H
132  template <class T, class U> struct access_pack<cd::Factory<T,U> >
133  {
134  void operator()(cd::pack_t& b,const cd::string& d, cd::Factory<T,U>& a)
135  {
136  pack(b,d,a.fmap);
137  }
138  };
139 
140 
141 
142  template <class T, class U> struct access_unpack<cd::Factory<T,U> >
143  {
144  void operator()(cd::unpack_t& b,const cd::string& d, cd::Factory<T,U>& a)
145  {
146  unpack(b,d,a.fmap);
147  }
148  };
149 #endif
150 
151 }
152 #include "polyAccessPack.h"
153 #include "pack_stream.h"
154 #include "pack_stl.h"
155 #endif
class to allow access to private members
Definition: classdesc_access.h:21
helper for constructing null descriptors
Definition: classdesc.h:784
class to allow access to private members
Definition: classdesc_access.h:22
serialisation for standard containers
Contains definitions related to classdesc functionality.
Definition: arrays.h:2514
Definition: pack_base.h:124
controlled template specialisation: stolen from boost::enable_if.
Definition: classdesc.h:249
Definition: classdesc.h:266
Contains access_* structs, and nothing else. These structs are used to gain access to private members...
Definition: accessor.h:55
Definition: factory.h:20
void unpack(unpack_t &targ, const string &desc, is_treenode dum, T *&arg)
unserialise a tree.
Definition: pack_graph.h:44