Jpp 21.0.0-rc.1
the software that should make you happy
Loading...
Searching...
No Matches
JWriterObjectOutput.hh
Go to the documentation of this file.
1#ifndef __JIO__JWRITEROBJECTITERATOR__
2#define __JIO__JWRITEROBJECTITERATOR__
3
4#include <type_traits>
5
6
8#include "JLang/JTypeList.hh"
9#include "JLang/JNullType.hh"
10#include "JLang/JConversion.hh"
11#include "JIO/JSerialisable.hh"
12
13
14/**
15 * \author mdejong
16 */
17
18namespace JIO {}
19namespace JPP { using namespace JIO; }
20
21namespace JIO {
22
24 using JLANG::JTypeList;
25 using JLANG::JNullType;
26
27
28 /**
29 * Implementation of object output using JIO::JWriter for single data type.
30 *
31 * This class implements the JLANG::JObjectOutput interface.
32 */
33 template<class T>
35 public virtual JObjectOutput<T>
36 {
37 public:
38 /**
39 * Constructor.
40 *
41 * \param writer writer output
42 */
44 out(writer)
45 {}
46
47
48 /**
49 * Object output.
50 *
51 * \param object object
52 * \return true if OK; else false
53 */
54 virtual bool put(const T& object) override
55 {
56 return put(object, std::bool_constant<JLANG::JConversion<T,JSerialisable>::is_derived>());
57 }
58
59 private:
60 bool put(const T& object, std::true_type) { return (bool) object.write(out); }
61 bool put(const T& object, std::false_type) { return (bool) (out << object); }
62
64 };
65
66
67 /**
68 * Implementation of object output for multiple data types.
69 *
70 * This class recursively implements the JLANG::JObjectOutput interface
71 * for all data types by deriving from:
72 * - JWriterObjectOutput<JHead_t>; and
73 * - JWriterObjectOutput<JTail_t>.
74 */
75 template<class JHead_t, class JTail_t>
76 class JWriterObjectOutput< JTypeList<JHead_t, JTail_t> > :
77 public virtual JObjectOutput< JTypeList<JHead_t, JTail_t> >,
78 public JWriterObjectOutput<JHead_t>,
79 public JWriterObjectOutput<JTail_t>
80
81 {
82 public:
83 /**
84 * Constructor.
85 *
86 * \param writer writer output
87 */
89 JWriterObjectOutput<JHead_t>(writer),
90 JWriterObjectOutput<JTail_t>(writer)
91 {}
92 };
93
94
95 /**
96 * Terminator class of recursive JWriterObjectOutput class.
97 */
98 template<class JHead_t>
100 public JWriterObjectOutput<JHead_t>
101 {
102 public:
103 /**
104 * Constructor.
105 *
106 * \param writer writer output
107 */
109 JWriterObjectOutput<JHead_t>(writer)
110 {}
111 };
112}
113
114#endif
Implementation of object output using JIO::JWriter for single data type.
JWriterObjectOutput(JWriter &writer)
Constructor.
bool put(const T &object, std::true_type)
virtual bool put(const T &object) override
Object output.
bool put(const T &object, std::false_type)
Interface for binary output.
Template interface of object output for single data type.
Auxiliary classes and methods for binary I/O.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Template class test for polymorphism.
Auxiliary class for no type definition.
Definition JNullType.hh:19
Type list.
Definition JTypeList.hh:23