dump_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 DUMP_EPILOGUE_H
10 #define DUMP_EPILOGUE_H
11 
12 
13 #include <iostream>
14 namespace classdesc
15 {
16  template <class B>
17  typename enable_if< Not<is_fundamental<B> >, void >::T
18  dumpp(dump_t& t, const string& d, B& a)
19  {
21  }
22 
23  template <class T>
24  typename enable_if<is_container<T>, bool>::T
25  is_basic_container() {
26  return is_fundamental<typename T::value_type>::value;
27  }
28 
29  template <class T>
30  typename enable_if<Not<is_container<T> >, bool>::T
31  is_basic_container() {return false;}
32 
33  // only format for complex types
34  template <class T>
35  struct Format
36  {
37  int tab;
38  std::ostream& o;
39  Format(std::ostream& o, const string& d): tab(-1), o(o)
40  {
41  if (!is_fundamental<T>::value && !is_string<T>::value
42  && !is_basic_container<T>() )
43  {
44  tab=format(o,d);
45  o<<"{"<<std::endl;
46  }
47  }
48  ~Format()
49  {
50  if (tab>=0)
51  o<<std::setw(tab+2)<<"}"<<std::endl;
52  }
53  };
54 
55  template <class T> void dump(classdesc::dump_t& o,
56  const classdesc::string& d, const T& a)
57  {
58  Format<T> f(o,d);
59  dumpp(o,d,const_cast<T&>(a));
60  }
61 
62 // template <class T>
63 // std::ostream& operator<<(std::ostream& o,const T& a)
64 // {dump(&o,"",a);}
65 }
66 
67 namespace classdesc_access
68 {
69  namespace cd=classdesc;
70  // support for polymorphic types, if loaded
71 //#ifdef NEW_POLY_H
72 // template <class T> struct access_dump<cd::PolyBase<T> >:
73 // public cd::NullDescriptor<cd::dump_t> {};
74 // template <class T, class B> struct access_dump<cd::Poly<T,B> >:
75 // public cd::NullDescriptor<cd::dump_t> {};
76 //#endif
77 
78 #ifdef POLYPACKBASE_H
79  template <> struct access_dump<cd::PolyPackBase>:
80  public cd::NullDescriptor<cd::dump_t> {};
81  template <class T> struct access_dump<cd::PolyPack<T> >:
82  public cd::NullDescriptor<cd::dump_t> {};
83 #endif
84 
85 #ifdef POLYJSONBASE_H
86  template <> struct access_dump<cd::PolyJsonBase>:
87  public cd::NullDescriptor<cd::dump_t> {};
88  template <class T> struct access_dump<cd::PolyJson<T> >:
89  public cd::NullDescriptor<cd::dump_t> {};
90 #endif
91 
92 #ifdef POLYXMLBASE_H
93  template <> struct access_dump<cd::PolyXMLBase>:
94  public cd::NullDescriptor<cd::dump_t> {};
95  template <class T> struct access_dump<cd::PolyXML<T> >:
96  public cd::NullDescriptor<cd::dump_t> {};
97 #endif
98 
99 #ifdef FACTORY_H
100  template <class T, class U> struct access_dump<cd::Factory<T,U> >
101  {
102  void operator()(cd::dump_t& b,const cd::string& d, cd::Factory<T,U>& a)
103  {
104  dump(b,d,a.fmap);
105  }
106  };
107 #endif
108 }
109 
110 #endif
Definition: polyJsonBase.h:23
determines if this is a string
Definition: classdesc.h:280
Definition: dump_base.h:180
helper for constructing null descriptors
Definition: classdesc.h:784
void dump(dump_t &o, const string &d, const T &a)
forward declare generic dump operation
Definition: dump_epilogue.h:55
Definition: dump_base.h:29
utility class for defining pack descriptors for polymorphic types
Definition: polyPackBase.h:45
Contains definitions related to classdesc functionality.
Definition: arrays.h:2514
Definition: polyXMLBase.h:25
Definition: polyXMLBase.h:17
Definition: dump_epilogue.h:35
interface for applying pack descriptors to polymorphic objects
Definition: polyPackBase.h:18
Contains access_* structs, and nothing else. These structs are used to gain access to private members...
Definition: accessor.h:55
Definition: polyJsonBase.h:15
Definition: factory.h:20