OMNeT++ Simulation Library  5.6.1
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 cConfigOption;
28 
32 #define CFGNAME_GENERAL "General"
33 
39 #define CFGVAR_RUNID "runid"
40 #define CFGVAR_INIFILE "inifile"
41 #define CFGVAR_CONFIGNAME "configname"
42 #define CFGVAR_RUNNUMBER "runnumber"
43 #define CFGVAR_NETWORK "network"
44 #define CFGVAR_EXPERIMENT "experiment"
45 #define CFGVAR_MEASUREMENT "measurement"
46 #define CFGVAR_REPLICATION "replication"
47 #define CFGVAR_PROCESSID "processid"
48 #define CFGVAR_DATETIME "datetime"
49 #define CFGVAR_RESULTDIR "resultdir"
50 #define CFGVAR_REPETITION "repetition"
51 #define CFGVAR_SEEDSET "seedset"
52 #define CFGVAR_ITERATIONVARS "iterationvars" // without $repetition
53 #define CFGVAR_ITERATIONVARSF "iterationvarsf" // same, sanitized for use in file names
54 
55 
70 class SIM_API cConfiguration : public cObject
71 {
72  public:
76  class KeyValue {
77  public:
78  virtual ~KeyValue() {}
79  virtual const char *getKey() const = 0;
80  virtual const char *getValue() const = 0;
81  virtual const char *getBaseDirectory() const = 0;
82  };
83 
87  struct RunInfo {
88  std::string info; // concatenated
89  std::map<std::string,std::string> runAttrs; // run attributes
90  std::string configBrief; // config options that contain inifile variables (${foo}), expanded
91  };
92 
93  public:
100  virtual const char *getConfigValue(const char *key) const = 0;
101 
112  virtual const KeyValue& getConfigEntry(const char *key) const = 0;
113 
119  virtual const char *getPerObjectConfigValue(const char *objectFullPath, const char *keySuffix) const = 0;
120 
131  virtual const KeyValue& getPerObjectConfigEntry(const char *objectFullPath, const char *keySuffix) const = 0;
133 
136  static bool parseBool(const char *s, const char *defaultValue, bool fallbackValue=false);
137  static long parseLong(const char *s, const char *defaultValue, long fallbackValue=0);
138  static double parseDouble(const char *s, const char *unit, const char *defaultValue, double fallbackValue=0);
139  static std::string parseString(const char *s, const char *defaultValue, const char *fallbackValue="");
140  static std::string parseFilename(const char *s, const char *baseDir, const char *defaultValue);
141  static std::vector<std::string> parseFilenames(const char *s, const char *baseDir, const char *defaultValue);
142  static std::string adjustPath(const char *s, const char *baseDir, const char *defaultValue);
144 
147 //FIXME why aren't these methods all const???
152  virtual const char *getAsCustom(cConfigOption *option, const char *fallbackValue=nullptr) const;
153 
158  virtual bool getAsBool(cConfigOption *option, bool fallbackValue=false) const;
159 
164  virtual long getAsInt(cConfigOption *option, long fallbackValue=0) const;
165 
170  virtual double getAsDouble(cConfigOption *option, double fallbackValue=0) const;
171 
176  virtual std::string getAsString(cConfigOption *option, const char *fallbackValue="") const;
177 
183  virtual std::string getAsFilename(cConfigOption *option) const;
184 
191  virtual std::vector<std::string> getAsFilenames(cConfigOption *option) const;
192 
199  virtual std::string getAsPath(cConfigOption *option) const;
201 
208  virtual const char *getAsCustom(const char *objectFullPath, cConfigOption *option, const char *fallbackValue=nullptr) const;
209 
214  virtual bool getAsBool(const char *objectFullPath, cConfigOption *option, bool fallbackValue=false) const;
215 
220  virtual long getAsInt(const char *objectFullPath, cConfigOption *option, long fallbackValue=0) const;
221 
226  virtual double getAsDouble(const char *objectFullPath, cConfigOption *option, double fallbackValue=0) const;
227 
232  virtual std::string getAsString(const char *objectFullPath, cConfigOption *option, const char *fallbackValue="") const;
233 
239  virtual std::string getAsFilename(const char *objectFullPath, cConfigOption *option) const;
240 
247  virtual std::vector<std::string> getAsFilenames(const char *objectFullPath, cConfigOption *option) const;
248 
255  virtual std::string getAsPath(const char *objectFullPath, cConfigOption *option) const;
257 
264  virtual const char *substituteVariables(const char *value) const = 0;
266 };
267 
268 
282 class SIM_API cConfigurationEx : public cConfiguration
283 {
284  public:
293  virtual void initializeFrom(cConfiguration *bootConfig) = 0;
294 
299  virtual const char *getFileName() const = 0;
300 
313  virtual void validate(const char *ignorableConfigKeys=nullptr) const = 0;
314 
320  virtual std::vector<std::string> getConfigNames() = 0;
321 
327  virtual void activateConfig(const char *configName, int runNumber=0) = 0;
328 
332  virtual std::string getConfigDescription(const char *configName) const = 0;
333 
341  virtual std::vector<std::string> getBaseConfigs(const char *configName) const = 0;
342 
348  virtual std::vector<std::string> getConfigChain(const char * configName) const = 0;
349 
355  virtual int getNumRunsInConfig(const char *configName) const = 0;
356 
366  virtual std::vector<RunInfo> unrollConfig(const char *configName) const = 0;
367 
371  virtual const char *getActiveConfigName() const = 0;
372 
377  virtual int getActiveRunNumber() const = 0;
378 
390  virtual const char *getVariable(const char *varname) const = 0;
391 
395  virtual std::vector<const char *> getIterationVariableNames() const = 0;
396 
401  virtual std::vector<const char *> getPredefinedVariableNames() const = 0;
402 
407  virtual const char *getVariableDescription(const char *varname) const = 0;
408 
412  virtual void dump() const = 0;
414 
417 
422  virtual std::vector<const char *> getMatchingConfigKeys(const char *pattern) const = 0;
423 
430  virtual const char *getParameterValue(const char *moduleFullPath, const char *paramName, bool hasDefaultValue) const = 0;
431 
442  virtual const KeyValue& getParameterEntry(const char *moduleFullPath, const char *paramName, bool hasDefaultValue) const = 0;
443 
449  virtual std::vector<const char *> getKeyValuePairs() const = 0;
450 
457  virtual std::vector<const char *> getParameterKeyValuePairs() const = 0;
458 
466  virtual std::vector<const char *> getMatchingPerObjectConfigKeys(const char *objectFullPath, const char *keySuffixPattern) const = 0;
467 
473  virtual std::vector<const char *> getMatchingPerObjectConfigKeySuffixes(const char *objectFullPath, const char *keySuffixPattern) const = 0;
475 };
476 
477 } // namespace omnetpp
478 
479 #endif
480 
481 
Root of the OMNeT++ class hierarchy. cObject is a lightweight class without any data members...
Definition: cobject.h:58
Describes a configuration entry.
Definition: cconfiguration.h:76
Represents a configuration suitable for use with the Envir library.
Definition: cconfiguration.h:282
Describes a configuration option.
Definition: cconfigoption.h:34
Definition: cabstracthistogram.h:21
Struct used by unrollConfig() to return information.
Definition: cconfiguration.h:87
Represents the configuration, as accessed by the simulation kernel.
Definition: cconfiguration.h:70