cConfiguration Class Reference
[Extension interface to Envir]

#include <cconfig.h>

Inheritance diagram for cConfiguration:

cPolymorphic List of all members.

Detailed Description

Abstract base class for representing the configuration (omnetpp.ini).

This class logically belongs to the cEnvir facade. (cEnvir presents to the simulation kernel the UI, or generally, the program which embeds the simulation.) This class provides access to configuration data for components such as scheduler classes, parallel simulation algorithms, etc. Model code (simple modules) should not directly read the configuration -- they should rely on module parameters for input.

This is an abstract base class, which means functionality is provided by subclasses. The subclass used by default is cInifile which reads config files in the omnetpp.ini format. One can create other subclasses which use different data sources (e.g. database) or different data format (e.g. XML).

To switch to your own configuration storage (e.g. database or XML files) from omnetpp.ini, subclass cConfiguration, register your new class with the Register_Class() macro, then create the following omnetpp.ini:

 [General]
 configuration-class="MyClass"
 

OMNeT++ will get the rest of the configuration from your configuration class.

See also: cEnvir::config()


Public Member Functions

virtual ~cConfiguration ()
virtual void initializeFrom (cConfiguration *conf)=0
virtual const char * fileName () const =0
Sections
virtual int getNumSections ()=0
virtual const char * getSectionName (int k)=0
Checking for presence of config entries
virtual bool exists (const char *section, const char *key)=0
virtual bool exists2 (const char *section1, const char *section2, const char *key)=0
virtual bool notFound ()=0
Getter methods
virtual bool getAsBool (const char *section, const char *key, bool defaultvalue=false)=0
virtual long getAsInt (const char *section, const char *key, long defaultvalue=0)=0
virtual double getAsDouble (const char *section, const char *key, double defaultvalue=0.0)=0
virtual double getAsTime (const char *sect, const char *key, double defaultvalue=0.0)=0
virtual const char * getAsString (const char *section, const char *key, const char *defaultvalue="")=0
virtual std::string getAsFilename (const char *section, const char *key, const char *defaultvalue="")=0
virtual std::string getAsFilenames (const char *section, const char *key, const char *defaultvalue="")=0
virtual const char * getAsCustom (const char *section, const char *key, const char *defaultvalue=NULL)=0
virtual const char * getBaseDirectoryFor (const char *section, const char *key)=0
virtual std::string getLocation (const char *section, const char *key)=0
Getter methods, with fallback to another section
virtual bool getAsBool2 (const char *section1, const char *section2, const char *key, bool defaultvalue=false)=0
virtual long getAsInt2 (const char *section1, const char *section2, const char *key, long defaultvalue=0)=0
virtual double getAsDouble2 (const char *section1, const char *section2, const char *key, double defaultvalue=0.0)=0
virtual double getAsTime2 (const char *section1, const char *section2, const char *key, double defaultvalue=0.0)=0
virtual const char * getAsString2 (const char *section1, const char *section2, const char *key, const char *defaultvalue="")=0
virtual std::string getAsFilename2 (const char *section1, const char *section2, const char *key, const char *defaultvalue="")=0
virtual std::string getAsFilenames2 (const char *section1, const char *section2, const char *key, const char *defaultvalue="")=0
virtual const char * getAsCustom2 (const char *section1, const char *section2, const char *key, const char *defaultvalue="")=0
virtual const char * getBaseDirectoryFor (const char *section1, const char *section2, const char *key)=0
virtual std::string getLocation (const char *section1, const char *section2, const char *key)=0
Special
virtual std::vector< opp_stringgetEntriesWithPrefix (const char *section, const char *keypart1, const char *keypart2)=0
virtual std::vector< opp_stringgetEntriesWithPrefix (const char *section1, const char *section2, const char *keypart1, const char *keypart2)=0


Constructor & Destructor Documentation

virtual cConfiguration::~cConfiguration  )  [inline, virtual]
 

Virtual destructor.


Member Function Documentation

virtual bool cConfiguration::exists const char *  section,
const char *  key
[pure virtual]
 

Returns true if the configuration contains an entry in the given section that matches the given key.

virtual bool cConfiguration::exists2 const char *  section1,
const char *  section2,
const char *  key
[pure virtual]
 

Like exists(), with fallback to another section.

virtual const char* cConfiguration::fileName  )  const [pure virtual]
 

Returns the name of the configuration file.

Returns NULL if this object is using a configuration file.

virtual bool cConfiguration::getAsBool const char *  section,
const char *  key,
bool  defaultvalue = false
[pure virtual]
 

Returns a config value as bool.

virtual bool cConfiguration::getAsBool2 const char *  section1,
const char *  section2,
const char *  key,
bool  defaultvalue = false
[pure virtual]
 

Returns a config value as bool.

virtual const char* cConfiguration::getAsCustom const char *  section,
const char *  key,
const char *  defaultvalue = NULL
[pure virtual]
 

Returns a config entry's "raw" (unparsed) value.

virtual const char* cConfiguration::getAsCustom2 const char *  section1,
const char *  section2,
const char *  key,
const char *  defaultvalue = ""
[pure virtual]
 

Returns a config entry's "raw" (unparsed) value.

virtual double cConfiguration::getAsDouble const char *  section,
const char *  key,
double  defaultvalue = 0.0
[pure virtual]
 

Returns a config value as double.

