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_Node(...));
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_Node(...)));
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  return HOMconvertValueForInterpreter(val.myPointer,
79  SWIG_POINTER_OWN);
80  }
81  };
82 }
83 %}
84 %enddef
85 #endif
86 
87 #endif
HOM_ElemPtr(T *pointer=NULL)
Definition: HOM_ElemPtr.h:47
GLenum void ** pointer
Definition: glcorearb.h:809
GLuint GLfloat * val
Definition: glcorearb.h:1607