OMNeT++ Simulation Library  5.6.1
ccomponenttype.h
1 //==========================================================================
2 // CCOMPONENTTYPE.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_CCOMPONENTTYPE_H
17 #define __OMNETPP_CCOMPONENTTYPE_H
18 
19 #include <string>
20 #include <map>
21 #include <set>
22 #include "cpar.h"
23 #include "cgate.h"
24 #include "cownedobject.h"
25 #include "clistener.h"
26 
27 
28 namespace omnetpp {
29 
30 class cModule;
31 class cChannel;
32 class cProperty;
33 class cProperties;
34 class cIdealChannel;
35 class cDelayChannel;
36 class cDatarateChannel;
37 class cObjectFactory;
38 
39 
50 {
51  protected:
52  std::string qualifiedName;
53  bool availabilityTested;
54  bool available;
55 
56  typedef std::map<std::string, cParImpl *> StringToParMap;
57  StringToParMap sharedParMap;
58 
59  struct Less {bool operator()(cParImpl *a, cParImpl *b) const;};
60  typedef std::set<cParImpl *, Less> ParImplSet;
61  ParImplSet sharedParSet;
62 
63  struct SignalDesc { SimsignalType type; cObjectFactory *objectType; bool isNullable; };
64  std::map<simsignal_t,SignalDesc> signalsSeen;
65 
66  protected:
67  friend class cComponent;
68  friend class cModule;
69  friend class cChannel;
70  friend class cPar;
71  friend class cGate;
72 
73  // internal: returns the properties for this component.
74  virtual cProperties *getProperties() const = 0;
75 
76  // internal: returns the properties of parameter
77  virtual cProperties *getParamProperties(const char *paramName) const = 0;
78 
79  // internal: returns the properties of gate
80  virtual cProperties *getGateProperties(const char *gateName) const = 0;
81 
82  // internal: returns the properties of a submodule.
83  // (Subcomponent type is needed because with the NED "like" syntax,
84  // we need the runtime type not the NED type of the submodule.)
85  virtual cProperties *getSubmoduleProperties(const char *submoduleName, const char *submoduleType) const = 0;
86 
87  // internal: returns the properties of a contained connection.
88  // (Subcomponent type is needed because with the NED "like" syntax,
89  // we need the runtime type not the NED type of the submodule.)
90  virtual cProperties *getConnectionProperties(int connectionId, const char *channelType) const = 0;
91 
92  // internal: returns the name of the C++ class that implements this NED type
93  virtual const char *getImplementationClassName() const = 0;
94 
95  // internal: apply pattern-based ("deep") parameter settings in NED
96  virtual void applyPatternAssignments(cComponent *component) = 0;
97 
98  // internal: sharedParMap access
99  cParImpl *getSharedParImpl(const char *key) const;
100  void putSharedParImpl(const char *key, cParImpl *value);
101 
102  // internal: sharedParSet access
103  cParImpl *getSharedParImpl(cParImpl *p) const;
104  void putSharedParImpl(cParImpl *p);
105 
106  // internal: helper for checkSignal()
107  cObjectFactory *lookupClass(const char *className) const;
108 
109  public:
110  // internal: delegates to the similar NedTypeInfo method
111  virtual std::string getPackageProperty(const char *name) const {return "";}
112 
113  // internal: checks whether this type is available; currently tests the existence of the implementation class
114  virtual bool isAvailable();
115 
116  // internal: delegates to the similar NedTypeInfo method
117  virtual bool isInnerType() const {return false;}
118 
119  // internal: return the default C++ namespace at this NED type (for NED it's the @namespace package property)
120  virtual std::string getCxxNamespace() const {return "";}
121 
122  // internal: return the path of the source file this declaration has been loaded from, or nullptr if not available
123  virtual const char *getSourceFileName() const {return nullptr;}
124 
125  // internal: used by cComponent::emit() methods to validate signals
126  virtual void checkSignal(simsignal_t signalID, SimsignalType type, cObject *obj = nullptr);
127 
128  // internal: returns the @signal property for the given signal, or nullptr if not found
129  virtual cProperty *getSignalDeclaration(const char *signalName);
130 
131  public:
137  cComponentType(const char *qname=nullptr);
138 
142  virtual ~cComponentType();
144 
163  virtual const char *getFullName() const override {return qualifiedName.c_str();}
165 
169  virtual std::string getNedSource() const = 0;
170 
175  static cComponentType *find(const char *qname);
176 
181  static cComponentType *get(const char *qname);
182 };
183 
184 
192 class SIM_API cModuleType : public cComponentType
193 {
194  friend class cModule;
195  protected:
199  virtual cModule *createModuleObject() = 0;
200 
207  //TODO in 5.0, these methods should be internal (i.e. nor public API)
208  virtual void addParametersAndGatesTo(cModule *mod) = 0;
209 
216  virtual void setupGateVectors(cModule *mod) = 0;
217 
227  virtual void buildInside(cModule *mod) = 0;
228 
234  cModule *instantiateModuleClass(const char *classname);
235 
236  public:
242  cModuleType(const char *qname=nullptr);
244 
250  virtual bool isNetwork() const = 0;
251 
256  virtual bool isSimple() const = 0;
258 
261 
268  virtual cModule *create(const char *name, cModule *parentmod);
269 
275  virtual cModule *create(const char *name, cModule *parentmod, int vectorsize, int index);
276 
290  virtual cModule *createScheduleInit(const char *name, cModule *parentmod);
292 
297  static cModuleType *find(const char *qname);
298 
303  static cModuleType *get(const char *qname);
304 };
305 
306 
312 class SIM_API cChannelType : public cComponentType
313 {
314  protected:
315  static cChannelType *idealChannelType;
316  static cChannelType *delayChannelType;
317  static cChannelType *datarateChannelType;
318 
319  protected:
323  virtual cChannel *createChannelObject() = 0;
324 
329  virtual void addParametersTo(cChannel *channel) = 0;
330 
335  cChannel *instantiateChannelClass(const char *classname);
336 
337  public:
340 
344  cChannelType(const char *qname=nullptr);
345 
359  virtual cChannel *create(const char *name);
361 
366  static cChannelType *find(const char *qname);
367 
372  static cChannelType *get(const char *qname);
373 
378  static cChannelType *getIdealChannelType();
379 
384  static cChannelType *getDelayChannelType();
385 
390  static cChannelType *getDatarateChannelType();
391 
395  static cIdealChannel *createIdealChannel(const char *name);
396 
400  static cDelayChannel *createDelayChannel(const char *name);
401 
405  static cDatarateChannel *createDatarateChannel(const char *name);
406 };
407 
408 } // namespace omnetpp
409 
410 
411 #endif
412 
413 
Common base for module and channel classes.
Definition: ccomponent.h:48
Represents a module gate.
Definition: cgate.h:63
Root of the OMNeT++ class hierarchy. cObject is a lightweight class without any data members...
Definition: cobject.h:58
Channel with propagation delay.
Definition: cdelaychannel.h:29
Channel with zero propagation delay, zero transmission delay (infinite datarate), and always enabled...
Definition: cchannel.h:327
Represents a module or channel parameter.
Definition: cpar.h:68
This class represents modules in the simulation.
Definition: cmodule.h:47
Stores a (NED) property with its (possibly compound) value.
Definition: cproperty.h:38
The class behind the createOne() function and the Register_Class() macro.
Definition: cobjectfactory.h:35
Common base class for cModuleType and cChannelType.
Definition: ccomponenttype.h:49
Definition: cabstracthistogram.h:21
A collection of properties (cProperty).
Definition: cproperties.h:34
SimsignalType
Signal data types.
Definition: clistener.h:44
Base class for cOwnedObject-based classes that do not wish to support assignment and duplication...
Definition: cownedobject.h:248
virtual const char * getFullName() const override
Definition: ccomponenttype.h:163
Abstract base class for creating a channel of a given type.
Definition: ccomponenttype.h:312
Abstract class for creating a module of a specific type.
Definition: ccomponenttype.h:192
int simsignal_t
Signal handle.
Definition: clistener.h:24
Base class for channels.
Definition: cchannel.h:34
Channel that models delay, bit error rate and data rate.
Definition: cdataratechannel.h:30
Internal class that stores values for cPar objects.
Definition: cparimpl.h:44