Statistics
| Branch: | Revision:

root / include / cconfigoption.h @ master

History | View | Annotate | Download (3.27 KB)

1 01873262 Georg Kunz
//==========================================================================
2
//  CCONFIGOPTION.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 __CCONFIGOPTION_H
17
#define __CCONFIGOPTION_H
18
19
#include <string>
20
#include "cownedobject.h"
21
22
NAMESPACE_BEGIN
23
24
25
/**
26
 * Declares a configuration option.
27
 *
28
 * @ingroup Internals
29
 */
30
class SIM_API cConfigOption : public cNoncopyableOwnedObject
31
{
32
  public:
33
    /// Configuration option data types.
34
    enum Type {
35
      CFG_BOOL,
36
      CFG_INT,
37
      CFG_DOUBLE,
38
      CFG_STRING,
39
      CFG_FILENAME,
40
      CFG_FILENAMES,
41
      CFG_PATH,
42
      CFG_CUSTOM
43
    };
44
45
    // note: option name (e.g. "sim-time-limit") is stored in object's name field
46
    bool isPerObject_;         // if true, entries must be in <object-full-path>.config-name format
47
    bool isGlobal_;            // if true, entries may only occur in the [General] section
48
    Type type_;                // option data type
49
    std::string unit_;         // if numeric, its unit ("s") or empty string
50
    std::string defaultValue_; // the default value in string form
51
    std::string description_;  // help text
52
53
  public:
54
    /** @name Constructors, destructor */
55
    //@{
56
    /**
57
     * Constructor.
58
     */
59
    cConfigOption(const char *name, bool isPerObject, bool isGlobal, Type type, const char *unit,
60
               const char *defaultValue, const char *description);
61
    //@}
62
63
    /** @name Redefined cObject methods */
64
    //@{
65
    virtual std::string info() const;
66
    //@}
67
68
    /** @name Getter methods */
69
    //@{
70
    /**
71
     * Returns whether this is a per-object configuration. Per-object
72
     * configuration entries take the form of
73
     * \<object-full-path\>.\<configname\> = \<value\> in the inifile,
74
     * instead of \<configname\> = \<value\>
75
     */
76
    bool isPerObject() const {return isPerObject_;}
77
78
    /**
79
     * Returns whether this is a global setting. Global settings may only
80
     * occur in the [General] section.
81
     */
82
    bool isGlobal() const  {return isGlobal_;}
83
84
    /**
85
     * Data type of the option.
86
     */
87
    Type getType() const  {return type_;}
88
89
    /**
90
     * Returns the human-readable name of an option data type.
91
     */
92
    static const char *getTypeName(Type type);
93
94
    /**
95
     * Returns the unit of the option (e.g. "s" for seconds, "b" for bytes, etc),
96
     * or NULL if the option does not have a unit.
97
     */
98
    const char *getUnit() const  {return unit_.empty() ? NULL : unit_.c_str();}
99
100
    /**
101
     * Returns the default value in string form, or NULL if there is no default.
102
     */
103
    const char *getDefaultValue() const  {return defaultValue_.empty() ? NULL : defaultValue_.c_str();}
104
105
    /**
106
     * Returns a brief textual description of the option, which can be used as
107
     * help text or hint.
108
     */
109
    const char *getDescription() const  {return description_.c_str();}
110
    //@}
111
};
112
113
NAMESPACE_END
114
115
116
#endif
117