Statistics
| Branch: | Revision:

root / include / nedsupport.h @ master

History | View | Annotate | Download (6.22 KB)

1
//==========================================================================
2
//   NEDSUPPORT.H  - part of
3
//                     OMNeT++/OMNEST
4
//            Discrete System Simulation in C++
5
//
6
//  Author: Andras Varga
7
//
8
//==========================================================================
9

    
10
/*--------------------------------------------------------------*
11
  Copyright (C) 1992-2008 Andras Varga
12
  Copyright (C) 2006-2008 OpenSim Ltd.
13

14
  This file is distributed WITHOUT ANY WARRANTY. See the file
15
  `license' for details on this and other legal matters.
16
*--------------------------------------------------------------*/
17

    
18
#ifndef __NEDSUPPORT_H
19
#define __NEDSUPPORT_H
20

    
21
#include "cdynamicexpression.h"
22

    
23
NAMESPACE_BEGIN
24

    
25
namespace NEDSupport {
26

    
27
typedef cDynamicExpression::Value Value; // abbreviation for local use
28

    
29
class ModuleIndex : public cDynamicExpression::Functor
30
{
31
  public:
32
    ModuleIndex();
33
    ModuleIndex *dup() const {return new ModuleIndex();}
34
    virtual const char *getFullName() const {return "index";}
35
    virtual const char *getArgTypes() const {return "";}
36
    virtual char getReturnType() const {return 'L';}
37
    virtual Value evaluate(cComponent *context, Value args[], int numargs);
38
    virtual std::string str(std::string args[], int numargs);
39
};
40

    
41
/**
42
 * Variations: parameter, parentParameter
43
 */
44
class ParameterRef : public cDynamicExpression::Functor
45
{
46
  protected:
47
    bool ofParent;  // if true, return parentModule->par(paramName)
48
    bool explicitKeyword; // when ofParent==false: whether the NED file contained the explicit "this" qualifier
49
    std::string paramName;
50
  public:
51
    ParameterRef(const char *paramName, bool ofParent, bool explicitKeyword);
52
    ParameterRef *dup() const {return new ParameterRef(paramName.c_str(), ofParent, explicitKeyword);}
53
    virtual const char *getFullName() const {return paramName.c_str();}
54
    virtual const char *getArgTypes() const {return "";}
55
    virtual char getReturnType() const {return '*';}
56
    virtual Value evaluate(cComponent *context, Value args[], int numargs);
57
    virtual std::string str(std::string args[], int numargs);
58
};
59

    
60
/**
61
 * siblingModuleParameter, indexedSiblingModuleParameter
62
 */
63
class SiblingModuleParameterRef : public cDynamicExpression::Functor
64
{
65
  protected:
66
    bool ofParent;  // if true, return parentModule->getSubmodule(...)->par(parname)
67
    std::string moduleName;
68
    bool withModuleIndex;
69
    std::string paramName;
70
  public:
71
    SiblingModuleParameterRef(const char *moduleName, const char *paramName, bool ofParent, bool withModuleIndex);
72
    SiblingModuleParameterRef *dup() const {return new SiblingModuleParameterRef(moduleName.c_str(), paramName.c_str(), ofParent, withModuleIndex);}
73
    virtual const char *getFullName() const {return paramName.c_str();}
74
    virtual const char *getArgTypes() const {return withModuleIndex ? "L" : "";}
75
    virtual char getReturnType() const {return '*';}
76
    virtual Value evaluate(cComponent *context, Value args[], int numargs);
77
    virtual std::string str(std::string args[], int numargs);
78
};
79

    
80
/**
81
 * i,j in NED "for" loops
82
 */
83
class LoopVar : public cDynamicExpression::Functor
84
{
85
  private:
86
    // the loopvar stack (vars of nested loops are pushed on the stack by cNEDNetworkBuilder)
87
    static const char *varNames[32];
88
    static long vars[32];
89
    static int varCount;
90
  public:
91
    static long& pushVar(const char *varName);
92
    static void popVar();
93
    static void reset();
94
    static const char **getVarNames() {return varNames;}
95
    static int getNumVars() {return varCount;}
96

    
97
  protected:
98
    std::string varName;
99
  public:
100
    LoopVar(const char *varName) {this->varName = varName;}
101
    LoopVar *dup() const {return new LoopVar(varName.c_str());}
102
    virtual const char *getFullName() const {return varName.c_str();}
103
    virtual const char *getArgTypes() const {return "";}
104
    virtual char getReturnType() const {return 'L';}
105
    virtual Value evaluate(cComponent *context, Value args[], int numargs);
106
    virtual std::string str(std::string args[], int numargs);
107
};
108

    
109

    
110
/**
111
 * sizeof operator. See also: SiblingModuleSizeof
112
 */
113
class Sizeof : public cDynamicExpression::Functor
114
{
115
  protected:
116
    bool ofParent;  // if true, return parentModule->gateSize(ident)
117
    bool explicitKeyword; // when ofParent==false: whether the NED file contained the explicit "this" qualifier
118
    std::string ident;
119
  public:
120
    Sizeof(const char *ident, bool ofParent, bool explicitKeyword);
121
    Sizeof *dup() const {return new Sizeof(ident.c_str(), ofParent, explicitKeyword);}
122
    virtual const char *getFullName() const {return ident.c_str();}
123
    virtual const char *getArgTypes() const {return "";}
124
    virtual char getReturnType() const {return 'L';}
125
    virtual Value evaluate(cComponent *context, Value args[], int numargs);
126
    virtual std::string str(std::string args[], int numargs);
127
};
128

    
129
/**
130
 * xmldoc operator: xmldoc(file) or xmldoc(file,xpath)
131
 */
132
class XMLDoc : public cDynamicExpression::Functor
133
{
134
  protected:
135
    bool withXPath;  // whether 1 or 2 args
136
  public:
137
    XMLDoc(bool withXPath) {this->withXPath = withXPath;}
138
    XMLDoc *dup() const {return new XMLDoc(withXPath);}
139
    virtual const char *getFullName() const {return "xmldoc";}
140
    virtual const char *getArgTypes() const {return withXPath ? "SS" : "S";}
141
    virtual char getReturnType() const {return 'X';}
142
    virtual Value evaluate(cComponent *context, Value args[], int numargs);
143
    virtual std::string str(std::string args[], int numargs);
144
};
145

    
146
/*XXX TODO
147
static Value getSizeofIdent(cComponent *context, Value args[], int numargs);
148
static Value getSizeofGate(cComponent *context, Value args[], int numargs);
149
static Value getSizeofParentModuleGate(cComponent *context, Value args[], int numargs);
150
static Value getSizeofSiblingModuleGate(cComponent *context, Value args[], int numargs);
151
static Value getSizeofIndexedSiblingModuleGate(cComponent *context, Value args[], int numargs);
152

153
class Sizeof : public Functor
154
{
155
  protected:
156
    bool ofParent;
157
    bool bstd::string paramName;
158
    std::string moduleName;
159
  public:
160
    virtual const char *getArgTypes() const {return "";}
161
    virtual char getReturnType() const {return 'L';}
162
    virtual Value evaluate(cComponent *context, Value args[], int numargs);
163
    virtual std::string str(std::string args[], int numargs) {return "index";}
164
};
165
*/
166

    
167
};
168

    
169
NAMESPACE_END
170

    
171

    
172
#endif
173

    
174