OMNeT++ Simulation Library  5.6.1
cnedfunction.h
1 //==========================================================================
2 // CNEDFUNCTION.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_CNEDFUNCTION_H
17 #define __OMNETPP_CNEDFUNCTION_H
18 
19 #include <cstdarg>
20 #include "simkerneldefs.h"
21 #include "globals.h"
22 #include "cownedobject.h"
23 #include "cdynamicexpression.h"
24 
25 namespace omnetpp {
26 
27 
34 typedef cNedValue (*NedFunction)(cComponent *context, cNedValue argv[], int argc);
35 
36 // NEDFunction was renamed NedFunction in OMNeT++ 5.3; typedef added for compatibility
37 typedef NedFunction NEDFunction;
38 
39 
40 
48 class SIM_API cNedFunction : public cNoncopyableOwnedObject
49 {
50  private:
51  std::string signature; // function signature, as passed to the ctor
52  std::string argTypes; // sequence of B,L,T,D,Q,S,X,*
53  bool hasVarargs_; // if true, signature contains "..." after the last typed arg
54  char returnType; // one of B,L,T,D,Q,S,X,*
55  int minArgc, maxArgc; // minimum and maximum argument count
56  NedFunction f; // function ptr
57  std::string category; // category string; only used when listing all functions
58  std::string description; // optional documentation string
59 
60  protected:
61  void parseSignature(const char *signature);
62  void checkArgs(cNedValue argv[], int argc);
63 
64  public:
83  cNedFunction(NedFunction f, const char *signature, const char *category=nullptr, const char *description=nullptr);
84 
88  virtual ~cNedFunction() {}
90 
96  virtual std::string str() const override;
98 
104  cNedValue invoke(cComponent *context, cNedValue argv[], int argc);
105 
110  NedFunction getFunctionPointer() const {return f;}
111 
115  const char *getSignature() const {return signature.c_str();}
116 
121  char getReturnType() const {return returnType;}
122 
128  char getArgType(int k) const {return argTypes[k];}
129 
134  int getMinArgs() const {return minArgc;}
135 
141  int getMaxArgs() const {return maxArgc;}
142 
147  bool hasVarArgs() const {return hasVarargs_;}
148 
153  const char *getCategory() const {return category.c_str();}
154 
158  const char *getDescription() const {return description.c_str();}
160 
164  static cNedFunction *find(const char *name);
165 
169  static cNedFunction *get(const char *name);
170 
174  static cNedFunction *findByPointer(NedFunction f);
175 };
176 
177 // cNEDFunction was renamed cNedFunction in OMNeT++ 5.3; typedef added for compatibility
178 typedef cNedFunction cNEDFunction;
179 
180 } // namespace omnetpp
181 
182 
183 #endif
184 
185 
Registration class for extending NED with arbitrary new functions.
Definition: cnedfunction.h:48
Common base for module and channel classes.
Definition: ccomponent.h:48
int getMinArgs() const
Definition: cnedfunction.h:134
char getReturnType() const
Definition: cnedfunction.h:121
cNedValue(* NedFunction)(cComponent *context, cNedValue argv[], int argc)
A function that can be used with cDynamicExpression.
Definition: cnedfunction.h:34
virtual ~cNedFunction()
Definition: cnedfunction.h:88
NedFunction getFunctionPointer() const
Definition: cnedfunction.h:110
Value used during evaluating NED expressions.
Definition: cnedvalue.h:50
int getMaxArgs() const
Definition: cnedfunction.h:141
char getArgType(int k) const
Definition: cnedfunction.h:128
bool hasVarArgs() const
Definition: cnedfunction.h:147
Definition: cabstracthistogram.h:21
Base class for cOwnedObject-based classes that do not wish to support assignment and duplication...
Definition: cownedobject.h:248
const char * getCategory() const
Definition: cnedfunction.h:153
const char * getDescription() const
Definition: cnedfunction.h:158
const char * getSignature() const
Definition: cnedfunction.h:115