OMNeT++ Simulation Library  5.6.1
nedsupport.h
1 //==========================================================================
2 // NEDSUPPORT.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_NEDSUPPORT_H
17 #define __OMNETPP_NEDSUPPORT_H
18 
19 #include "cdynamicexpression.h"
20 
21 namespace omnetpp {
22 
23 namespace nedsupport {
24 
25 class NedExpressionContext : public cExpression::Context
26 {
27  public:
28  enum ExpressionRole { SUBMODULE_CONDITION, SUBMODULE_ARRAY_CONDITION, OTHER };
29  explicit NedExpressionContext(cComponent *component, ExpressionRole role, const char *computedTypename) :
30  cExpression::Context(component), role(role), computedTypename(computedTypename) {}
31  ExpressionRole role;
32  const char *computedTypename;
33 };
34 
35 class ModuleIndex : public cDynamicExpression::Functor
36 {
37  public:
38  ModuleIndex();
39  ModuleIndex *dup() const override {return new ModuleIndex();}
40  virtual const char *getFullName() const override {return "index";}
41  virtual const char *getArgTypes() const override {return "";}
42  virtual char getReturnType() const override {return 'L';}
43  virtual cNedValue evaluate(Context *context, cNedValue args[], int numargs) override;
44  virtual std::string str(std::string args[], int numargs) override;
45 };
46 
47 class Exists : public cDynamicExpression::Functor
48 {
49  std::string ident;
50  bool ofParent;
51  public:
52  Exists(const char *ident, bool ofParent);
53  Exists *dup() const override {return new Exists(ident.c_str(), ofParent);}
54  virtual const char *getFullName() const override {return "exists";}
55  virtual const char *getArgTypes() const override {return "";}
56  virtual char getReturnType() const override {return 'B';}
57  virtual cNedValue evaluate(Context *context, cNedValue args[], int numargs) override;
58  virtual std::string str(std::string args[], int numargs) override;
59 };
60 
61 class Typename : public cDynamicExpression::Functor
62 {
63  public:
64  Typename();
65  Typename *dup() const override {return new Typename();}
66  virtual const char *getFullName() const override {return "typename";}
67  virtual const char *getArgTypes() const override {return "";}
68  virtual char getReturnType() const override {return 'S';}
69  virtual cNedValue evaluate(Context *context, cNedValue args[], int numargs) override;
70  virtual std::string str(std::string args[], int numargs) override;
71 };
72 
77 {
78  protected:
79  bool ofParent; // if true, return parentModule->par(paramName)
80  bool explicitKeyword; // when ofParent==false: whether the NED file contained the explicit "this" qualifier
81  std::string paramName;
82  public:
83  ParameterRef(const char *paramName, bool ofParent, bool explicitKeyword);
84  ParameterRef *dup() const override {return new ParameterRef(paramName.c_str(), ofParent, explicitKeyword);}
85  virtual const char *getFullName() const override {return paramName.c_str();}
86  virtual const char *getArgTypes() const override {return "";}
87  virtual char getReturnType() const override {return '*';}
88  virtual cNedValue evaluate(Context *context, cNedValue args[], int numargs) override;
89  virtual std::string str(std::string args[], int numargs) override;
90 };
91 
96 {
97  protected:
98  bool ofParent; // if true, return parentModule->getSubmodule(...)->par(parname)
99  std::string moduleName;
100  bool withModuleIndex;
101  std::string paramName;
102  public:
103  SiblingModuleParameterRef(const char *moduleName, const char *paramName, bool ofParent, bool withModuleIndex);
104  SiblingModuleParameterRef *dup() const override {return new SiblingModuleParameterRef(moduleName.c_str(), paramName.c_str(), ofParent, withModuleIndex);}
105  virtual const char *getFullName() const override {return paramName.c_str();}
106  virtual const char *getArgTypes() const override {return withModuleIndex ? "L" : "";}
107  virtual char getReturnType() const override {return '*';}
108  virtual cNedValue evaluate(Context *context, cNedValue args[], int numargs) override;
109  virtual std::string str(std::string args[], int numargs) override;
110 };
111 
116 {
117  private:
118  // the loopvar stack (vars of nested loops are pushed on the stack by cNedNetworkBuilder)
119  static const char *varNames[32];
120  static long vars[32];
121  static int varCount;
122  public:
123  static long& pushVar(const char *varName);
124  static void popVar();
125  static void reset();
126  static const char **getVarNames() {return varNames;}
127  static int getNumVars() {return varCount;}
128 
129  protected:
130  std::string varName;
131  public:
132  LoopVar(const char *varName) {this->varName = varName;}
133  LoopVar *dup() const override {return new LoopVar(varName.c_str());}
134  virtual const char *getFullName() const override {return varName.c_str();}
135  virtual const char *getArgTypes() const override {return "";}
136  virtual char getReturnType() const override {return 'L';}
137  virtual cNedValue evaluate(Context *context, cNedValue args[], int numargs) override;
138  virtual std::string str(std::string args[], int numargs) override;
139 };
140 
141 
146 {
147  protected:
148  bool ofParent; // if true, return parentModule->gateSize(ident)
149  bool explicitKeyword; // when ofParent==false: whether the NED file contained the explicit "this" qualifier
150  std::string ident;
151  public:
152  Sizeof(const char *ident, bool ofParent, bool explicitKeyword);
153  Sizeof *dup() const override {return new Sizeof(ident.c_str(), ofParent, explicitKeyword);}
154  virtual const char *getFullName() const override {return ident.c_str();}
155  virtual const char *getArgTypes() const override {return "";}
156  virtual char getReturnType() const override {return 'L';}
157  virtual cNedValue evaluate(Context *context, cNedValue args[], int numargs) override;
158  virtual std::string str(std::string args[], int numargs) override;
159 };
160 
161 /*XXX TODO
162 static cNedValue getSizeofIdent(Context *context, cNedValue args[], int numargs);
163 static cNedValue getSizeofGate(Context *context, cNedValue args[], int numargs);
164 static cNedValue getSizeofParentModuleGate(Context *context, cNedValue args[], int numargs);
165 static cNedValue getSizeofSiblingModuleGate(Context *context, cNedValue args[], int numargs);
166 static cNedValue getSizeofIndexedSiblingModuleGate(Context *context, cNedValue args[], int numargs);
167 
168 class Sizeof : public Functor
169 {
170  protected:
171  bool ofParent;
172  bool bstd::string paramName;
173  std::string moduleName;
174  public:
175  virtual const char *getArgTypes() const {return "";}
176  virtual char getReturnType() const {return 'L';}
177  virtual cNedValue evaluate(Context *context, cNedValue args[], int numargs);
178  virtual std::string str(std::string args[], int numargs) {return "index";}
179 };
180 */
181 
182 };
183 
184 } // namespace omnetpp
185 
186 
187 #endif
188 
189 
ParameterRef * dup() const override
Definition: nedsupport.h:84
virtual const char * getFullName() const override
Definition: nedsupport.h:105
i,j in NED "for" loops
Definition: nedsupport.h:115
virtual const char * getFullName() const override
Definition: nedsupport.h:134
Function object base class. We use function objects to handle NED parameter references, "index" and "sizeof" operators, and references to NED "for" loop variables.
Definition: cdynamicexpression.h:237
sizeof operator. See also: SiblingModuleSizeof
Definition: nedsupport.h:145
siblingModuleParameter, indexedSiblingModuleParameter
Definition: nedsupport.h:95
Value used during evaluating NED expressions.
Definition: cnedvalue.h:50
virtual const char * getFullName() const override
Definition: nedsupport.h:154
Variations: parameter, parentParameter.
Definition: nedsupport.h:76
LoopVar * dup() const override
Definition: nedsupport.h:133
Sizeof * dup() const override
Definition: nedsupport.h:153
Definition: cabstracthistogram.h:21
virtual const char * getFullName() const override
Definition: nedsupport.h:85
SiblingModuleParameterRef * dup() const override
Definition: nedsupport.h:104
Contextual information for evaluating the expression.
Definition: cexpression.h:39