-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrandom_init_epilogue.h
128 lines (108 loc) · 3.6 KB
/
random_init_epilogue.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
/*
@copyright Russell Standish 2000-2014
@author Russell Standish
This file is part of Classdesc
Open source licensed under the MIT license. See LICENSE for details.
*/
#ifndef CLASSDESC_RANDOM_INIT_EPILOGUE_H
#define CLASSDESC_RANDOM_INIT_EPILOGUE_H
#include "classdesc.h"
#include "random_init-allCDs.h"
namespace classdesc_access
{
namespace cd=classdesc;
template <class T>
struct access_random_init<const T>
{
void operator()(classdesc::random_init_t&,const classdesc::string&,const T&a)
{/* nothing to do */}
};
template<class T> typename
cd::enable_if<cd::is_default_constructible<typename T::element_type>, void>::T
random_init_smart_ptr(cd::random_init_t& r, const cd::string& d,
T& a, cd::dummy<0> dum=0)
{
a.reset(new typename T::element_type);
random_init(r,d,*a);
}
template<class T> typename
cd::enable_if<
cd::Not<cd::is_default_constructible<typename T::element_type> >, void>::T
random_init_smart_ptr(cd::random_init_t& r, const cd::string& d,
T& a, cd::dummy<1> dum=0)
{
if (a.get())
random_init(r,d,*a);
}
template <class T>
struct access_random_init<cd::shared_ptr<T> >
{
void operator()(cd::random_init_t& x, const cd::string& d,
cd::shared_ptr<T>& a)
{random_init_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_random_init<std::auto_ptr<T> >
{
void operator()(cd::random_init_t& x, const cd::string& d,
std::auto_ptr<T>& a)
{random_init_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>
struct access_random_init<std::unique_ptr<T,D> >
{
void operator()(cd::random_init_t& x, const cd::string& d,
std::unique_ptr<T,D>& a)
{json_pack_smart_ptr(x,d,a);}
};
#endif
#ifdef CLASSDESC_POLYPACKBASE_H
template <> struct access_random_init<cd::PolyPackBase>:
public cd::NullDescriptor<cd::random_init_t> {};
template <class T> struct access_random_init<cd::PolyPack<T> >:
public cd::NullDescriptor<cd::random_init_t> {};
#endif
#ifdef CLASSDESC_POLYJSONBASE_H
template <> struct access_random_init<cd::PolyJsonBase>:
public cd::NullDescriptor<cd::random_init_t> {};
template <class T> struct access_random_init<cd::PolyJson<T> >:
public cd::NullDescriptor<cd::random_init_t> {};
#endif
//#ifdef CLASSDESC_POLYXMLBASE_H
// template <> struct access_random_init<cd::PolyXMLBase>:
// public cd::NullDescriptor<cd::random_init_t> {};
// template <class T> struct access_random_init<cd::PolyXML<T> >:
// public cd::NullDescriptor<cd::random_init_t> {};
//#endif
}
namespace classdesc
{
template <class T>
struct AllOtherRandomInitTypes:
public Not< Or< Or< Or<is_arithmetic<T>,is_string<T> >, is_sequence<T> >,
is_associative_container<T> > >
{};
template <class T> typename
enable_if<AllOtherRandomInitTypes<T>, void >::T
random_initp(random_init_t& r,const string& d,T& a, dummy<3> dum=0)
{classdesc_access::access_random_init<T>()(r,d,a);}
// by default, do nothing
template <class T> void random_init_normalise(T&) {}
template <class T>
void random_init(random_init_t& r,const string& d,T& a)
{
random_initp(r,d,a);
random_init_normalise(a);
}
}
#endif