OMNeT++ NEDXML 6.1
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 "common/commonutil.h"
25 #include "nedelements.h"
26 
27 namespace omnetpp {
28 namespace nedxml {
29 
30 class NedResourceCache;
31 
44 {
45  public:
46  enum Type {SIMPLE_MODULE, COMPOUND_MODULE, MODULEINTERFACE, CHANNEL, CHANNELINTERFACE};
47 
48  protected:
49  // the resolver this type is in
51 
53  std::string qualifiedName;
54  bool isInner; // whether it is an inner type
55  ASTNode *tree; // points into resolver
56 
57  bool resolved = false;
58  bool resolving = false;
59 
60  // Important: The fields below are only filled in when the "resolved" flag is true.
61 
62  typedef std::vector<std::string> StringVector;
63  typedef std::map<std::string,ASTNode*> NameToElementMap;
64 
65  // inheritance. Vectors contain fully qualifies names, and include
66  // indirect base types/interfaces as well (transitive closure).
69 
70  std::string enclosingTypeName;
71 
72  // simple module/channel C++ class to instantiate
73  std::string implClassName;
74 
75  // local declarations by name
82 
83  protected:
84  void checkComplianceToInterface(NedTypeInfo *interfaceDecl);
85  void collectLocalDeclarations();
86  void addToElementMap(NameToElementMap& elementMap, ASTNode *node);
87  void mergeElementMap(NameToElementMap& destMap, const NameToElementMap& elementMap);
88  void resolveIfNeeded() const {if (!isResolved()) const_cast<NedTypeInfo*>(this)->resolve(); /*ouch*/}
89 
90  public:
92  NedTypeInfo(NedResourceCache *resolver, const char *qname, bool isInnerType, ASTNode *tree);
93 
95  virtual ~NedTypeInfo();
96 
98  virtual const char *getName() const;
99 
101  virtual const char *getFullName() const;
102 
104  virtual ASTNode *getTree() const;
105 
107  NedResourceCache *getResolver() const {return resolver;}
108 
113  virtual Type getType() const {return type;}
114 
119  virtual bool isNetwork() const;
120 
124  virtual const char *getSourceFileName() const;
125 
130  virtual std::string getPackage() const;
131 
135  virtual bool isInnerType() const {return isInner;}
136 
141  virtual const char *getEnclosingTypeName() const;
142 
146  virtual std::string str() const;
147 
151  virtual std::string getNedSource() const;
152 
156  virtual bool isResolved() const {return resolved;}
157 
165  virtual void resolve();
166 
172  virtual int numExtendsNames() const {resolveIfNeeded(); return extendsNames.size();}
173 
179  virtual const char *getExtendsName(int k) const;
180 
188  virtual int numInterfaceNames() const {resolveIfNeeded(); return interfaceNames.size();}
189 
195  virtual const char *getInterfaceName(int k) const;
196 
202  virtual bool supportsInterface(const char *qname);
203 
210  virtual const char *getImplementationClassName() const;
211 
220  virtual std::string getPackageProperty(const char *name) const;
221 
226  virtual std::string getCxxNamespace() const;
227 
232  virtual NedTypeInfo *getSuperDecl() const;
233 
236  TypesElement *getTypesElement() const;
237  ParametersElement *getParametersElement() const;
238  GatesElement *getGatesElement() const;
239  SubmodulesElement *getSubmodulesElement() const;
240  ConnectionsElement *getConnectionsElement() const;
241 
243  SubmoduleElement *getLocalSubmoduleElement(const char *submoduleName) const;
244 
246  ConnectionElement *getLocalConnectionElement(long id) const;
247 
249  SubmoduleElement *getSubmoduleElement(const char *submoduleName) const;
250 
252  ConnectionElement *getConnectionElement(long id) const;
253 
255  ParamElement *findLocalParamDecl(const char *name) const;
256 
258  ParamElement *findParamDecl(const char *name) const;
259 
261  GateElement *findLocalGateDecl(const char *name) const;
262 
264  GateElement *findGateDecl(const char *name) const;
266 };
267 
268 } // namespace nedxml
269 } // namespace omnetpp
270 
271 
272 #endif
273 
omnetpp::nedxml::NedTypeInfo::localSubmoduleDecls
NameToElementMap localSubmoduleDecls
Definition: nedtypeinfo.h:79
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:80
omnetpp::nedxml::NedTypeInfo::localParamDecls
NameToElementMap localParamDecls
Definition: nedtypeinfo.h:77
omnetpp::nedxml::NedTypeInfo::Type
Type
Definition: nedtypeinfo.h:46
omnetpp::nedxml::NedTypeInfo::interfaceNames
StringVector interfaceNames
Definition: nedtypeinfo.h:68
omnetpp::nedxml::NedTypeInfo::getResolver
NedResourceCache * getResolver() const
Definition: nedtypeinfo.h:107
omnetpp::nedxml::NedTypeInfo::implClassName
std::string implClassName
Definition: nedtypeinfo.h:73
NEDXML_API
#define NEDXML_API
Definition: nedxmldefs.h:31
omnetpp::nedxml::NedTypeInfo::tree
ASTNode * tree
Definition: nedtypeinfo.h:55
omnetpp::nedxml::NedTypeInfo::numInterfaceNames
virtual int numInterfaceNames() const
Definition: nedtypeinfo.h:188
omnetpp
Definition: astbuilder.h:25
omnetpp::nedxml::NedTypeInfo::StringVector
std::vector< std::string > StringVector
Definition: nedtypeinfo.h:62
omnetpp::nedxml::NedTypeInfo::numExtendsNames
virtual int numExtendsNames() const
Definition: nedtypeinfo.h:172
omnetpp::nedxml::NedTypeInfo::resolver
NedResourceCache * resolver
Definition: nedtypeinfo.h:50
omnetpp::nedxml::NedTypeInfo::localGateDecls
NameToElementMap localGateDecls
Definition: nedtypeinfo.h:78
omnetpp::nedxml::NedTypeInfo
Stores information on a NED type.
Definition: nedtypeinfo.h:43
omnetpp::nedxml::ASTNode
Definition: astnode.h:87
omnetpp::nedxml::NedTypeInfo::getType
virtual Type getType() const
Definition: nedtypeinfo.h:113
omnetpp::nedxml::NedTypeInfo::extendsNames
StringVector extendsNames
Definition: nedtypeinfo.h:67
omnetpp::nedxml::NedTypeInfo::NameToElementMap
std::map< std::string, ASTNode * > NameToElementMap
Definition: nedtypeinfo.h:63
omnetpp::nedxml::NedTypeInfo::isResolved
virtual bool isResolved() const
Definition: nedtypeinfo.h:156
omnetpp::nedxml::NedTypeInfo::allLocalDecls
NameToElementMap allLocalDecls
Definition: nedtypeinfo.h:81
omnetpp::nedxml::NedTypeInfo::type
Type type
Definition: nedtypeinfo.h:52
omnetpp::nedxml::NedTypeInfo::localInnerTypeDecls
NameToElementMap localInnerTypeDecls
Definition: nedtypeinfo.h:76
omnetpp::nedxml::NedTypeInfo::qualifiedName
std::string qualifiedName
Definition: nedtypeinfo.h:53
omnetpp::nedxml::NedTypeInfo::enclosingTypeName
std::string enclosingTypeName
Definition: nedtypeinfo.h:70
omnetpp::nedxml::NedTypeInfo::isInnerType
virtual bool isInnerType() const
Definition: nedtypeinfo.h:135
omnetpp::nedxml::NedTypeInfo::isInner
bool isInner
Definition: nedtypeinfo.h:54
omnetpp::nedxml::NedTypeInfo::resolveIfNeeded
void resolveIfNeeded() const
Definition: nedtypeinfo.h:88