-
Notifications
You must be signed in to change notification settings - Fork 2
/
dump_epilogue.h
110 lines (95 loc) · 2.75 KB
/
dump_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
/*
@copyright Russell Standish 2000-2013
@author Russell Standish
This file is part of Classdesc
Open source licensed under the MIT license. See LICENSE for details.
*/
#ifndef CLASSDESC_DUMP_EPILOGUE_H
#define CLASSDESC_DUMP_EPILOGUE_H
#include <iostream>
namespace classdesc
{
template <class B>
typename enable_if< Not<is_fundamental<B> >, void >::T
dumpp(dump_t& t, const string& d, B& a)
{
classdesc_access::access_dump<B>()(t,d,a);
}
template <class T>
typename enable_if<is_container<T>, bool>::T
is_basic_container() {
return is_fundamental<typename T::value_type>::value;
}
template <class T>
typename enable_if<Not<is_container<T> >, bool>::T
is_basic_container() {return false;}
// only format for complex types
template <class T>
struct Format
{
int tab;
std::ostream& o;
Format(std::ostream& o, const string& d): tab(-1), o(o)
{
if (!is_fundamental<T>::value && !is_string<T>::value
&& !is_basic_container<T>() )
{
tab=format(o,d);
o<<"{"<<std::endl;
}
}
~Format()
{
if (tab>=0)
o<<std::setw(tab+2)<<"}"<<std::endl;
}
};
template <class T> void dump(classdesc::dump_t& o,
const classdesc::string& d, const T& a)
{
Format<T> f(o,d);
dumpp(o,d,const_cast<T&>(a));
}
// template <class T>
// std::ostream& operator<<(std::ostream& o,const T& a)
// {dump(&o,"",a);}
}
namespace classdesc_access
{
namespace cd=classdesc;
// support for polymorphic types, if loaded
//#ifdef NEW_POLY_H
// template <class T> struct access_dump<cd::PolyBase<T> >:
// public cd::NullDescriptor<cd::dump_t> {};
// template <class T, class B> struct access_dump<cd::Poly<T,B> >:
// public cd::NullDescriptor<cd::dump_t> {};
//#endif
#ifdef CLASSDESC_POLYPACKBASE_H
template <> struct access_dump<cd::PolyPackBase>:
public cd::NullDescriptor<cd::dump_t> {};
template <class T> struct access_dump<cd::PolyPack<T> >:
public cd::NullDescriptor<cd::dump_t> {};
#endif
#ifdef CLASSDESC_POLYJSONBASE_H
template <> struct access_dump<cd::PolyJsonBase>:
public cd::NullDescriptor<cd::dump_t> {};
template <class T> struct access_dump<cd::PolyJson<T> >:
public cd::NullDescriptor<cd::dump_t> {};
#endif
#ifdef CLASSDESC_POLYXMLBASE_H
template <> struct access_dump<cd::PolyXMLBase>:
public cd::NullDescriptor<cd::dump_t> {};
template <class T> struct access_dump<cd::PolyXML<T> >:
public cd::NullDescriptor<cd::dump_t> {};
#endif
#ifdef CLASSDESC_FACTORY_H
template <class T, class U> struct access_dump<cd::Factory<T,U> >
{
void operator()(cd::dump_t& b,const cd::string& d, cd::Factory<T,U>& a)
{
dump(b,d,a.fmap);
}
};
#endif
}
#endif