virtual double cConfiguration::getAsDouble2 const char *  section1,
const char *  section2,
const char *  key,
double  defaultvalue = 0.0
[pure virtual]
 

Returns a config value as double.

virtual std::string cConfiguration::getAsFilename const char *  section,
const char *  key,
const char *  defaultvalue = ""
[pure virtual]
 

Interprets the config value as a path.

If it is relative, then it will be converted to an absolute path, using the base directory (see the getBaseDirectoryFor() method).

virtual std::string cConfiguration::getAsFilename2 const char *  section1,
const char *  section2,
const char *  key,
const char *  defaultvalue = ""
[pure virtual]
 

Returns getAsFilename(section1, key) or getAsFilename(section2, key), depending where the given entry was found.

virtual std::string cConfiguration::getAsFilenames const char *  section,
const char *  key,
const char *  defaultvalue = ""
[pure virtual]
 

Interprets the config value as a list of paths (file or directory names, possibly containing wildcards), separated by spaces.

The relative paths in the list will be converted to absolute, using the base directory (see getBaseDirectoryFor() method). If the base directory name contains spaces, the path will be surrounded with quotes.

virtual std::string cConfiguration::getAsFilenames2 const char *  section1,
const char *  section2,
const char *  key,
const char *  defaultvalue = ""
[pure virtual]
 

Returns getAsFilenames(section1, key) or getAsFilenames(section2, key), depending where the given entry was found.

virtual long cConfiguration::getAsInt const char *  section,
const char *  key,
long  defaultvalue = 0
[pure virtual]
 

Returns a config value as long.

virtual long cConfiguration::getAsInt2 const char *  section1,
const char *  section2,
const char *  key,
long  defaultvalue = 0
[pure virtual]
 

Returns a config value as long.

virtual const char* cConfiguration::getAsString const char *  section,
const char *  key,
const char *  defaultvalue = ""
[pure virtual]
 

Returns a config value as string.

virtual const char* cConfiguration::getAsString2 const char *  section1,
const char *  section2,
const char *  key,
const char *  defaultvalue = ""
[pure virtual]
 

Returns a config value as string.

virtual double cConfiguration::getAsTime const char *  sect,
const char *  key,
double  defaultvalue = 0.0
[pure virtual]
 

Returns a config value as time.

virtual double cConfiguration::getAsTime2 const char *  section1,
const char *  section2,
const char *  key,
double  defaultvalue = 0.0
[pure virtual]
 

Returns a config value as time.

virtual const char* cConfiguration::getBaseDirectoryFor const char *  section1,
const char *  section2,
const char *  key
[pure virtual]
 

Returns getBaseDirectoryFor(section1, key) or getBaseDirectoryFor(section2, key), depending where the given entry was found.

virtual const char* cConfiguration::getBaseDirectoryFor const char *  section,
const char *  key
[pure virtual]
 

Returns the base directory, to which the entry's value -- if it is a string to be interpreted as a file name -- should be understood as relative.

This method in the cInifile class returns the location of the ini file in which the given entry occurred. Other cConfiguration implementations may return "." to mean the current working directory. For example, this function is used by the preload-ned-files= ini file entry to ensure that files are loaded from the correct place.

virtual std::vector<opp_string> cConfiguration::getEntriesWithPrefix const char *  section1,
const char *  section2,
const char *  keypart1,
const char *  keypart2
[pure virtual]
 

getEntriesWithPrefix(), with fallback to another section.

virtual std::vector<opp_string> cConfiguration::getEntriesWithPrefix const char *  section,
const char *  keypart1,
const char *  keypart2
[pure virtual]
 

Returns a collection of entries together with their values.

Entry names must match keypart1 + keypart2 + some suffix. Pairs of "some suffix" and their matching values are returned.

Example: The config contains:

   [General]
   net.host1.gen.rng-0 = value1
   net.host1.gen.rng-2 = value2
   net.host1.gen.rng-5 = value3
 

getEntriesWithPrefix("General", "net.host1.gen", ".rng-") returns this:

  • "0" --> value1
  • "2" --> value2
  • "5" --> value3

Returned array contains "0", "2", "5" at odd indices, and value1, value2, value3 at even indices.

virtual std::string cConfiguration::getLocation const char *  section1,
const char *  section2,
const char *  key
[pure virtual]
 

Returns getLocation(section1, key) or getLocation(section2, key), depending where the given entry was found.

virtual std::string cConfiguration::getLocation const char *  section,
const char *  key
[pure virtual]
 

Returns the location from which this entry was read (e.g.

name of the ini file). This can be useful for debugging; it is not used by the system for any other purpose.

virtual int cConfiguration::getNumSections  )  [pure virtual]
 

Returns the number of sections available in configuration.

virtual const char* cConfiguration::getSectionName int  k  )  [pure virtual]
 

Returns the name of section k.

0<=k<getNumSections().

virtual void cConfiguration::initializeFrom cConfiguration conf  )  [pure virtual]
 

Initializes configuration object from "boot-time" configuration (omnetpp.ini).

For example, if a particular cConfiguration subclass uses a database as data source, it may take the connection parameters from the "boot-time" configuration.

virtual bool cConfiguration::notFound  )  [pure virtual]
 

Returns true if the last "get" call didn't find the configuration entry and returned the default value.


The documentation for this class was generated from the following file:
Generated on Sat Oct 21 17:47:56 2006 for OMNeT++/OMNEST Simulation Library by  doxygen 1.4.6