00001 /* 00002 * PROPRIETARY INFORMATION. This software is proprietary to 00003 * Side Effects Software Inc., and is not to be reproduced, 00004 * transmitted, or disclosed in any way without written permission. 00005 * 00006 * Produced by: 00007 * Side Effects Software Inc 00008 * 123 Front Street West, Suite 1401 00009 * Toronto, Ontario 00010 * Canada M5J 2M2 00011 * 416-504-9876 00012 * 00013 * COMMENTS: 00014 * This class is used to tell swig that it should take ownership of 00015 * the items inside a std::vector. (There is no way with %newobject 00016 * to say that the items inside a vector are dynamically allocated.) 00017 * 00018 * Use this class as follows: 00019 * 00020 * std::vector<HOM_ElemPtr<HOM_Node> > returnTupleOfNodes() 00021 * { 00022 * std::vector<HOM_ElemPtr<HOM_Node> > result; 00023 * for (...) 00024 * result.push_back(new HOMF_Node(...)); 00025 * return result; 00026 * } 00027 * 00028 * or 00029 * 00030 * std::map<std::string, HOM_ElemPtr<HOM_Node> > returnDictOfNodes() 00031 * { 00032 * std::map<std::string, HOM_ElemPtr<HOM_Node> > result; 00033 * for (...) 00034 * result.insert(std::make_pair("...", new HOMF_Node(...))); 00035 * return result; 00036 * } 00037 * 00038 * When swig converts the std::vector into a python object, it will 00039 * create a python tuple and add the elements inside the vector into 00040 * the tuple. When it converts a HOM_ElemPtr<T> element inside the 00041 * vector, it will just wrap the pointer to the T object, and the 00042 * wrapped object will take ownership of the T. 00043 */ 00044 00045 #ifndef __HOM_ElemPtr_h__ 00046 #define __HOM_ElemPtr_h__ 00047 00048 template <typename T> 00049 class HOM_ElemPtr 00050 { 00051 public: 00052 HOM_ElemPtr(T *pointer = NULL) 00053 : myPointer(pointer) 00054 {} 00055 00056 // We need a less than comparator function if we want HOM_ElemPtr<T> 00057 // objects to be used as keys in std::maps. 00058 bool operator<(const HOM_ElemPtr<T> &otherElem) const 00059 throw(HOM_ObjectWasDeleted, HOM_Error) 00060 { return myPointer < otherElem.myPointer; } 00061 00062 T *myPointer; 00063 }; 00064 00065 #ifdef SWIG 00066 // This macro adds a typemap to convert from HOM_ElemPtr<ElemType> into 00067 // swig interpreter objects. The interpreter object will own the pointer to 00068 // ElemType. 00069 %define %add_elem_ptr_typemap(ElemType...) 00070 %typemap(out) HOM_ElemPtr<ElemType> { 00071 $result = SWIG_NewPointerObj($1.myPointer, SWIGTYPE_p_ ## ElemType, 00072 SWIG_POINTER_OWN | $owner); 00073 } 00074 00075 // For whatever reason, adding the typemap does not customize swig::from(), 00076 // so we do that manually. 00077 %{ 00078 namespace swig { 00079 template <> 00080 struct traits_from<HOM_ElemPtr<ElemType > > 00081 { 00082 static PyObject *from(const HOM_ElemPtr<ElemType > &val) 00083 { 00084 return HOMconvertValueForInterpreter(val.myPointer, 00085 SWIG_POINTER_OWN); 00086 } 00087 }; 00088 } 00089 %} 00090 %enddef 00091 #endif 00092 00093 #endif
1.5.9