Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages | Examples

wrapper_Functors.h

00001 /*
00002 MobileRobots Advanced Robotics Interface for Applications (ARIA)
00003 Copyright (C) 2004, 2005 ActivMedia Robotics LLC
00004 Copyright (C) 2006, 2007 MobileRobots Inc.
00005 
00006      This program is free software; you can redistribute it and/or modify
00007      it under the terms of the GNU General Public License as published by
00008      the Free Software Foundation; either version 2 of the License, or
00009      (at your option) any later version.
00010 
00011      This program is distributed in the hope that it will be useful,
00012      but WITHOUT ANY WARRANTY; without even the implied warranty of
00013      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014      GNU General Public License for more details.
00015 
00016      You should have received a copy of the GNU General Public License
00017      along with this program; if not, write to the Free Software
00018      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 
00020 If you wish to redistribute ARIA under different terms, contact 
00021 MobileRobots for information about a commercial version of ARIA at 
00022 robots@mobilerobots.com or 
00023 MobileRobots Inc, 19 Columbia Drive, Amherst, NH 03031; 800-639-9481
00024 */
00025 
00026 
00027 #ifndef ARIA_wrapper_Functors_h
00028 #define ARIA_wrapper_Functors_h
00029 
00030 /* Define ArFunctor subclasses to hold target-language callable function
00031  * object, and define typemaps to give instances of these subclasses to Aria
00032  * when it wants ArFunctors.
00033  *
00034  * These are used internally by the wrapper library, and typemaps convert
00035  * target-language function objects to these ArFunctor subclasses.
00036  */
00037 
00038 #include "ArFunctor.h"
00039 
00040 /* Functiors for Python: */
00041 
00042 #ifdef SWIGPYTHON
00043 class ArPyFunctor : public ArFunctor 
00044 {
00045 protected:
00046   PyObject* pyFunction;
00047 public:
00048   ArPyFunctor(PyObject* _m) : pyFunction(_m) {
00049     Py_INCREF(pyFunction);
00050   }
00051 
00052   virtual void invoke() { 
00053     PyObject* r = PyObject_CallObject(pyFunction, NULL);
00054     if(!r) {
00055       fputs("** ArPyFunctor: Error calling Python function: ", stderr);
00056       PyErr_Print();
00057     }
00058   }
00059 
00060   virtual ~ArPyFunctor() {
00061     Py_DECREF(pyFunction);
00062   }
00063 
00064   virtual const char* getName() {
00065     return (const char*) PyString_AsString(PyObject_Str(pyFunction));
00066   }
00067 };
00068 
00069 
00070 class ArPyRetFunctor_Bool : 
00071   public ArRetFunctor<bool>,
00072   public ArPyFunctor
00073 {
00074 public:
00075   ArPyRetFunctor_Bool(PyObject* _m) : ArRetFunctor<bool>(), ArPyFunctor(_m) {
00076   }
00077 
00078   virtual bool invokeR() {
00079     PyObject* r = PyObject_CallObject(pyFunction, NULL);  
00080     if(!r) {
00081       fputs("** ArPyRetFunctor_Bool: Error calling Python function: ", stderr);
00082       PyErr_Print();
00083     }
00084     return(r == Py_True);
00085   }
00086 
00087   virtual const char* getName() {
00088     return (const char*) PyString_AsString(PyObject_Str(pyFunction));
00089   }
00090 };
00091 
00092 #endif // PYTHON
00093 
00094 
00095 
00096 class ArRetFunctor_Bool:
00097   public ArRetFunctor<bool>
00098 {
00099 };
00100 
00101 #endif // wrapperFunctors.h

Generated on Tue Feb 20 10:51:42 2007 for Aria by  doxygen 1.4.0