Jpp  18.3.0-rc.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JWriterObjectOutput.hh
Go to the documentation of this file.
1 #ifndef __JIO__JWRITEROBJECTITERATOR__
2 #define __JIO__JWRITEROBJECTITERATOR__
3 
4 #include "JLang/JObjectOutput.hh"
5 #include "JLang/JTypeList.hh"
6 #include "JLang/JNullType.hh"
7 #include "JLang/JConversion.hh"
8 #include "JLang/JBool.hh"
9 #include "JIO/JSerialisable.hh"
10 
11 
12 /**
13  * \author mdejong
14  */
15 
16 namespace JIO {}
17 namespace JPP { using namespace JIO; }
18 
19 namespace JIO {
20 
22  using JLANG::JTypeList;
23  using JLANG::JNullType;
24 
25 
26  /**
27  * Implementation of object output using JIO::JWriter for single data type.
28  *
29  * This class implements the JLANG::JObjectOutput interface.
30  */
31  template<class T>
33  public virtual JObjectOutput<T>
34  {
35  public:
36  /**
37  * Constructor.
38  *
39  * \param writer writer output
40  */
42  out(writer)
43  {}
44 
45 
46  /**
47  * Object output.
48  *
49  * \param object object
50  * \return true if OK; else false
51  */
52  virtual bool put(const T& object) override
53  {
55  }
56 
57  private:
58  bool put(const T& object, JLANG::JBool<true>) { return (bool) object.write(out); }
59  bool put(const T& object, JLANG::JBool<false>) { return (bool) (out << object); }
60 
62  };
63 
64 
65  /**
66  * Implementation of object output for multiple data types.
67  *
68  * This class recursively implements the JLANG::JObjectOutput interface
69  * for all data types by deriving from:
70  * - JWriterObjectOutput<JHead_t>; and
71  * - JWriterObjectOutput<JTail_t>.
72  */
73  template<class JHead_t, class JTail_t>
74  class JWriterObjectOutput< JTypeList<JHead_t, JTail_t> > :
75  public virtual JObjectOutput< JTypeList<JHead_t, JTail_t> >,
76  public JWriterObjectOutput<JHead_t>,
77  public JWriterObjectOutput<JTail_t>
78 
79  {
80  public:
81  /**
82  * Constructor.
83  *
84  * \param writer writer output
85  */
87  JWriterObjectOutput<JHead_t>(writer),
88  JWriterObjectOutput<JTail_t>(writer)
89  {}
90  };
91 
92 
93  /**
94  * Terminator class of recursive JWriterObjectOutput class.
95  */
96  template<class JHead_t>
98  public JWriterObjectOutput<JHead_t>
99  {
100  public:
101  /**
102  * Constructor.
103  *
104  * \param writer writer output
105  */
107  JWriterObjectOutput<JHead_t>(writer)
108  {}
109  };
110 }
111 
112 #endif
Interface for binary output.
Type list.
Definition: JTypeList.hh:22
Auxiliary template class for type bool.
Definition: JBool.hh:20
do set_variable OUTPUT_DIRECTORY $WORKDIR T
Template class test for polymorphism.
Definition: JConversion.hh:22
Auxiliary class for no type definition.
Definition: JNullType.hh:19
bool put(const T &object, JLANG::JBool< false >)
virtual bool put(const T &object) override
Object output.
bool put(const T &object, JLANG::JBool< true >)
JWriterObjectOutput(JWriter &writer)
Constructor.
Template interface of object output for single data type.
Implementation of object output using JIO::JWriter for single data type.