cnedfunction.h

00001 //==========================================================================
00002 //  CNEDFUNCTION.H - part of
00003 //                     OMNeT++/OMNEST
00004 //            Discrete System Simulation in C++
00005 //
00006 //==========================================================================
00007 
00008 /*--------------------------------------------------------------*
00009   Copyright (C) 1992-2008 Andras Varga
00010   Copyright (C) 2006-2008 OpenSim Ltd.
00011 
00012   This file is distributed WITHOUT ANY WARRANTY. See the file
00013   `license' for details on this and other legal matters.
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;      // function signature, as passed to the ctor
00048     std::string argtypes;  // sequence of B,L,D,Q,S,X,*
00049     bool hasvarargs;       // if true, signature contains "..." after the last typed arg
00050     char rettype;          // one of B,L,D,Q,S,X,*
00051     int minargc, maxargc;  // minimum and maximum argument count
00052     NEDFunction f;         // function ptr
00053     std::string categ;     // category string; only used when listing all functions
00054     std::string desc;      // optional documentation string
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 
Generated on Tue Dec 2 11:16:27 2014 for OMNeT++ Simulation Library by  doxygen 1.6.3