Statistics
| Branch: | Revision:

root / include / cconfigreader.h @ ffa9279f

History | View | Annotate | Download (3.41 KB)

1
//==========================================================================
2
//  CCONFIGREADER.H - part of
3
//                     OMNeT++/OMNEST
4
//            Discrete System Simulation in C++
5
//
6
//==========================================================================
7

    
8
/*--------------------------------------------------------------*
9
  Copyright (C) 1992-2008 Andras Varga
10
  Copyright (C) 2006-2008 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 __CCONFIGREADER_H
17
#define __CCONFIGREADER_H
18

    
19
#include "simkerneldefs.h"
20

    
21
class cConfiguration;
22

    
23
/**
24
 * Abstract base class for configuration readers for SectionBasedConfiguration.
25
 * This class presents configuration contents as key-value pairs grouped
26
 * into sections. This class does not try to make sense of section/key names.
27
 *
28
 * The default implementation is InifileReader, but other variants (e.g. those
29
 * that read the configuration from a database) can also be implemented.
30
 */
31
class cConfigurationReader
32
{
33
  public:
34
    /**
35
     * Abstract base class for representing a key-value pair in the configuration.
36
     */
37
    class KeyValue {
38
      public:
39
        virtual ~KeyValue() {}
40
        virtual const char *getKey() const = 0;
41
        virtual const char *getValue() const = 0;
42
        virtual const char *getBaseDirectory() const = 0;
43
        virtual const char *getFileName() const = 0;
44
        virtual int getLineNumber() const = 0;
45
    };
46

    
47
  public:
48
    /**
49
     * Virtual destructor
50
     */
51
    virtual ~cConfigurationReader() {}
52

    
53
    /**
54
     * Initializes the object from a "boot-time" configuration (omnetpp.ini).
55
     * For example, if a particular cConfigurationReader class uses a database
56
     * as data source, it may take the connection parameters from the
57
     * "boot-time" configuration.
58
     */
59
    virtual void initializeFrom(cConfiguration *bootConfig) = 0;
60

    
61
    /**
62
     * Returns the name of the configuration file. Returns NULL if this object is
63
     * not using a configuration file.
64
     */
65
    virtual const char *getFileName() const = 0;
66

    
67
    /**
68
     * Returns the directory defaulted filenames should be understood to be
69
     * relative to. For example, if the name of the output vector file is
70
     * not explicitly configured, it defaults to "omnetpp.vec" in the
71
     * default base directory.
72
     */
73
    virtual const char *getDefaultBaseDirectory() const = 0;
74

    
75
    /**
76
     * Returns the number of sections in the configuration.
77
     */
78
    virtual int getNumSections() const = 0;
79

    
80
    /**
81
     * Returns the name of the given section. sectionId should be in
82
     * 0..getNumSections()-1.
83
     */
84
    virtual const char *getSectionName(int sectionId) const = 0;
85

    
86
    /**
87
     * Returns the number of entries in the given section. sectionId should be
88
     * in 0..getNumSections()-1.
89
     */
90
    virtual int getNumEntries(int sectionId) const = 0;
91

    
92
    /**
93
     * Returns the given entry in the in the given section. sectionId should be
94
     * in 0..getNumSections()-1. The lifetime of the returned entry may be
95
     * limited, so references to entries should not be cached.
96
     */
97
    virtual const KeyValue& getEntry(int sectionId, int entryId) const = 0;
98

    
99
    /**
100
     * Prints the configuration to the standard output. This can be useful
101
     * for tracking down problems.
102
     */
103
    virtual void dump() const = 0;
104
};
105

    
106
#endif
107

    
108