OMNeT++ API 6.1
Discrete Event Simulation Library
cconfiguration.h
1 //==========================================================================
2 // CCONFIGURATION.H - part of
3 // OMNeT++/OMNEST
4 // Discrete System Simulation in C++
5 //
6 //==========================================================================
7 
8 /*--------------------------------------------------------------*
9  Copyright (C) 1992-2017 Andras Varga
10  Copyright (C) 2006-2017 OpenSim Ltd.
11 
12  This file is distributed WITHOUT ANY WARRANTY. See the file
13  `license' for details on this and other legal matters.
14 *--------------------------------------------------------------*/
15 
16 #ifndef __OMNETPP_CCONFIGURATION_H
17 #define __OMNETPP_CCONFIGURATION_H
18 
19 #include <string>
20 #include <map>
21 #include <vector>
22 #include "simkerneldefs.h"
23 #include "cobject.h"
24 
25 namespace omnetpp {
26 
27 class FileLine;
28 class cConfigOption;
29 
33 #define CFGNAME_GENERAL "General"
34 
43 #define CFGVAR_RUNID "runid"
44 #define CFGVAR_INIFILE "inifile"
45 #define CFGVAR_CONFIGNAME "configname"
46 #define CFGVAR_RUNNUMBER "runnumber"
47 #define CFGVAR_NETWORK "network"
48 #define CFGVAR_EXPERIMENT "experiment"
49 #define CFGVAR_MEASUREMENT "measurement"
50 #define CFGVAR_REPLICATION "replication"
51 #define CFGVAR_PROCESSID "processid"
52 #define CFGVAR_DATETIME "datetime"
53 #define CFGVAR_DATETIMEF "datetimef"
54 #define CFGVAR_RESULTDIR "resultdir"
55 #define CFGVAR_REPETITION "repetition"
56 #define CFGVAR_SEEDSET "seedset"
57 #define CFGVAR_ITERATIONVARS "iterationvars"
58 #define CFGVAR_ITERATIONVARSF "iterationvarsf"
59 #define CFGVAR_ITERATIONVARSD "iterationvarsd"
60 
76 class SIM_API cConfiguration : public cObject
77 {
78  public:
82  class SIM_API KeyValue {
83  public:
84  virtual ~KeyValue() {}
85  virtual const char *getKey() const = 0;
86  virtual const char *getValue() const = 0;
87  virtual const char *getBaseDirectory() const = 0;
88  virtual FileLine getSourceLocation() const;
89  };
90 
94  struct RunInfo {
95  std::string info; // concatenated
96  std::map<std::string,std::string> runAttrs; // run attributes
97  std::string configBrief; // config options that contain inifile variables (${foo}), expanded
98  };
99 
100  public:
108  virtual const char *getConfigValue(const char *key) const = 0;
109 
119  virtual const KeyValue& getConfigEntry(const char *key) const = 0;
120 
127  virtual const char *getPerObjectConfigValue(const char *objectFullPath, const char *keySuffix) const = 0;
128 
140  virtual const KeyValue& getPerObjectConfigEntry(const char *objectFullPath, const char *keySuffix) const = 0;
142 
145  static bool parseBool(const char *s, const char *defaultValue, bool fallbackValue=false);
146  static long parseLong(const char *s, const char *defaultValue, long fallbackValue=0);
147  static double parseDouble(const char *s, const char *unit, const char *defaultValue, double fallbackValue=0);
148  static std::string parseString(const char *s, const char *defaultValue, const char *fallbackValue="");
149  static std::string parseFilename(const char *s, const char *baseDir, const char *defaultValue);
150  static std::vector<std::string> parseFilenames(const char *s, const char *baseDir, const char *defaultValue);
151  static std::string adjustPath(const char *s, const char *baseDir, const char *defaultValue);
153 
160  virtual const char *getConfigValue(cConfigOption *option, const char *fallbackValue=nullptr) const;
161 
166  virtual const char *getAsCustom(cConfigOption *option, const char *fallbackValue=nullptr) const;
167 
172  virtual bool getAsBool(cConfigOption *option, bool fallbackValue=false) const;
173 
178  virtual long getAsInt(cConfigOption *option, long fallbackValue=0) const;
179 
184  virtual double getAsDouble(cConfigOption *option, double fallbackValue=0) const;
185 
190  virtual std::string getAsString(cConfigOption *option, const char *fallbackValue="") const;
191 
197  virtual std::string getAsFilename(cConfigOption *option) const;
198 
205  virtual std::vector<std::string> getAsFilenames(cConfigOption *option) const;
206 
214  virtual std::string getAsPath(cConfigOption *option) const;
216 
223  virtual const char *getPerObjectConfigValue(const char *objectFullPath, cConfigOption *option, const char *fallbackValue=nullptr) const;
224 
229  virtual const char *getAsCustom(const char *objectFullPath, cConfigOption *option, const char *fallbackValue=nullptr) const;
230 
235  virtual bool getAsBool(const char *objectFullPath, cConfigOption *option, bool fallbackValue=false) const;
236 
241  virtual long getAsInt(const char *objectFullPath, cConfigOption *option, long fallbackValue=0) const;
242 
247  virtual double getAsDouble(const char *objectFullPath, cConfigOption *option, double fallbackValue=0) const;
248 
253  virtual std::string getAsString(const char *objectFullPath, cConfigOption *option, const char *fallbackValue="") const;
254 
260  virtual std::string getAsFilename(const char *objectFullPath, cConfigOption *option) const;
261 
268  virtual std::vector<std::string> getAsFilenames(const char *objectFullPath, cConfigOption *option) const;
269 
277  virtual std::string getAsPath(const char *objectFullPath, cConfigOption *option) const;
279 
286  virtual const char *substituteVariables(const char *value) const = 0;
288 };
289 
290 
304 class SIM_API cConfigurationEx : public cConfiguration
305 {
306  public:
310  enum FilterFlags {
311  FILT_ESSENTIAL_CONFIG = 1 << 0,
312  FILT_GLOBAL_CONFIG = 1 << 1 | FILT_ESSENTIAL_CONFIG, // both per-run and not per-run
313  FILT_PER_OBJECT_CONFIG = 1 << 2,
314  FILT_CONFIG = FILT_GLOBAL_CONFIG | FILT_PER_OBJECT_CONFIG,
315  FILT_PARAM = 1 << 3,
316  FILT_ALL = FILT_CONFIG | FILT_PARAM
317  };
318 
319  public:
328  virtual void initializeFrom(cConfiguration *bootConfig) = 0;
329 
334  virtual const char *getFileName() const = 0;
335 
348  virtual void validate(const char *ignorableConfigKeys=nullptr) const = 0;
349 
355  virtual std::vector<std::string> getConfigNames() = 0;
356 
362  virtual void activateConfig(const char *configName, int runNumber=0) = 0;
363 
367  virtual std::string getConfigDescription(const char *configName) const = 0;
368 
373  virtual bool isAbstractConfig(const char *configName) const = 0;
374 
382  virtual std::vector<std::string> getBaseConfigs(const char *configName) const = 0;
383 
389  virtual std::vector<std::string> getConfigChain(const char * configName) const = 0;
390 
396  virtual int getNumRunsInConfig(const char *configName) const = 0;
397 
407  virtual std::vector<RunInfo> unrollConfig(const char *configName) const = 0;
408 
412  virtual const char *getActiveConfigName() const = 0;
413 
418  virtual int getActiveRunNumber() const = 0;
419 
431  virtual const char *getVariable(const char *varname) const = 0;
432 
436  virtual std::vector<const char *> getIterationVariableNames() const = 0;
437 
442  virtual std::vector<const char *> getPredefinedVariableNames() const = 0;
443 
448  virtual const char *getVariableDescription(const char *varname) const = 0;
449 
453  virtual void dump() const = 0;
455 
458 
463  virtual std::vector<const char *> getMatchingConfigKeys(const char *pattern) const = 0;
464 
471  virtual const char *getParameterValue(const char *moduleFullPath, const char *paramName, bool hasDefaultValue) const = 0;
472 
483  virtual const KeyValue& getParameterEntry(const char *moduleFullPath, const char *paramName, bool hasDefaultValue) const = 0;
484 
493  virtual std::vector<const char *> getKeyValuePairs(int flags=FILT_ALL) const = 0;
494 
503  virtual std::vector<const char *> getMatchingPerObjectConfigKeySuffixes(const char *objectFullPath, const char *keySuffixPattern) const = 0;
505 };
506 
507 } // namespace omnetpp
508 
509 #endif
510 
511 
omnetpp::cConfigurationEx
Represents a configuration suitable for use with the Envir library.
Definition: cconfiguration.h:304
omnetpp::cConfiguration
Represents the configuration, as accessed by the simulation kernel.
Definition: cconfiguration.h:76
omnetpp::cConfiguration::RunInfo
Struct used by unrollConfig() to return information.
Definition: cconfiguration.h:94
omnetpp::cConfiguration::KeyValue
Describes a configuration entry.
Definition: cconfiguration.h:82
omnetpp::cConfigOption
Describes a configuration option.
Definition: cconfigoption.h:33
omnetpp::FileLine
Definition: fileline.h:27
omnetpp::cConfigurationEx::FilterFlags
FilterFlags
Definition: cconfiguration.h:310