random_init_epilogue.h
1 /*
2  @copyright Russell Standish 2000-2014
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 RANDOM_INIT_EPILOGUE_H
10 #define RANDOM_INIT_EPILOGUE_H
11 #include "classdesc.h"
12 
13 namespace classdesc_access
14 {
15  namespace cd=classdesc;
16  template <class T>
17  struct access_random_init<const T>
18  {
19  void operator()(classdesc::random_init_t&,const classdesc::string&,const T&a)
20  {/* nothing to do */}
21  };
22 
23  template<class T> typename
25  random_init_smart_ptr(cd::random_init_t& r, const cd::string& d,
26  T& a, cd::dummy<0> dum=0)
27  {
28  a.reset(new typename T::element_type);
29  random_init(r,d,*a);
30  }
31 
32  template<class T> typename
35  random_init_smart_ptr(cd::random_init_t& r, const cd::string& d,
36  T& a, cd::dummy<1> dum=0)
37  {
38  if (a.get())
39  random_init(r,d,*a);
40  }
41 
42  template <class T>
43  struct access_random_init<cd::shared_ptr<T> >
44  {
45  void operator()(cd::random_init_t& x, const cd::string& d,
46  cd::shared_ptr<T>& a)
47  {random_init_smart_ptr(x,d,a);}
48  };
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  struct access_random_init<std::auto_ptr<T> >
57  {
58  void operator()(cd::random_init_t& x, const cd::string& d,
59  std::auto_ptr<T>& a)
60  {random_init_smart_ptr(x,d,a);}
61  };
62 #if defined(__GNUC__) && !defined(__ICC) && !defined(__clang__)
63 #pragma GCC diagnostic pop
64 #endif
65 #endif
66 
67 #if defined(__cplusplus) && __cplusplus >= 201103L
68  template <class T, class D>
69  struct access_random_init<std::unique_ptr<T,D> >
70  {
71  void operator()(cd::random_init_t& x, const cd::string& d,
72  std::unique_ptr<T,D>& a)
73  {json_pack_smart_ptr(x,d,a);}
74  };
75 
76 #endif
77 
78 
79  // support for polymorphic types, if loaded
80 //#ifdef NEW_POLY_H
81 // template <class T> struct access_random_init<cd::PolyBase<T> >:
82 // public cd::NullDescriptor<cd::random_init_t> {};
83 // template <class T, class B> struct access_random_init<cd::Poly<T,B> >
84 // {
85 // template <class U>
86 // void operator()(cd::random_init_t& t, const cd::string& d, U& a)
87 // {
88 // random_init(t,d,cd::base_cast<B>::cast(a));
89 // }
90 // };
91 //#endif
92 
93 #ifdef POLYPACKBASE_H
94  template <> struct access_random_init<cd::PolyPackBase>:
95  public cd::NullDescriptor<cd::random_init_t> {};
96  template <class T> struct access_random_init<cd::PolyPack<T> >:
97  public cd::NullDescriptor<cd::random_init_t> {};
98 #endif
99 
100 #ifdef POLYJSONBASE_H
101  template <> struct access_random_init<cd::PolyJsonBase>:
102  public cd::NullDescriptor<cd::random_init_t> {};
103  template <class T> struct access_random_init<cd::PolyJson<T> >:
104  public cd::NullDescriptor<cd::random_init_t> {};
105 #endif
106 
107 #ifdef POLYXMLBASE_H
108  template <> struct access_random_init<cd::PolyXMLBase>:
109  public cd::NullDescriptor<cd::random_init_t> {};
110  template <class T> struct access_random_init<cd::PolyXML<T> >:
111  public cd::NullDescriptor<cd::random_init_t> {};
112 #endif
113 
114 
115 
116 }
117 
118 namespace classdesc
119 {
120  template <class T>
122  public Not< Or< Or< Or<is_arithmetic<T>,is_string<T> >, is_sequence<T> >,
123  is_associative_container<T> > >
124  {};
125 
126  template <class T> typename
128  random_initp(random_init_t& r,const string& d,T& a, dummy<3> dum=0)
130 
131  // by default, do nothing
132  template <class T> void random_init_normalise(T&) {}
133 
134  template <class T>
135  void random_init(random_init_t& r,const string& d,T& a)
136  {
137  random_initp(r,d,a);
139  }
140 }
141 #endif
Definition: classdesc.h:326
Definition: random_init_epilogue.h:121
Definition: random_init_base.h:20
helper for constructing null descriptors
Definition: classdesc.h:784
void random_init_normalise(T &)
Definition: random_init_epilogue.h:132
Contains definitions related to classdesc functionality.
Definition: arrays.h:2514
Definition: classdesc_access.h:27
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