HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
HOM_ElemPtr.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * COMMENTS:
7  * This class is used to tell swig that it should take ownership of
8  * the items inside a std::vector. (There is no way with %newobject
9  * to say that the items inside a vector are dynamically allocated.)
10  *
11  * Use this class as follows:
12  *
13  * std::vector<HOM_ElemPtr<HOM_Node> > returnTupleOfNodes()
14  * {
15  * std::vector<HOM_ElemPtr<HOM_Node> > result;
16  * for (...)
17  * result.push_back(new HOMF_OpNode(...));
18  * return result;
19  * }
20  *
21  * or
22  *
23  * std::map<std::string, HOM_ElemPtr<HOM_Node> > returnDictOfNodes()
24  * {
25  * std::map<std::string, HOM_ElemPtr<HOM_Node> > result;
26  * for (...)
27  * result.insert(std::make_pair("...", new HOMF_OpNode(...)));
28  * return result;
29  * }
30  *
31  * When swig converts the std::vector into a python object, it will
32  * create a python tuple and add the elements inside the vector into
33  * the tuple. When it converts a HOM_ElemPtr<T> element inside the
34  * vector, it will just wrap the pointer to the T object, and the
35  * wrapped object will take ownership of the T.
36  */
37 
38 #ifndef __HOM_ElemPtr_h__
39 #define __HOM_ElemPtr_h__
40 
41 #include "HOM_Errors.h"
42 
43 template <typename T>
45 {
46 public:
49  {}
50 
51  // We need a less than comparator function if we want HOM_ElemPtr<T>
52  // objects to be used as keys in std::maps.
53  bool operator<(const HOM_ElemPtr<T> &otherElem) const
54  { return myPointer < otherElem.myPointer; }
55 
57 };
58 
59 #ifdef SWIG
60 // This macro adds a typemap to convert from HOM_ElemPtr<ElemType> into
61 // swig interpreter objects. The interpreter object will own the pointer to
62 // ElemType.
63 %define %add_elem_ptr_typemap(ElemType...)
64 %typemap(out) HOM_ElemPtr<ElemType> {
65  $result = SWIG_NewPointerObj($1.myPointer, SWIGTYPE_p_ ## ElemType,
66  SWIG_POINTER_OWN | $owner);
67 }
68 
69 // For whatever reason, adding the typemap does not customize swig::from(),
70 // so we do that manually.
71 %{
72 namespace swig {
73  template <>
74  struct traits_from<HOM_ElemPtr<ElemType > >
75  {
76  static PyObject *from(const HOM_ElemPtr<ElemType > &val)
77  {
78  // Guard exceptions here that are normally for python. This is
79  // similar to what we do with HOM_CONVERT_AND_CATCH code in
80  // HOM_Defines.h
81  PyObject *result;
82  try
83  {
84  result = HOMconvertValueForInterpreter(val.myPointer,
85  SWIG_POINTER_OWN);
86  }
87  catch (...)
88  {
89  // Unlike HOM_CONVERT_AND_CATCH, we can't raise a SWIG exception
90  // here because it will be ignored anyways in the list
91  // conversion code. Plus, we'll also run into an assertion
92  // failure inside the Python interpreter if we do this:
93  // (void)hom::raise_swig_exception();
94  result = Py_None;
95  }
96  return result;
97  }
98  };
99 }
100 %}
101 %enddef
102 #endif
103 
104 #endif
HOM_ElemPtr(T *pointer=NULL)
Definition: HOM_ElemPtr.h:47
**But if you need a result
Definition: thread.h:613
GLenum void ** pointer
Definition: glcorearb.h:810
GLuint GLfloat * val
Definition: glcorearb.h:1608