nedtypeinfo.h Source File

NEDXML API: nedtypeinfo.h Source File
NEDXML API
nedtypeinfo.h
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
28namespace omnetpp {
29namespace nedxml {
30
32
44class NEDXML_API NedTypeInfo
45{
46 public:
47 enum Type {SIMPLE_MODULE, COMPOUND_MODULE, MODULEINTERFACE, CHANNEL, CHANNELINTERFACE};
48
49 protected:
50 // the resolver this type is in
51 NedResourceCache *resolver;
52
53 Type type;
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).
68 StringVector extendsNames;
69 StringVector interfaceNames;
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
79 NameToElementMap localInnerTypeDecls;
80 NameToElementMap localParamDecls;
81 NameToElementMap localGateDecls;
82 NameToElementMap localSubmoduleDecls;
83 NameToElementMap localConnectionDecls;
84 NameToElementMap allLocalDecls;
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
Definition astnode.h:88
Stores loaded NED files, and keeps track of components in them.
Definition nedresourcecache.h:53
virtual const char * getFullName() const
virtual const char * getExtendsName(int k) const
ParamElement * findParamDecl(const char *name) const
GateElement * findLocalGateDecl(const char *name) const
ParamElement * findLocalParamDecl(const char *name) const
virtual ASTNode * getTree() const
virtual bool supportsInterface(const char *qname)
virtual bool isResolved() const
Definition nedtypeinfo.h:164
NedTypeInfo(NedResourceCache *resolver, const char *qname, bool isInnerType, ASTNode *tree)
virtual NedTypeInfo * getSuperDecl() const
virtual std::string getPackageProperty(const char *name) const
virtual const char * getImplementationClassName() const
virtual const char * getName() const
virtual bool isNetwork() const
virtual const char * getEnclosingTypeName() const
SubmoduleElement * getLocalSubmoduleElement(const char *submoduleName) const
virtual std::string getCxxNamespace() const
virtual std::string str() const
virtual const char * getInterfaceName(int k) const
virtual const char * getSourceFileName() const
ConnectionElement * getConnectionElement(long id) const
virtual std::string getNedSource() const
virtual std::string getDocumentation() const
NedResourceCache * getResolver() const
Definition nedtypeinfo.h:110
SubmoduleElement * getSubmoduleElement(const char *submoduleName) const
virtual int numExtendsNames() const
Definition nedtypeinfo.h:180
virtual Type getType() const
Definition nedtypeinfo.h:116
ConnectionElement * getLocalConnectionElement(long id) const
virtual std::string getPackage() const
virtual bool isInnerType() const
Definition nedtypeinfo.h:138
GateElement * findGateDecl(const char *name) const
virtual int numInterfaceNames() const
Definition nedtypeinfo.h:196