humoto
define_accessors.h
Go to the documentation of this file.
1 /**
2  @file
3  @author Alexander Sherikov
4  @copyright 2014-2017 INRIA. Licensed under the Apache License, Version 2.0.
5  (see @ref LICENSE or http://www.apache.org/licenses/LICENSE-2.0)
6 
7  @brief Inclusion of this file results in generation of functions which
8  read and write entries 'HUMOTO_CONFIG_ENTRIES' defined in the including
9  header from / to a configuration file.
10 */
11 
12 #ifndef HUMOTO_DOXYGEN_PROCESSING
13 
14 #ifdef HUMOTO_USE_CONFIG
15 // Generic stuff
16  private:
17  // Define read and write methods
18  #ifdef HUMOTO_CONFIG_ENTRIES
19  #define HUMOTO_CONFIG_COMPOUND_(entry) HUMOTO_CONFIG_WRITE_COMPOUND_(entry)
20  #define HUMOTO_CONFIG_COMPOUND(entry) HUMOTO_CONFIG_WRITE_COMPOUND(entry)
21 
22  #define HUMOTO_CONFIG_SCALAR_(entry) HUMOTO_CONFIG_WRITE_SCALAR_(entry)
23  #define HUMOTO_CONFIG_SCALAR(entry) HUMOTO_CONFIG_WRITE_SCALAR(entry)
24 
25  #define HUMOTO_CONFIG_ENUM_(entry) HUMOTO_CONFIG_WRITE_ENUM_(entry)
26  #define HUMOTO_CONFIG_ENUM(entry) HUMOTO_CONFIG_WRITE_ENUM(entry)
27 
28  #define HUMOTO_CONFIG_PARENT_CLASS(entry) HUMOTO_CONFIG_WRITE_PARENT_CLASS(entry)
29  #define HUMOTO_CONFIG_MEMBER_CLASS(entry, name) HUMOTO_CONFIG_WRITE_MEMBER_CLASS(entry, name)
30 
31  template <class t_Writer>
32  void writeConfigEntriesTemplate(t_Writer & writer) const
33  {
35  }
36 
37  #undef HUMOTO_CONFIG_COMPOUND_
38  #undef HUMOTO_CONFIG_COMPOUND
39 
40  #undef HUMOTO_CONFIG_SCALAR_
41  #undef HUMOTO_CONFIG_SCALAR
42 
43  #undef HUMOTO_CONFIG_ENUM_
44  #undef HUMOTO_CONFIG_ENUM
45 
46  #undef HUMOTO_CONFIG_PARENT_CLASS
47  #undef HUMOTO_CONFIG_MEMBER_CLASS
48 
49 
50 
51  #define HUMOTO_CONFIG_COMPOUND_(entry) HUMOTO_CONFIG_READ_COMPOUND_(entry)
52  #define HUMOTO_CONFIG_COMPOUND(entry) HUMOTO_CONFIG_READ_COMPOUND(entry)
53 
54  #define HUMOTO_CONFIG_SCALAR_(entry) HUMOTO_CONFIG_READ_SCALAR_(entry)
55  #define HUMOTO_CONFIG_SCALAR(entry) HUMOTO_CONFIG_READ_SCALAR(entry)
56 
57  #define HUMOTO_CONFIG_ENUM_(entry) HUMOTO_CONFIG_READ_ENUM_(entry)
58  #define HUMOTO_CONFIG_ENUM(entry) HUMOTO_CONFIG_READ_ENUM(entry)
59 
60  #define HUMOTO_CONFIG_PARENT_CLASS(entry) HUMOTO_CONFIG_READ_PARENT_CLASS(entry)
61  #define HUMOTO_CONFIG_MEMBER_CLASS(entry, name) HUMOTO_CONFIG_READ_MEMBER_CLASS(entry, name)
62 
63  template <class t_Reader>
64  void readConfigEntriesTemplate( t_Reader & reader,
65  const bool crash_on_missing_entry = false)
66  {
68  finalize();
69  }
70 
71  #undef HUMOTO_CONFIG_COMPOUND_
72  #undef HUMOTO_CONFIG_COMPOUND
73 
74  #undef HUMOTO_CONFIG_SCALAR_
75  #undef HUMOTO_CONFIG_SCALAR
76 
77  #undef HUMOTO_CONFIG_ENUM_
78  #undef HUMOTO_CONFIG_ENUM
79 
80  #undef HUMOTO_CONFIG_PARENT_CLASS
81  #undef HUMOTO_CONFIG_MEMBER_CLASS
82  #endif
83 
84 
85  protected:
86  // Define node name
87  #ifdef HUMOTO_CONFIG_SECTION_ID
88  const std::string & getConfigSectionID() const
89  {
90  static const std::string name(HUMOTO_CONFIG_SECTION_ID);
91  return (name);
92  }
93  #endif
94 
95 
96  // Count number of entries and define a function, which returns it.
97  #ifdef HUMOTO_CONFIG_ENTRIES
98  #define HUMOTO_CONFIG_COMPOUND_(entry) +1
99  #define HUMOTO_CONFIG_COMPOUND(entry) +1
100 
101  #define HUMOTO_CONFIG_SCALAR_(entry) +1
102  #define HUMOTO_CONFIG_SCALAR(entry) +1
103 
104  #define HUMOTO_CONFIG_ENUM_(entry) +1
105  #define HUMOTO_CONFIG_ENUM(entry) +1
106 
107  #define HUMOTO_CONFIG_PARENT_CLASS(entry) +entry::getNumberOfEntries()
108  #define HUMOTO_CONFIG_MEMBER_CLASS(entry, name) +1
109 
110  std::size_t getNumberOfEntries() const
111  {
112  static const std::size_t num_entries = (0 HUMOTO_MACRO_SUBSTITUTE(HUMOTO_CONFIG_ENTRIES) );
113  return(num_entries);
114  }
115 
116  #undef HUMOTO_CONFIG_COMPOUND_
117  #undef HUMOTO_CONFIG_COMPOUND
118 
119  #undef HUMOTO_CONFIG_SCALAR_
120  #undef HUMOTO_CONFIG_SCALAR
121 
122  #undef HUMOTO_CONFIG_ENUM_
123  #undef HUMOTO_CONFIG_ENUM
124 
125  #undef HUMOTO_CONFIG_PARENT_CLASS
126  #undef HUMOTO_CONFIG_MEMBER_CLASS
127  #endif
128 
129 
130  public:
131  // Define constructors if requested
132  #ifdef HUMOTO_CONFIG_CONSTRUCTOR
133  /**
134  * Define constructors for the given class.
135  */
136  template <class t_Reader>
137  explicit HUMOTO_CONFIG_CONSTRUCTOR(
138  t_Reader &reader,
139  const std::string &node_name,
140  const bool crash_on_missing_entry = default_crash_on_missing_entry_)
141  {
142  readConfig(reader, node_name, crash_on_missing_entry);
143  }
144 
145  template <class t_Reader>
146  explicit HUMOTO_CONFIG_CONSTRUCTOR(
147  t_Reader &reader,
148  const bool crash_on_missing_entry = default_crash_on_missing_entry_)
149  {
150  readConfig(reader, crash_on_missing_entry);
151  }
152  #endif
153 
154 
155 // Format-specific stuff
156  #ifdef HUMOTO_BRIDGE_config_yaml_DEFINITIONS
158  #endif
159 
160  #ifdef HUMOTO_BRIDGE_config_msgpack_DEFINITIONS
162  #endif
163 
164 #endif //HUMOTO_USE_CONFIG
165 
166 #undef HUMOTO_CONFIG_SECTION_ID
167 #undef HUMOTO_CONFIG_CONSTRUCTOR
168 #undef HUMOTO_CONFIG_ENTRIES
169 #endif
#define HUMOTO_CONFIG_ENTRIES
Definition: solution.h:180
#define HUMOTO_MACRO_SUBSTITUTE(arg)
#define HUMOTO_CONFIG_CONSTRUCTOR
Definition: solution.h:179
#define HUMOTO_BRIDGE_config_yaml_DEFINITIONS
Definition: config_yaml.h:65
#define HUMOTO_CONFIG_SECTION_ID
#define HUMOTO_BRIDGE_config_msgpack_DEFINITIONS