Ariles
ariles.h
Go to the documentation of this file.
1 /**
2  @file
3  @author Alexander Sherikov
4 
5  @copyright 2014-2017 INRIA. Licensed under the Apache License, Version 2.0.
6  (see @ref LICENSE or http://www.apache.org/licenses/LICENSE-2.0)
7 
8  @copyright 2017-2019 Alexander Sherikov, Licensed under the Apache License, Version 2.0.
9  (see @ref LICENSE or http://www.apache.org/licenses/LICENSE-2.0)
10 
11  @brief
12 
13  @todo DEPRECATED
14 */
15 
16 #pragma once
17 
18 #undef ARILES_API_VERSION
19 #define ARILES_API_VERSION 1
20 
21 #include "ariles2.h"
22 #include "visitors/serialization.h"
23 
24 namespace ariles
25 {
27 }
28 
29 
30 #ifndef ARILES_DISABLE
31 # define ARILES_ENABLED
32 
33 
34 # undef ARILES_INITIALIZE
35 # define ARILES_INITIALIZE "ariles/members/define_accessors.h"
36 
37 
38 # define ARILES_WRITE_NAMED_ENTRY(entry, name) writer(entry, name, param);
39 
40 # define ARILES_WRITE_ENTRY_(entry) ARILES_WRITE_NAMED_ENTRY(entry##_, # entry)
41 # define ARILES_WRITE_ENTRY(entry) ARILES_WRITE_NAMED_ENTRY(entry, # entry)
42 
43 # define ARILES_WRITE_PARENT(parent_class) parent_class::writeConfigEntries(writer, param);
44 
45 
46 # define ARILES_READ_NAMED_ENTRY(entry, name) reader(entry, name, param);
47 
48 # define ARILES_READ_ENTRY_(entry) ARILES_READ_NAMED_ENTRY(entry##_, # entry);
49 # define ARILES_READ_ENTRY(entry) ARILES_READ_NAMED_ENTRY(entry, # entry);
50 
51 # define ARILES_READ_PARENT(parent_class) parent_class::readConfigEntries(reader, param);
52 
53 
54 namespace ariles
55 {
59 
60 
61  /**
62  * @brief Configurable base class.
63  */
65  {
66  protected:
67  /**
68  * @brief Protected destructor: prevent destruction of the child
69  * classes through a base pointer.
70  */
72  {
73  }
75  {
76  }
77 
78  public:
79  virtual void setDefaults()
80  {
81  ariles::apply<ariles::defaults::Visitor>(*this);
82  }
83 
84 
85  virtual void arilesFinalize() = 0;
86 
87  virtual void finalize()
88  {
89  }
90 
91 
92  /**
93  * @brief Get number of entries in the corresponding
94  * configuration node.
95  *
96  * @return number of entries
97  */
98  virtual std::size_t getNumberOfEntries() const = 0;
99 
100 
101 
102  /**
103  * @brief Return the default name of a configuration node
104  * corresponding to this class
105  *
106  * @return the name
107  *
108  * @attention Implementation of this method is added
109  * automatically upon inclusion of define_accessors.h if
110  * ARILES_SECTION_ID is defined.
111  */
112  virtual const std::string &getConfigSectionID() const = 0;
113  virtual const ConfigurableFlags &getArilesConfigurableFlags() const = 0;
114 
115 
116  virtual void readConfigEntries(ariles::ReaderBase &visitor, const ariles::ReaderBase::Parameters &parameters)
117  {
119  arilesVirtualVisit(visitor, parameters);
120  }
121 
122 
123  /**
124  * @brief Read configuration (assuming the configuration node
125  * to be in the root).
126  *
127  * @param[in] reader configuration reader
128  */
130  {
132  this->readConfig(reader, this->getConfigSectionID(), param);
133  }
134 
136  {
138  this->readConfig(reader, this->getConfigSectionID(), this->getArilesConfigurableFlags());
139  }
140 
141 
142 /**
143  * @brief Read configuration (assuming the configuration node
144  * to be in the root).
145  *
146  * @param[in] reader configuration reader
147  * @param[in] node_name node name, the default is used if empty
148  *
149  * @note Intercept implicit conversion of a pointer to bool.
150  */
151 # define ARILES_READ_CONFIG(NameType) \
152  virtual void readConfig( \
153  ariles::ReaderBase &reader, NameType node_name, const ariles::ReaderBase::Parameters &param) = 0; \
154  void readConfig(ariles::ReaderBase &reader, NameType node_name) \
155  { \
156  ARILES_TRACE_FUNCTION; \
157  this->readConfig(reader, node_name, this->getArilesConfigurableFlags()); \
158  }
159 
160  ARILES_READ_CONFIG(const std::string &)
161  ARILES_READ_CONFIG(const char *)
162 
163 # undef ARILES_READ_CONFIG
164 
165 
166 /**
167  * @brief Read configuration (assuming the configuration node
168  * to be in the root).
169  *
170  * @param[in] file_name file name
171  */
172 # define ARILES_READ_CONFIG(InitializerType) \
173  template <class t_Bridge, class t_ReaderInitializer> \
174  void readConfig(InitializerType &reader_initializer) \
175  { \
176  ARILES_TRACE_FUNCTION; \
177  typename t_Bridge::Reader reader(reader_initializer); \
178  this->readConfig(reader, this->getConfigSectionID(), this->getArilesConfigurableFlags()); \
179  } \
180  template <class t_Bridge, class t_ReaderInitializer> \
181  void readConfig(InitializerType &reader_initializer, const ariles::ConfigurableFlags &param) \
182  { \
183  ARILES_TRACE_FUNCTION; \
184  typename t_Bridge::Reader reader(reader_initializer); \
185  this->readConfig(reader, this->getConfigSectionID(), param); \
186  }
187 
188  ARILES_READ_CONFIG(t_ReaderInitializer)
189  ARILES_READ_CONFIG(const t_ReaderInitializer)
190 
191 # undef ARILES_READ_CONFIG
192 
193 
194 /**
195  * @brief Read configuration (assuming the configuration node
196  * to be in the root).
197  *
198  * @param[in] file_name file name
199  * @param[in] node_name node name, the default is used if empty
200  *
201  * @note Intercept implicit conversion of a pointer to bool.
202  */
203 # define ARILES_READ_CONFIG(InitializerType, NameType) \
204  template <class t_Bridge, class t_ReaderInitializer> \
205  void readConfig(InitializerType &reader_initializer, NameType node_name) \
206  { \
207  ARILES_TRACE_FUNCTION; \
208  typename t_Bridge::Reader reader(reader_initializer); \
209  this->readConfig(reader, node_name, this->getArilesConfigurableFlags()); \
210  } \
211  template <class t_Bridge, class t_ReaderInitializer> \
212  void readConfig( \
213  InitializerType &reader_initializer, NameType node_name, const ariles::ConfigurableFlags &param) \
214  { \
215  ARILES_TRACE_FUNCTION; \
216  typename t_Bridge::Reader reader(reader_initializer); \
217  this->readConfig(reader, node_name, param); \
218  }
219 
220  ARILES_READ_CONFIG(t_ReaderInitializer, const std::string &)
221  ARILES_READ_CONFIG(const t_ReaderInitializer, const std::string &)
222  ARILES_READ_CONFIG(t_ReaderInitializer, const char *)
223  ARILES_READ_CONFIG(const t_ReaderInitializer, const char *)
224 
225 # undef ARILES_READ_CONFIG
226 
227  /// @}
228 
229 
230 # define ARILES_WRITE_CONFIG(InitializerType) \
231  template <class t_Bridge, class t_WriterInitializer> \
232  void writeConfig(InitializerType &writer_initializer) const \
233  { \
234  typename t_Bridge::Writer writer(writer_initializer); \
235  this->writeConfig(writer, this->getArilesConfigurableFlags()); \
236  } \
237  template <class t_Bridge, class t_WriterInitializer> \
238  void writeConfig(InitializerType &writer_initializer, const ariles::ConfigurableFlags &param) const \
239  { \
240  typename t_Bridge::Writer writer(writer_initializer); \
241  this->writeConfig(writer, param); \
242  }
243 
244  ARILES_WRITE_CONFIG(t_WriterInitializer)
245  ARILES_WRITE_CONFIG(const t_WriterInitializer)
246 
247 # undef ARILES_WRITE_CONFIG
248 
249 
250 
251 /**
252  * @brief Write configuration.
253  *
254  * @param[in] file_name file name
255  * @param[in] node_name node name, the default is used if empty
256  */
257 # define ARILES_WRITE_CONFIG(InitializerType, NameType) \
258  template <class t_Bridge, class t_WriterInitializer> \
259  void writeConfig(InitializerType &writer_initializer, NameType node_name) const \
260  { \
261  typename t_Bridge::Writer writer(writer_initializer); \
262  this->writeConfig(writer, node_name, this->getArilesConfigurableFlags()); \
263  } \
264  template <class t_Bridge, class t_WriterInitializer> \
265  void writeConfig( \
266  InitializerType &writer_initializer, NameType node_name, const ariles::ConfigurableFlags &param) const \
267  { \
268  typename t_Bridge::Writer writer(writer_initializer); \
269  this->writeConfig(writer, node_name, param); \
270  }
271 
272  ARILES_WRITE_CONFIG(t_WriterInitializer, const std::string &)
273  ARILES_WRITE_CONFIG(const t_WriterInitializer, const std::string &)
274  ARILES_WRITE_CONFIG(t_WriterInitializer, const char *)
275  ARILES_WRITE_CONFIG(const t_WriterInitializer, const char *)
276 
277 # undef ARILES_WRITE_CONFIG
278 
279 
280 
281  /**
282  * @brief Write configuration
283  *
284  * @param[in,out] writer configuration writer
285  */
286  void writeConfig(ariles::WriterBase &writer, const ariles::ConfigurableFlags &param) const
287  {
288  this->writeConfig(writer, this->getConfigSectionID(), param);
289  }
290  void writeConfig(ariles::WriterBase &writer) const
291  {
292  this->writeConfig(writer, this->getConfigSectionID(), this->getArilesConfigurableFlags());
293  }
294 
295 
296 /**
297  * @brief Write configuration
298  *
299  * @param[in,out] writer configuration writer
300  * @param[in] node_name node name, the default is used if empty
301  */
302 # define ARILES_WRITE_CONFIG(NameType) \
303  virtual void writeConfig( \
304  ariles::WriterBase &writer, NameType node_name, const ariles::ConfigurableFlags &param) const = 0; \
305  void writeConfig(ariles::WriterBase &writer, NameType node_name) const \
306  { \
307  this->writeConfig(writer, node_name, this->getArilesConfigurableFlags()); \
308  }
309 
310  ARILES_WRITE_CONFIG(const std::string &)
311  ARILES_WRITE_CONFIG(const char *)
312 
313 # undef ARILES_WRITE_CONFIG
314 
315 
316 
317  virtual void writeConfigEntries(ariles::WriterBase &visitor, const ariles::WriterBase::Parameters &param) const
318  {
320  arilesVirtualVisit(visitor, param);
321  }
322  };
323 
324 
326  {
327  public:
329  {
330  static ConfigurableFlags parameters(
332  return (parameters);
333  }
334  };
335 
337  {
338  public:
340  {
341  static ConfigurableFlags parameters(
343  return (parameters);
344  }
345  };
346 
347  /// Default configurable base
349  {
350  public:
352  {
354  return (parameters);
355  }
356  };
357 } // namespace ariles
358 
359 # include "adapters/basic.h"
360 # include "types.h"
361 
362 #else
363 
364 # define ARILES_DISABLED
365 
366 namespace ariles
367 {
368  // Some classes may inherit from this
369  class ARILES_VISIBILITY_ATTRIBUTE StrictConfigurableBase
370  {
371  protected:
372  /**
373  * @brief Protected destructor: prevent destruction of the
374  * child classes through a base pointer.
375  */
376  ~StrictConfigurableBase()
377  {
378  }
379 
380  public:
381  virtual void finalize(){};
382  };
383 
384 
385  // Some classes may inherit from this
386  class ARILES_VISIBILITY_ATTRIBUTE RelaxedConfigurableBase
387  {
388  protected:
389  /**
390  * @brief Protected destructor: prevent destruction of the
391  * child classes through a base pointer.
392  */
393  ~RelaxedConfigurableBase()
394  {
395  }
396 
397  public:
398  virtual void finalize(){};
399  };
400 
401 
402  // Some classes may inherit from this
403  class ARILES_VISIBILITY_ATTRIBUTE ConfigurableBase
404  {
405  protected:
406  /**
407  * @brief Protected destructor: prevent destruction of the
408  * child classes through a base pointer.
409  */
410  ~ConfigurableBase()
411  {
412  }
413 
414  public:
415  virtual void finalize(){};
416  };
417 } // namespace ariles
418 
419 #endif
#define ARILES_TRACE_FUNCTION
Definition: trace.h:118
Configurable base class.
Definition: ariles.h:64
virtual void writeConfigEntries(ariles::WriterBase &visitor, const ariles::WriterBase::Parameters &param) const
Definition: ariles.h:317
void readConfig(ariles::ReaderBase &reader, const ariles::ConfigurableFlags &param)
Read configuration (assuming the configuration node to be in the root).
Definition: ariles.h:129
virtual const ConfigurableFlags & getArilesConfigurableFlags() const
Definition: ariles.h:339
virtual void setDefaults()
Definition: ariles.h:79
void readConfig(ariles::ReaderBase &reader)
Definition: ariles.h:135
#define ARILES_READ_CONFIG(NameType)
Read configuration (assuming the configuration node to be in the root).
Definition: ariles.h:203
virtual const ConfigurableFlags & getArilesConfigurableFlags() const
Definition: ariles.h:328
virtual void finalize()
Definition: ariles.h:87
void writeConfig(ariles::WriterBase &writer, const ariles::ConfigurableFlags &param) const
Write configuration.
Definition: ariles.h:286
~CommonConfigurableBase()
Protected destructor: prevent destruction of the child classes through a base pointer.
Definition: ariles.h:71
void writeConfig(ariles::WriterBase &writer) const
Definition: ariles.h:290
serialization::Features BridgeFlags
Definition: ariles.h:26
ariles::compare::Visitor::Parameters ComparisonParameters
Definition: ariles.h:56
virtual const ConfigurableFlags & getArilesConfigurableFlags() const
Definition: ariles.h:351
Default configurable base.
Definition: ariles.h:348
virtual void readConfigEntries(ariles::ReaderBase &visitor, const ariles::ReaderBase::Parameters &parameters)
Definition: ariles.h:116
ariles::write::Visitor WriterBase
Definition: ariles.h:57
ariles::read::Visitor ReaderBase
Definition: ariles.h:58
#define ARILES_VISIBILITY_ATTRIBUTE
Definition: helpers.h:69
#define ARILES_WRITE_CONFIG(InitializerType)
Write configuration.
Definition: ariles.h:302
Definition: basic.h:17