OMNeT++ NEDXML 6.2.0
Discrete Event Simulation Library
nedtypeinfo.h
Go to the documentation of this file.
1 //==========================================================================
2 // NEDTYPEINFO.H -
3 //
4 // OMNeT++/OMNEST
5 // Discrete System Simulation in C++
6 //
7 //==========================================================================
8 
9 /*--------------------------------------------------------------*
10  Copyright (C) 2002-2017 Andras Varga
11  Copyright (C) 2006-2017 OpenSim Ltd.
12 
13  This file is distributed WITHOUT ANY WARRANTY. See the file
14  `license' for details on this and other legal matters.
15 *--------------------------------------------------------------*/
16 
17 
18 #ifndef __OMNETPP_NEDXML_NEDTYPEINFO_H
19 #define __OMNETPP_NEDXML_NEDTYPEINFO_H
20 
21 #include <map>
22 #include <vector>
23 #include <string>
24 #include <optional>
25 #include "common/commonutil.h"
26 #include "nedelements.h"
27 
28 namespace omnetpp {
29 namespace nedxml {
30 
31 class NedResourceCache;
32 
45 {
46  public:
47  enum Type {SIMPLE_MODULE, COMPOUND_MODULE, MODULEINTERFACE, CHANNEL, CHANNELINTERFACE};
48 
49  protected:
50  // the resolver this type is in
52 
54  std::string qualifiedName;
55  bool isInner; // whether it is an inner type
56  ASTNode *tree; // points into resolver
57 
58  bool resolved = false;
59  bool resolving = false;
60 
61  // Important: The fields below are only filled in when the "resolved" flag is true.
62 
63  typedef std::vector<std::string> StringVector;
64  typedef std::map<std::string,ASTNode*> NameToElementMap;
65 
66  // inheritance. Vectors contain fully qualifies names, and include
67  // indirect base types/interfaces as well (transitive closure).
70 
71  std::string enclosingTypeName;
72 
73  // simple module/channel C++ class to instantiate
74  std::string implClassName;
75  // cached return value of getDocumentation
76  mutable std::optional<std::string> documentation;
77 
78  // local declarations by name
85 
86  protected:
87  void checkComplianceToInterface(NedTypeInfo *interfaceDecl);
88  void collectLocalDeclarations();
89  void addToElementMap(NameToElementMap& elementMap, ASTNode *node);
90  void mergeElementMap(NameToElementMap& destMap, const NameToElementMap& elementMap);
91  void resolveIfNeeded() const {if (!isResolved()) const_cast<NedTypeInfo*>(this)->resolve(); /*ouch*/}
92 
93  public:
95  NedTypeInfo(NedResourceCache *resolver, const char *qname, bool isInnerType, ASTNode *tree);
96 
98  virtual ~NedTypeInfo();
99 
101  virtual const char *getName() const;
102 
104  virtual const char *getFullName() const;
105 
107  virtual ASTNode *getTree() const;
108 
110  NedResourceCache *getResolver() const {return resolver;}
111 
116  virtual Type getType() const {return type;}
117 
122  virtual bool isNetwork() const;
123 
127  virtual const char *getSourceFileName() const;
128 
133  virtual std::string getPackage() const;
134 
138  virtual bool isInnerType() const {return isInner;}
139 
144  virtual const char *getEnclosingTypeName() const;
145 
149  virtual std::string str() const;
150 
154  virtual std::string getNedSource() const;
155 
159  virtual std::string getDocumentation() const;
160 
164  virtual bool isResolved() const {return resolved;}
165 
173  virtual void resolve();
174 
180  virtual int numExtendsNames() const {resolveIfNeeded(); return extendsNames.size();}
181 
187  virtual const char *getExtendsName(int k) const;
188 
196  virtual int numInterfaceNames() const {resolveIfNeeded(); return interfaceNames.size();}
197 
203  virtual const char *getInterfaceName(int k) const;
204 
210  virtual bool supportsInterface(const char *qname);
211 
218  virtual const char *getImplementationClassName() const;
219 
228  virtual std::string getPackageProperty(const char *name) const;
229 
234  virtual std::string getCxxNamespace() const;
235 
240  virtual NedTypeInfo *getSuperDecl() const;
241 
244  TypesElement *getTypesElement() const;
245  ParametersElement *getParametersElement() const;
246  GatesElement *getGatesElement() const;
247  SubmodulesElement *getSubmodulesElement() const;
248  ConnectionsElement *getConnectionsElement() const;
249 
251  SubmoduleElement *getLocalSubmoduleElement(const char *submoduleName) const;
252 
254  ConnectionElement *getLocalConnectionElement(long id) const;
255 
257  SubmoduleElement *getSubmoduleElement(const char *submoduleName) const;
258 
260  ConnectionElement *getConnectionElement(long id) const;
261 
263  ParamElement *findLocalParamDecl(const char *name) const;
264 
266  ParamElement *findParamDecl(const char *name) const;
267 
269  GateElement *findLocalGateDecl(const char *name) const;
270 
272  GateElement *findGateDecl(const char *name) const;
274 };
275 
276 } // namespace nedxml
277 } // namespace omnetpp
278 
279 
280 #endif
281 
omnetpp::nedxml::NedTypeInfo::localSubmoduleDecls
NameToElementMap localSubmoduleDecls
Definition: nedtypeinfo.h:82
omnetpp::nedxml::NedResourceCache
Stores loaded NED files, and keeps track of components in them.
Definition: nedresourcecache.h:52
omnetpp::nedxml::NedTypeInfo::localConnectionDecls
NameToElementMap localConnectionDecls
Definition: nedtypeinfo.h:83
omnetpp::nedxml::NedTypeInfo::localParamDecls
NameToElementMap localParamDecls
Definition: nedtypeinfo.h:80
omnetpp::nedxml::NedTypeInfo::Type
Type
Definition: nedtypeinfo.h:47
omnetpp::nedxml::NedTypeInfo::interfaceNames
StringVector interfaceNames
Definition: nedtypeinfo.h:69
omnetpp::nedxml::NedTypeInfo::getResolver
NedResourceCache * getResolver() const
Definition: nedtypeinfo.h:110
omnetpp::nedxml::NedTypeInfo::implClassName
std::string implClassName
Definition: nedtypeinfo.h:74
NEDXML_API
#define NEDXML_API
Definition: nedxmldefs.h:31
omnetpp::nedxml::NedTypeInfo::tree
ASTNode * tree
Definition: nedtypeinfo.h:56
omnetpp::nedxml::NedTypeInfo::numInterfaceNames
virtual int numInterfaceNames() const
Definition: nedtypeinfo.h:196
omnetpp
Definition: astbuilder.h:25
omnetpp::nedxml::NedTypeInfo::StringVector
std::vector< std::string > StringVector
Definition: nedtypeinfo.h:63
omnetpp::nedxml::NedTypeInfo::numExtendsNames
virtual int numExtendsNames() const
Definition: nedtypeinfo.h:180
omnetpp::nedxml::NedTypeInfo::resolver
NedResourceCache * resolver
Definition: nedtypeinfo.h:51
omnetpp::nedxml::NedTypeInfo::documentation
std::optional< std::string > documentation
Definition: nedtypeinfo.h:76
omnetpp::nedxml::NedTypeInfo::localGateDecls
NameToElementMap localGateDecls
Definition: nedtypeinfo.h:81
omnetpp::nedxml::NedTypeInfo
Stores information on a NED type.
Definition: nedtypeinfo.h:44
omnetpp::nedxml::ASTNode
Definition: astnode.h:87
omnetpp::nedxml::NedTypeInfo::getType
virtual Type getType() const
Definition: nedtypeinfo.h:116
omnetpp::nedxml::NedTypeInfo::extendsNames
StringVector extendsNames
Definition: nedtypeinfo.h:68
omnetpp::nedxml::NedTypeInfo::NameToElementMap
std::map< std::string, ASTNode * > NameToElementMap
Definition: nedtypeinfo.h:64
omnetpp::nedxml::NedTypeInfo::isResolved
virtual bool isResolved() const
Definition: nedtypeinfo.h:164
omnetpp::nedxml::NedTypeInfo::allLocalDecls
NameToElementMap allLocalDecls
Definition: nedtypeinfo.h:84
omnetpp::nedxml::NedTypeInfo::type
Type type
Definition: nedtypeinfo.h:53
omnetpp::nedxml::NedTypeInfo::localInnerTypeDecls
NameToElementMap localInnerTypeDecls
Definition: nedtypeinfo.h:79
omnetpp::nedxml::NedTypeInfo::qualifiedName
std::string qualifiedName
Definition: nedtypeinfo.h:54
omnetpp::nedxml::NedTypeInfo::enclosingTypeName
std::string enclosingTypeName
Definition: nedtypeinfo.h:71
omnetpp::nedxml::NedTypeInfo::isInnerType
virtual bool isInnerType() const
Definition: nedtypeinfo.h:138
omnetpp::nedxml::NedTypeInfo::isInner
bool isInner
Definition: nedtypeinfo.h:55
omnetpp::nedxml::NedTypeInfo::resolveIfNeeded
void resolveIfNeeded() const
Definition: nedtypeinfo.h:91