OMNeT++ Simulation Library  5.6.1
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 
24 
34 class SIM_API cConfigOption : public cNoncopyableOwnedObject
35 {
36  public:
38  enum Type {
39  CFG_BOOL,
40  CFG_INT,
41  CFG_DOUBLE,
42  CFG_STRING,
43  CFG_FILENAME,
44  CFG_FILENAMES,
45  CFG_PATH,
46  CFG_CUSTOM
47  };
48 
50  enum ObjectKind {
51  KIND_NONE,
52  KIND_COMPONENT,
53  KIND_CHANNEL,
54  KIND_MODULE,
55  KIND_SIMPLE_MODULE,
56  KIND_UNSPECIFIED_TYPE, // for 'typename' option (object is submodule/channel declared with 'like')
57  KIND_PARAMETER,
58  KIND_STATISTIC,
59  KIND_SCALAR,
60  KIND_VECTOR,
61  KIND_OTHER
62  };
63 
64  // note: option name (e.g. "sim-time-limit") is stored in object's name field
65  bool isPerObject_; // if true, entries must be in <object-full-path>.config-name format
66  bool isGlobal_; // if true, entries may only occur in the [General] section
67  ObjectKind objectKind; // kind of the object if isPerObject is true, KIND_NONE otherwise
68  Type type; // option data type
69  std::string unit; // if numeric, its unit ("s") or empty string
70  std::string defaultValue; // the default value in string form
71  std::string description; // help text
72 
73  public:
79  cConfigOption(const char *name, bool isGlobal, Type type, const char *unit,
80  const char *defaultValue, const char *description);
81 
85  cConfigOption(const char *name, ObjectKind kind, Type type, const char *unit,
86  const char *defaultValue, const char *description);
88 
91  virtual std::string str() const override;
93 
102  bool isPerObject() const {return isPerObject_;}
103 
108  bool isGlobal() const {return isGlobal_;}
109 
114  ObjectKind getObjectKind() const {return objectKind;}
115 
119  static const char *getObjectKindName(ObjectKind kind);
120 
124  Type getType() const {return type;}
125 
129  static const char *getTypeName(Type type);
130 
135  const char *getUnit() const {return unit.empty() ? nullptr : unit.c_str();}
136 
140  const char *getDefaultValue() const {return defaultValue.empty() ? nullptr : defaultValue.c_str();}
141 
146  const char *getDescription() const {return description.c_str();}
148 
154  static cConfigOption *find(const char *name);
155 
159  static cConfigOption *get(const char *name);
161 };
162 
163 } // namespace omnetpp
164 
165 
166 #endif
167 
168 
bool isPerObject() const
Definition: cconfigoption.h:102
const char * getDefaultValue() const
Definition: cconfigoption.h:140
Type
Configuration option data types.
Definition: cconfigoption.h:38
ObjectKind getObjectKind() const
Definition: cconfigoption.h:114
const char * getDescription() const
Definition: cconfigoption.h:146
bool isGlobal() const
Definition: cconfigoption.h:108
Describes a configuration option.
Definition: cconfigoption.h:34
Definition: cabstracthistogram.h:21
Base class for cOwnedObject-based classes that do not wish to support assignment and duplication...
Definition: cownedobject.h:248
ObjectKind
Configuration option kinds.
Definition: cconfigoption.h:50
const char * getUnit() const
Definition: cconfigoption.h:135
Type getType() const
Definition: cconfigoption.h:124