OMNeT++ Simulation Library  6.0.3
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 
376  virtual std::vector<std::string> getBaseConfigs(const char *configName) const = 0;
377 
383  virtual std::vector<std::string> getConfigChain(const char * configName) const = 0;
384 
390  virtual int getNumRunsInConfig(const char *configName) const = 0;
391 
401  virtual std::vector<RunInfo> unrollConfig(const char *configName) const = 0;
402 
406  virtual const char *getActiveConfigName() const = 0;
407 
412  virtual int getActiveRunNumber() const = 0;
413 
425  virtual const char *getVariable(const char *varname) const = 0;
426 
430  virtual std::vector<const char *> getIterationVariableNames() const = 0;
431 
436  virtual std::vector<const char *> getPredefinedVariableNames() const = 0;
437 
442  virtual const char *getVariableDescription(const char *varname) const = 0;
443 
447  virtual void dump() const = 0;
449 
452 
457  virtual std::vector<const char *> getMatchingConfigKeys(const char *pattern) const = 0;
458 
465  virtual const char *getParameterValue(const char *moduleFullPath, const char *paramName, bool hasDefaultValue) const = 0;
466 
477  virtual const KeyValue& getParameterEntry(const char *moduleFullPath, const char *paramName, bool hasDefaultValue) const = 0;
478 
487  virtual std::vector<const char *> getKeyValuePairs(int flags=FILT_ALL) const = 0;
488 
497  virtual std::vector<const char *> getMatchingPerObjectConfigKeySuffixes(const char *objectFullPath, const char *keySuffixPattern) const = 0;
499 };
500 
501 } // namespace omnetpp
502 
503 #endif
504 
505 
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