OMNeT++ API 6.1
Discrete Event Simulation Library
cconfigoption.h
1 //==========================================================================
2 // CCONFIGOPTION.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_CCONFIGOPTION_H
17 #define __OMNETPP_CCONFIGOPTION_H
18 
19 #include <string>
20 #include "cownedobject.h"
21 
22 namespace omnetpp {
23 
33 class SIM_API cConfigOption : public cNoncopyableOwnedObject
34 {
35  public:
37  enum Type {
38  CFG_BOOL,
39  CFG_INT,
40  CFG_DOUBLE,
41  CFG_STRING,
42  CFG_FILENAME,
43  CFG_FILENAMES,
44  CFG_PATH,
45  CFG_CUSTOM
46  };
47 
49  enum ObjectKind {
50  KIND_NONE,
51  KIND_COMPONENT,
52  KIND_CHANNEL,
53  KIND_MODULE,
54  KIND_SIMPLE_MODULE,
55  KIND_UNSPECIFIED_TYPE, // for 'typename' option (object is submodule/channel declared with 'like')
56  KIND_PARAMETER,
57  KIND_STATISTIC,
58  KIND_SCALAR,
59  KIND_VECTOR,
60  KIND_OTHER
61  };
62 
63  // note: option name (e.g. "sim-time-limit") is stored in object's name field
64  bool isPerObject_; // if true, entries must be in <object-full-path>.config-name format
65  bool isGlobal_; // if true, entries may only occur in the [General] section
66  ObjectKind objectKind; // kind of the object if isPerObject is true, KIND_NONE otherwise
67  Type type; // option data type
68  std::string unit; // if numeric, its unit ("s") or empty string
69  std::string defaultValue; // the default value in string form
70  std::string description; // help text
71 
72  public:
78  cConfigOption(const char *name, bool isGlobal, Type type, const char *unit,
79  const char *defaultValue, const char *description);
80 
84  cConfigOption(const char *name, ObjectKind kind, Type type, const char *unit,
85  const char *defaultValue, const char *description);
87 
90  virtual std::string str() const override;
92 
101  bool isPerObject() const {return isPerObject_;}
102 
107  bool isGlobal() const {return isGlobal_;}
108 
113  ObjectKind getObjectKind() const {return objectKind;}
114 
118  static const char *getObjectKindName(ObjectKind kind);
119 
123  Type getType() const {return type;}
124 
128  static const char *getTypeName(Type type);
129 
134  const char *getUnit() const {return unit.empty() ? nullptr : unit.c_str();}
135 
139  const char *getDefaultValue() const {return defaultValue.empty() ? nullptr : defaultValue.c_str();}
140 
145  const char *getDescription() const {return description.c_str();}
147 
153  static cConfigOption *find(const char *name);
154 
158  static cConfigOption *get(const char *name);
160 };
161 
162 } // namespace omnetpp
163 
164 
165 #endif
166 
167 
omnetpp::cConfigOption::getDescription
const char * getDescription() const
Definition: cconfigoption.h:145
omnetpp::cConfigOption::getDefaultValue
const char * getDefaultValue() const
Definition: cconfigoption.h:139
omnetpp::cConfigOption::isPerObject
bool isPerObject() const
Definition: cconfigoption.h:101
omnetpp::cConfigOption::getObjectKind
ObjectKind getObjectKind() const
Definition: cconfigoption.h:113
omnetpp::cConfigOption::Type
Type
Configuration option data types.
Definition: cconfigoption.h:37
omnetpp::cConfigOption
Describes a configuration option.
Definition: cconfigoption.h:33
omnetpp::cConfigOption::isGlobal
bool isGlobal() const
Definition: cconfigoption.h:107
omnetpp::cConfigOption::getUnit
const char * getUnit() const
Definition: cconfigoption.h:134
omnetpp::cConfigOption::getType
Type getType() const
Definition: cconfigoption.h:123
omnetpp::cNoncopyableOwnedObject
Base class for cOwnedObject-based classes that do not wish to support assignment and duplication.
Definition: cownedobject.h:242
omnetpp::cConfigOption::ObjectKind
ObjectKind
Configuration option kinds.
Definition: cconfigoption.h:49