Jpp  17.3.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JSTDObjectWriter.hh
Go to the documentation of this file.
1 #ifndef __JLANG__JSTDOBJECTWRITER__
2 #define __JLANG__JSTDOBJECTWRITER__
3 
4 #include "JLang/JObjectWriter.hh"
6 
7 
8 /**
9  * \author mdejong
10  */
11 
12 namespace JLANG {}
13 namespace JPP { using namespace JLANG; }
14 
15 namespace JLANG {
16 
17 
18  /**
19  * Implementation of object output from STD container.
20  *
21  * This class implements the JObjectOutput interface.
22  */
23  template<class T>
25  public virtual JObjectOutput<T>,
26  public JObjectWriter<T>
27  {
28  public:
29 
30  /**
31  * Default constructor.
32  */
34  {}
35 
36 
37  /**
38  * Constructor.
39  *
40  * \param out output iterator
41  */
42  template<class JOutputIterator_t>
44  {
45  this->reset(out.clone());
46  }
47 
48 
49  /**
50  * Constructor.
51  *
52  * \param buffer output buffer
53  */
54  template<class JContainer_t>
55  JSTDObjectWriter(JContainer_t& buffer)
56  {
57  this->reset(getObjectOutput(buffer).clone());
58  }
59 
60 
61  /**
62  * Set output buffer.
63  *
64  * \param buffer output buffer
65  */
66  template<class JContainer_t>
67  void set(JContainer_t& buffer)
68  {
69  this->reset(getObjectOutput(buffer).clone());
70  }
71  };
72 
73 
74 
75  /**
76  * Implementation of object output from STD container for multiple data types.
77  *
78  * This class recursively implements the JLANG::JObjectOutput interface
79  * for all data types by deriving from:
80  * - JSTDObjectWriter<JHead_t>; and
81  * - JSTDObjectWriter<JTail_t>.
82  */
83  template<class JHead_t, class JTail_t>
84  struct JSTDObjectWriter< JTypeList<JHead_t, JTail_t> > :
85  public virtual JObjectOutput< JTypeList<JHead_t, JTail_t> >,
86  public JSTDObjectWriter<JHead_t>,
87  public JSTDObjectWriter<JTail_t>
88  {
93 
94 
95  /**
96  * Set output puffer.
97  *
98  * \param buffer output buffer
99  */
100  template<class JContainer_t>
101  void set(JContainer_t& buffer)
102  {
103  this->reset(getObjectOutput(buffer).clone());
104  }
105  };
106 
107 
108  /**
109  * Terminator class of recursive JSTDObjectWriter class.
110  */
111  template<class JHead_t>
112  struct JSTDObjectWriter< JTypeList<JHead_t, JNullType> > :
113  public JSTDObjectWriter<JHead_t>
114  {};
115 }
116 
117 #endif
data_type * clone() const
Get clone from temporary object.
Definition: JObject.hh:44
JSTDObjectWriter(JContainer_t &buffer)
Constructor.
JSTDObjectWriter()
Default constructor.
void set(JContainer_t &buffer)
Set output buffer.
Implementation of object output from STD container.
Type list.
Definition: JTypeList.hh:22
Auxiliary class for object writing to a named device.
Auxiliary class for no type definition.
Definition: JNullType.hh:19
Implementation of object output for STD compatible output iterator.
JSTDObjectOutput< std::back_insert_iterator< std::vector< JElement_t, JAllocator_t > > > getObjectOutput(std::vector< JElement_t, JAllocator_t > &buffer)
Helper method to create STD compatible object output.
Template interface of object output for single data type.
virtual void reset() override
Reset pointer.
JSTDObjectWriter(const JSTDObjectOutput< JOutputIterator_t > &out)
Constructor.
void set(JContainer_t &buffer)
Set output puffer.