Statistics
| Branch: | Revision:

root / src / nedxml / nedtypeinfo.h @ 68da4f12

History | View | Annotate | Download (7.88 KB)

1 01873262 Georg Kunz
//==========================================================================
2
// NEDTYPEINFO.H -
3
//
4
//                     OMNeT++/OMNEST
5
//            Discrete System Simulation in C++
6
//
7
//==========================================================================
8
9
/*--------------------------------------------------------------*
10
  Copyright (C) 2002-2008 Andras Varga
11
  Copyright (C) 2006-2008 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 __NEDTYPEINFO_H
19
#define __NEDTYPEINFO_H
20
21
#include <map>
22
#include <vector>
23
#include <string>
24
#include "nedelements.h"
25
#include "commonutil.h"
26
27
NAMESPACE_BEGIN
28
29
class NEDResourceCache;
30
31
/**
32
 * Wraps a NEDElement tree of a NED declaration (module, channel, module
33
 * interface or channel interface), or declaration in a msg file (enum,
34
 * class, struct). May be extended by subclassing.
35
 *
36
 * Represents NED declarations of modules, module interfaces,
37
 * channels and channel interfaces. All instances are created and managed
38
 * by NEDResourceCache.
39
 *
40
 * @ingroup NEDResources
41
 */
42
class NEDXML_API NEDTypeInfo
43
{
44
  public:
45
    enum Type {SIMPLE_MODULE, COMPOUND_MODULE, MODULEINTERFACE, CHANNEL, CHANNELINTERFACE};
46
47
  protected:
48
    // the resolver this type is in
49
    NEDResourceCache *resolver;
50
51
    Type type;
52
    std::string qualifiedName;
53
    bool isInner;  // whether it is an inner type
54
    NEDElement *tree; // points into resolver
55
56
    // tree with inheritance flattened out.
57
    // may be NULL (-->not initialized), or ==tree (when there is no super types);
58
    // otherwise it's a constructed tree that gets disposed of in the destructor
59
    mutable NEDElement *flattenedTree;
60
61
    typedef std::vector<std::string> StringVector;
62
    typedef std::map<std::string,int> StringToIntMap;
63
64
    // inheritance. Vectors contain fully qualifies names, and include
65
    // indirect base types/interfaces as well (transitive closure).
66
    StringVector extendsnames;
67
    StringVector interfacenames;
68
69
    std::string enclosingTypeName;
70
71
    // simple module/channel C++ class to instantiate
72
    std::string implClassName;
73
74
  protected:
75
    NEDElement *buildFlattenedTree() const; //XXX mostly unused
76
    void mergeNEDType(NEDElement *basetree, const NEDElement *tree) const;
77
    void mergeProperties(NEDElement *basetree, const NEDElement *tree) const;
78
    void mergeProperty(PropertyElement *baseprop, const PropertyElement *prop) const;
79
    void mergePropertyKey(PropertyKeyElement *basekey, const PropertyKeyElement *key) const;
80
81
    void checkComplianceToInterface(NEDTypeInfo *interfaceDecl);
82
83
  public:
84
    /** Constructor. It expects fully qualified name */
85
    NEDTypeInfo(NEDResourceCache *resolver, const char *qname, bool isInnerType, NEDElement *tree);
86
87
    /** Destructor */
88
    virtual ~NEDTypeInfo();
89
90
    /** Returns the simple name of the NED type */
91
    virtual const char *getName() const;
92
93
    /** Returns the fully qualified name of the NED type */
94
    virtual const char *getFullName() const;
95
96
    /** Returns the raw NEDElement tree representing the component */
97
    virtual NEDElement *getTree() const;
98
99
    /** Returns the NEDElement tree where super types have been flattened */
100
    virtual NEDElement *getFlattenedTree() const; //XXX this is a BAD idea, get rid of it!
101
102
    /** The NED type resolver this type is registered in */
103
    NEDResourceCache *getResolver() const  {return resolver;}
104
105
    /**
106
     * Returns the type of this declaration: simple module, compound module,
107
     * channel, etc.
108
     */
109
    virtual Type getType() const {return type;}
110
111
    /**
112
     * Returns the package name (from the package declaration of the containing
113
     * NED file
114
     */
115
    virtual std::string getPackage() const;
116
117
    /**
118
     * Returns a one-line summary (base class, implemented interfaces, etc)
119
     */
120
    virtual std::string info() const;
121
122
    /**
123
     * Returns the NED declaration.
124
     */
125
    virtual std::string nedSource() const;
126
127
    /**
128
     * Returns the number of "extends" names. This includes indirect
129
     * base types as well (i.e. base types of base types, etc).
130
     */
131
    virtual int numExtendsNames() const  {return extendsnames.size();}
132
133
    /**
134
     * Returns the name of the kth "extends" name (k=0..numExtendsNames()-1),
135
     * resolved to fully qualified name.
136
     */
137
    virtual const char *extendsName(int k) const;
138
139
    /**
140
     * Returns the number of interfaces. This includes indirectly implemented
141
     * interfaces as well. (That is, the list contains interfaces implemented
142
     * by this type and all its base types, plus base types of all those
143
     * interfaces).
144
     */
145
    virtual int numInterfaceNames() const  {return interfacenames.size();}
146
147
    /**
148
     * Returns the name of the kth interface (k=0..numInterfaceNames()-1),
149
     * resolved to fully qualified name.
150
     */
151
    virtual const char *interfaceName(int k) const;
152
153
    /**
154
     * Returns true if this NED type extends/"is like" the given module interface
155
     * or channel interface
156
     */
157
    virtual bool supportsInterface(const char *qname);
158
159
    /**
160
     * Returns true if this NED type is an inner type
161
     */
162
    virtual bool isInnerType() const  {return isInner;}
163
164
    /**
165
     * If this type is an inner type, returns fully qualified name of its
166
     * enclosing type, otherwise returns NULL.
167
     */
168
    virtual const char *getEnclosingTypeName() const;
169
170
    /**
171
     * Returns true if this NED type has a local (non-inherited)
172
     * \@network (or \@network(true)) property.
173
     */
174
    virtual bool isNetwork() const;
175
176
    /**
177
     * For simple modules and channels, it returns the name of the C++ class that
178
     * has to be instantiated; otherwise it returns NULL.
179
     */
180
    virtual const char *implementationClassName() const;
181
182
    /**
183
     * Find a property with the given name in the type's NED file, then in the
184
     * package.ned file of the NED file, then in parent package.ned files up
185
     * to the root (the NED source folder this NED file is in). Returns
186
     * the simple value of the property (1st value of default key), or
187
     * empty string if not found.
188
     */
189
    virtual std::string getPackageProperty(const char *name) const;
190
191
    /** The C++ namespace for this NED type; implemented as getPackageProperty("namespace"). */
192
    virtual std::string getCxxNamespace() const;
193
194
    /** Returns the first "extends" clause, or NULL */
195
    virtual NEDTypeInfo *getSuperDecl() const;
196
197
    /** @name Convenience method to query the tree */
198
    //@{
199
    ParametersElement *getParametersElement() const;
200
    GatesElement *getGatesElement() const;
201
    SubmodulesElement *getSubmodulesElement() const;
202
    ConnectionsElement *getConnectionsElement() const;
203
204
    /** Returns the submodule element with the given name from the local type, or NULL if not found */
205
    SubmoduleElement *getLocalSubmoduleElement(const char *submoduleName) const;
206
207
    /** Returns the connection element with the given id from the local type, or NULL if not found */
208
    ConnectionElement *getLocalConnectionElement(long id) const;
209
210
    /** Returns the submodule element with the given name from the local type and "extends" types, or NULL if not found */
211
    SubmoduleElement *getSubmoduleElement(const char *submoduleName) const;
212
213
    /** Returns the connection element with the given id from the local type and "extends" types, or NULL if not found */
214
    ConnectionElement *getConnectionElement(long id) const;
215
216
    /** Searches local type; NULL if not found */
217
    ParamElement *findLocalParamDecl(const char *name) const;
218
219
    /** Searches local type and "extends" types; NULL if not found */
220
    ParamElement *findParamDecl(const char *name) const;
221
222
    /** Searches local type; NULL if not found */
223
    GateElement *findLocalGateDecl(const char *name) const;
224
225
    /** Searches local type and "extends" types; NULL if not found */
226
    GateElement *findGateDecl(const char *name) const;
227
    //@}
228
};
229
230
NAMESPACE_END
231
232
233
#endif