-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathConfigInterface.hpp
More file actions
264 lines (240 loc) · 12.7 KB
/
Copy pathConfigInterface.hpp
File metadata and controls
264 lines (240 loc) · 12.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
/* =============================================================================
* Vader Modular Fuzzer (VMF)
* Copyright (c) 2021-2025 The Charles Stark Draper Laboratory, Inc.
* <vmf@draper.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 (only) as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @license GPL-2.0-only <https://spdx.org/licenses/GPL-2.0-only.html>
* ===========================================================================*/
#pragma once
#include "Module.hpp"
#include <string>
#include <vector>
namespace vmf
{
class Module; //Forward-declaration
/**
* @brief This class defines the interface used by modules to retrieve their configuration information
*
* Modules can retrieve any configuration parameter that is specific to that module or that is globally scoped.
*/
class ConfigInterface
{
public:
///The key name for the root module (used in the config file)
const std::string ROOT_MODULE_KEY = "controller";
///The key name for the storage module (used in the config file)
const std::string STORAGE_MODULE_KEY = "storage";
///The key name for module children (used in the config file)
const std::string VMF_FRAMEWORK_KEY = "vmfFramework";
///The key name for the vmf variables configuration section (used in the config file)
const std::string VMF_VARIABLES_KEY = "vmfVariables";
///The key name for the vmf class set configuration section (used in the config file)
const std::string VMF_CLASS_SET_KEY = "vmfClassSet";
///The key name for the vmf modules configuration section (used in the config file)
const std::string VMF_MODULES_KEY = "vmfModules";
///The key name for the vmf distributed configuration section (used in the config file)
const std::string VMF_DISTRIBUTED_KEY = "vmfDistributed";
/**
* @brief Lookup a module's name given its unique ID
*
* @param id unique identifer for an instance of a module
* @return std::string the instance's name
*/
virtual std::string getModuleName(int id) = 0;
/**
* @brief Get the Output Directory for the application
* This parameter is handled separately because the top level application creates
* a dated sub-directory for each VMF run.
*
* @return std::string
*/
virtual std::string getOutputDir() = 0;
/**
* @brief Retrieves the submodules that are associated with this module in the config file(s)
*
* To use, any module can just call getSubModules(getModuleName())
* Module* will need to be converted to their underlying type, using the convenience methods
* isAnInstance() and castTo() that are defined in each of the module base classes.
*
* @param parentModuleName the name of the module
* @return std::vector<Module*> the submodules
*/
virtual std::vector<Module*> getSubModules(std::string parentModuleName) = 0;
/**
* @brief Check to see if a parameter is defined in a config file, without returning the value.
*
* This method is primarily useful for truly optional parameters. Parameters with a default
* value should instead be retrieved with the appropriate getXXXParam method (using the version
* accepts a default parameter -- e.g. getIntParam(moduleName,paramName,defaultValue).
*
* @param moduleName the name of the module (use getModuleName())
* @param paramName the name of the parameter, which must match the name that is in the config file
* @return true if an instance of the parameter is defined, and false otherwise
*/
virtual bool isParam(std::string moduleName, std::string paramName) = 0;
/**
* @brief Get a string of all data from the config associated with the module name.
*
* @param moduleName the name of the module (use getModuleName())
* @return std::string the concatenated value of all configs
*/
virtual std::string getAllParams(std::string moduleName) = 0;
/**
* @brief Get the YAML of map for the module name.
*
* @param moduleName the name of the module (use getModuleName())
* @return std::string YAML serialized value of all configs
*/
virtual std::string getAllParamsYAML(std::string moduleName) = 0;
/**
* @brief Get a required string based parameter from the config file(s)
*
* @param moduleName the name of the module (use getModuleName())
* @param paramName the name of the parameter, which must match the name that is in the config file
* @return std::string the associated value
* @throws RuntimeException if the parameter is not found
*/
virtual std::string getStringParam(std::string moduleName, std::string paramName) = 0;
/**
* @brief Get an optional string based parameter from the config file(s)
* If the parameter is not found in the config file, the provided default value will be returned instead.
*
* @param moduleName the name of the module (use getModuleName())
* @param paramName the name of the parameter, which must match the name that is in the config file
* @param defaultValue the default value to return if the config option is not in the file
* @return std::string the associated value
*/
virtual std::string getStringParam(std::string moduleName, std::string paramName, std::string defaultValue) = 0;
/**
* @brief Get a required string vector based parameter from the config file(s)
*
* @param moduleName the name of the module (use getModuleName())
* @param paramName the name of the parameter, which must match the name that is in the config file
* @return std::vector<std::string> the associated value
* @throws RuntimeException if the parameter is not found
*/
virtual std::vector<std::string> getStringVectorParam(std::string moduleName, std::string paramName) = 0;
/**
* @brief Get an optional string vector based parameter from the config file(s)
*
* @param moduleName the name of the module (use getModuleName())
* @param paramName the name of the parameter, which must match the name that is in the config file
* @param defaultValue the default value to return if the config option is not in the file
* @return std::vector<std::string> the associated value
* @throws RuntimeException if the parameter is not found
*/
virtual std::vector<std::string> getStringVectorParam(std::string moduleName, std::string paramName, std::vector<std::string> defaultValue) = 0;
/**
* @brief Get a required integer based parameter from the config file(s)
*
* @param moduleName the name of the module (use getModuleName())
* @param paramName the name of the parameter, which must match the name that is in the config file
* @return int the associated value
* @throws RuntimeException if the parameter is not found
*/
virtual int getIntParam(std::string moduleName, std::string paramName) = 0;
/**
* @brief Get an optional integer based parameter from the config file(s)
* If the parameter is not found in the config file, the provided default value will be returned instead.
*
* @param moduleName the name of the module (use getModuleName())
* @param paramName the name of the parameter, which must match the name that is in the config file
* @param defaultValue the default value to return if the config option is not in the file
* @return int the associated value
*/
virtual int getIntParam(std::string moduleName, std::string paramName, int defaultValue) = 0;
/**
* @brief Get a required int vector based parameter from the config file(s)
*
* @param moduleName the name of the module (use getModuleName())
* @param paramName the name of the parameter, which must match the name that is in the config file
* @return std::vector<int> the associated value
* @throws RuntimeException if the parameter is not found
*/
virtual std::vector<int> getIntVectorParam(std::string moduleName, std::string paramName) = 0;
/**
* @brief Get an optional int vector based parameter from the config file(s)
* If the parameter is not found in the config file, the provided default value will be returned instead.
*
* @param moduleName the name of the module (use getModuleName())
* @param paramName the name of the parameter, which must match the name that is in the config file
* @param defaultValue the default to return if the parameter is not found
* @return std::vector<int> the associated value
* @throws RuntimeException if the parameter is not found
*/
virtual std::vector<int> getIntVectorParam(std::string moduleName, std::string paramName, std::vector<int> defaultValue) = 0;
/**
* @brief Get a required float based parameter from the config file(s)
*
* @param moduleName the name of the module (use getModuleName())
* @param paramName the name of the parameter, which must match the name that is in the config file
* @return float the associated value
* @throws RuntimeException if the parameter is not found
*/
virtual float getFloatParam(std::string moduleName, std::string paramName) = 0;
/**
* @brief Get an optional float based parameter from the config file(s)
* If the parameter is not found in the config file, the provided default value will be returned instead.
*
* @param moduleName the name of the module (use getModuleName())
* @param paramName the name of the parameter, which must match the name that is in the config file
* @param defaultValue the default value to return if the config option is not in the file
* @return float the associated value
*/
virtual float getFloatParam(std::string moduleName, std::string paramName, float defaultValue) = 0;
/**
* @brief Get a required float vector based parameter from the config file(s)
*
* @param moduleName the name of the module (use getModuleName())
* @param paramName the name of the parameter, which must match the name that is in the config file
* @return std::vector<float> the associated value
* @throws RuntimeException if the parameter is not found
*/
virtual std::vector<float> getFloatVectorParam(std::string moduleName, std::string paramName) = 0;
/**
* @brief Get an optional float vector based parameter from the config file(s)
* If the parameter is not found in the config file, the provided default value will be returned instead.
*
* @param moduleName the name of the module (use getModuleName())
* @param paramName the name of the parameter, which must match the name that is in the config file
* @param defaultValue the default to return if the parameter is not found
* @return std::vector<float> the associated value
* @throws RuntimeException if the parameter is not found
*/
virtual std::vector<float> getFloatVectorParam(std::string moduleName, std::string paramName, std::vector<float> defaultValue) = 0;
/**
* @brief Get a required boolean based parameter from the config file(s)
* Note: "true" or "TRUE" are acceptable formats for the parameter
*
* @param moduleName the name of the module (use getModuleName())
* @param paramName the name of the parameter, which must match the name that is in the config file
* @return bool the associated value
* @throws RuntimeException if the parameter is not found
*/
virtual bool getBoolParam(std::string moduleName, std::string paramName) = 0;
/**
* @brief Get an optional boolean based parameter from the config file(s)
* If the parameter is not found in the config file, the provided default value will be returned instead.
* Note: "true" or "TRUE" are acceptable formats for the parameter
*
* @param moduleName the name of the module (use getModuleName())
* @param paramName the name of the parameter, which must match the name that is in the config file
* @param defaultValue the default value to return if the config option is not in the file
* @return bool the associated value
*/
virtual bool getBoolParam(std::string moduleName, std::string paramName, bool defaultValue) = 0;
//Note: The above methods are provided individually by type, because C++ does not allow virtual templated functions
};
}