Jpp 19.3.0-rc.3
the software that should make you happy
Loading...
Searching...
No Matches
JRootSupportkit.hh
Go to the documentation of this file.
1#ifndef __JROOTSUPPORTKIT__
2#define __JROOTSUPPORTKIT__
3
4#include "TFile.h"
5
6#include "JLang/JTest.hh"
7#include "JLang/JBool.hh"
8
10
11
12/**
13 * \file
14 *
15 * Data type dependent action methods for customised ROOT version management.
16 * \author mdejong
17 */
18namespace JROOT {}
19namespace JPP { using namespace JROOT; }
20
21namespace JROOT {
22
23 using JLANG::JTest;
24 using JLANG::JBool;
25
26
27 /**
28 * Auxiliary class to handle version management of given class at opening of a ROOT file.
29 */
30 template <class T>
32 public JTest
33 {
34 using JTest::test;
35
36 template<class U> static JTrue test(JTypecheck<void (*)(int), &U::actionAtFileOpen>*);
37
38
39 /**
40 * Execute action.
41 *
42 * This implementation transfers the action to the given class.
43 *
44 * \param file pointer to file
45 * \param option true
46 */
47 static inline void execute(TFile* file, JBool<true> option)
48 {
49 T::actionAtFileOpen(getStreamerVersion(file, T::Class_Name()));
50 }
51
52
53 /**
54 * Execute action.
55 *
56 * This implementation does nothing.
57 *
58 * \param file pointer to file
59 * \param option false
60 */
61 static inline void execute(TFile* file, JBool<false> option)
62 {}
63
64 public:
65
66 static const bool has_method = JTEST(test<T>(NULL)); //!< true if class has policy method actionAtFileOpen; else false
67
68
69 /**
70 * Execute action.
71 *
72 * \param file pointer to file
73 */
74 static inline void execute(TFile* file)
75 {
77 }
78 };
79
80
81 /**
82 * Auxiliary class to handle version management of given class at reading from a ROOT file.
83 */
84 template <class T>
86 public JTest
87 {
88 using JTest::test;
89
90 template<class U> static JTrue test(JTypecheck<void (U::*)(), &U::actionAtFileRead>*);
91
92
93 /**
94 * Execute action.
95 *
96 * This implementation transfers the action to the given object.
97 *
98 * \param object pointer to object (I/O)
99 * \param option true
100 */
101 static inline void execute(T* object, JBool<true> option)
102 {
103 object->actionAtFileRead();
104 }
105
106
107 /**
108 * Execute action.
109 *
110 * This implementation does nothing.
111 *
112 * \param object pointer to object (I/O)
113 * \param option false
114 */
115 static inline void execute(T* object, JBool<false> option)
116 {}
117
118 public:
119
120 static const bool has_method = JTEST(test<T>(NULL)); //!< true if class has policy method actionAtFileRead; else false
121
122
123 /**
124 * Execute action.
125 *
126 * \param object pointer to object (I/O)
127 */
128 static inline void execute(T* object)
129 {
130 execute(object, JBool<has_method>());
131 }
132 };
133
134
135 /**
136 * General action method at file open.
137 *
138 * The class T should provide the policy method:
139 * <pre>
140 * static void %actionAtFileOpen(int version);
141 * </pre>
142 * whenever an action specific to this data type has to be executed after opening a file.\n
143 * This method will then be called following each file open operation.
144 *
145 * \param file pointer to file
146 */
147 template<class T>
148 inline void actionAtFileOpen(TFile* file)
149 {
150 if (file != NULL) {
152 }
153 }
154
155
156 /**
157 * General action method at file read.
158 *
159 * The class T should provide the policy method:
160 * <pre>
161 * void %actionAtFileRead();
162 * </pre>
163 * whenever an action specific to this data type has to be executed after reading from a file.\n
164 * This method will then be called following each file read operation.
165 *
166 * \param object pointer to object (I/O)
167 */
168 template<class T>
169 inline void actionAtFileRead(T* object)
170 {
171 if (object != NULL) {
173 }
174 }
175}
176#endif
#define JTEST(__A__)
Test macro.
Definition JTest.hh:45
Auxiliary class to handle version management of given class at opening of a ROOT file.
static void execute(TFile *file, JBool< false > option)
Execute action.
static const bool has_method
true if class has policy method actionAtFileOpen; else false
static void execute(TFile *file, JBool< true > option)
Execute action.
static JTrue test(JTypecheck< void(*)(int), &U::actionAtFileOpen > *)
static void execute(TFile *file)
Execute action.
Auxiliary class to handle version management of given class at reading from a ROOT file.
static void execute(T *object)
Execute action.
static const bool has_method
true if class has policy method actionAtFileRead; else false
static void execute(T *object, JBool< false > option)
Execute action.
static JTrue test(JTypecheck< void(U::*)(), &U::actionAtFileRead > *)
static void execute(T *object, JBool< true > option)
Execute action.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary classes and methods for ROOT I/O.
void actionAtFileRead(T *object)
General action method at file read.
int getStreamerVersion(TFile *file, const char *const name)
Get ROOT streamer version of class with given name.
void actionAtFileOpen(TFile *file)
General action method at file open.
Auxiliary template class for type bool.
Definition JBool.hh:21
definition of true
Definition JTest.hh:24
Auxiliary class for type checking.
Definition JTest.hh:36
Auxiliary base class for compile time evaluation of test.
Definition JTest.hh:21
static JFalse test(...)
default false