Sirikata
libproxyobject/include/sirikata/proxyobject/Invokable.hpp
Go to the documentation of this file.
00001 #ifndef _SIRIKATA_INVOKABLE_HPP_
00002 #define _SIRIKATA_INVOKABLE_HPP_
00003 
00004 #include <sirikata/proxyobject/Platform.hpp>
00005 #include <sirikata/core/util/SpaceObjectReference.hpp>
00006 #include <vector>
00007 #include <boost/any.hpp>
00008 
00009 
00010 namespace Sirikata
00011 {
00012   class SIRIKATA_PROXYOBJECT_EXPORT Invokable
00013   {
00014     public:
00015     virtual boost::any invoke(std::vector<boost::any>& params);
00016     boost::any invoke();
00017     virtual ~Invokable();
00018 
00019     typedef std::vector<boost::any> Array;
00020     typedef std::map<String, boost::any> Dict;
00021 
00022     // Because type_info's aren't guaranteed the same across shared libraries unless you
00023     // export *all* symbols, we include a bunch of utilties for performing
00024     // translations, which will all end up using *this* library's type_infos. As
00025     // long as you stick to using these utilities, everything should translate
00026     // back and forth to and from boost:any's in a way that all libraries can
00027     // safely interact with.  Note that this also means that you can only
00028     // *safely* use these types, but you shouldn't be using a wide variety of
00029     // types anyway since both ends need to know how to encode/decode the values.
00030 
00031     static bool anyIsBoolean(const boost::any& a);
00032     static bool anyAsBoolean(const boost::any& a);
00033     static bool anyIsFloat(const boost::any& a);
00034     static float32 anyAsFloat(const boost::any& a);
00035     static bool anyIsDouble(const boost::any& a);
00036     static float64 anyAsDouble(const boost::any& a);
00037     static bool anyIsNumeric(const boost::any& a);
00038     static float64 anyAsNumeric(const boost::any& a);
00039 
00040     static bool anyIsUInt8(const boost::any& a);
00041     static uint8 anyAsUInt8(const boost::any& a);
00042     static bool anyIsInt8(const boost::any& a);
00043     static int8 anyAsInt8(const boost::any& a);
00044     static bool anyIsUInt16(const boost::any& a);
00045     static uint16 anyAsUInt16(const boost::any& a);
00046     static bool anyIsInt16(const boost::any& a);
00047     static int16 anyAsInt16(const boost::any& a);
00048     static bool anyIsUInt32(const boost::any& a);
00049     static uint32 anyAsUInt32(const boost::any& a);
00050     static bool anyIsInt32(const boost::any& a);
00051     static int32 anyAsInt32(const boost::any& a);
00052     static bool anyIsUInt64(const boost::any& a);
00053     static uint64 anyAsUInt64(const boost::any& a);
00054     static bool anyIsInt64(const boost::any& a);
00055     static int64 anyAsInt64(const boost::any& a);
00056 
00057     static bool anyIsString(const boost::any& a);
00058     static String anyAsString(const boost::any& a);
00059     static bool anyIsInvokable(const boost::any& a);
00060     static Invokable* anyAsInvokable(const boost::any& a);
00061     static bool anyIsObject(const boost::any& a);
00062     static SpaceObjectReference anyAsObject(const boost::any& a);
00063     static bool anyIsDict(const boost::any& a);
00064     static Dict anyAsDict(const boost::any& a);
00065     static bool anyIsArray(const boost::any& a);
00066     static Array anyAsArray(const boost::any& a);
00067 
00068     // Note that these are specifically *not* templated so they are forced to be
00069     // compiled into this library, guaranteeing proper type_info's.
00070     static boost::any asAny(bool b);
00071     static boost::any asAny(uint8 b);
00072     static boost::any asAny(int8 b);
00073     static boost::any asAny(uint16 b);
00074     static boost::any asAny(int16 b);
00075     static boost::any asAny(uint32 b);
00076     static boost::any asAny(int32 b);
00077     static boost::any asAny(uint64 b);
00078     static boost::any asAny(int64 b);
00079     static boost::any asAny(float b);
00080     static boost::any asAny(double b);
00081     static boost::any asAny(const String& b);
00082     static boost::any asAny(Invokable* b);
00083     static boost::any asAny(const SpaceObjectReference& b);
00084     static boost::any asAny(const Dict& b);
00085     static boost::any asAny(const Array& b);
00086   };
00087 }
00088 
00089 #endif