cnedfunction.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef __CNEDFUNCTION_H
00017 #define __CNEDFUNCTION_H
00018
00019 #include <stdarg.h>
00020 #include "simkerneldefs.h"
00021 #include "globals.h"
00022 #include "cownedobject.h"
00023 #include "cdynamicexpression.h"
00024
00025 NAMESPACE_BEGIN
00026
00027
00034 typedef cNEDValue (*NEDFunction)(cComponent *context, cNEDValue argv[], int argc);
00035
00036
00044 class SIM_API cNEDFunction : public cNoncopyableOwnedObject
00045 {
00046 private:
00047 std::string sign;
00048 std::string argtypes;
00049 bool hasvarargs;
00050 char rettype;
00051 int minargc, maxargc;
00052 NEDFunction f;
00053 std::string categ;
00054 std::string desc;
00055
00056 protected:
00057 void parseSignature(const char *signature);
00058 void checkArgs(cNEDValue argv[], int argc);
00059
00060 public:
00079 cNEDFunction(NEDFunction f, const char *signature, const char *category=NULL, const char *description=NULL);
00080
00084 virtual ~cNEDFunction() {}
00086
00092 virtual std::string info() const;
00094
00100 cNEDValue invoke(cComponent *context, cNEDValue argv[], int argc);
00101
00106 NEDFunction getFunctionPointer() const {return f;}
00107
00111 const char *getSignature() const {return sign.c_str();}
00112
00117 char getReturnType() const {return rettype;}
00118
00124 char getArgType(int k) const {return argtypes[k];}
00125
00130 int getMinArgs() const {return minargc;}
00131
00137 int getMaxArgs() const {return maxargc;}
00138
00143 bool hasVarArgs() const {return hasvarargs;}
00144
00149 const char *getCategory() const {return categ.c_str();}
00150
00154 const char *getDescription() const {return desc.c_str();}
00156
00160 static cNEDFunction *find(const char *name);
00161
00165 static cNEDFunction *get(const char *name);
00166
00170 static cNEDFunction *findByPointer(NEDFunction f);
00171 };
00172
00173 NAMESPACE_END
00174
00175
00176 #endif
00177
00178