All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
pyObjWrapper.h
1 //
2 // Copyright 2016 Pixar
3 //
4 // Licensed under the Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 #ifndef PXR_BASE_TF_PY_OBJ_WRAPPER_H
25 #define PXR_BASE_TF_PY_OBJ_WRAPPER_H
26 
27 #include "pxr/pxr.h"
28 
29 #include "pxr/base/tf/api.h"
30 
31 #include <boost/functional/hash.hpp>
32 #include <boost/python/object_fwd.hpp>
33 #include <boost/python/object_operators.hpp>
34 
35 #include <iosfwd>
36 #include <memory>
37 
38 PXR_NAMESPACE_OPEN_SCOPE
39 
67  : public boost::python::api::object_operators<TfPyObjWrapper>
68 {
69  typedef boost::python::object object;
70 
71 public:
72 
75  TF_API TfPyObjWrapper();
76 
80  TF_API TfPyObjWrapper(object obj);
81 
87  object const &Get() const {
88  return *_objectPtr;
89  }
90 
98  TF_API PyObject *ptr() const;
99 
104  friend inline size_t hash_value(TfPyObjWrapper const &o) {
105  return (size_t) o.ptr();
106  }
107 
110  TF_API bool operator==(TfPyObjWrapper const &other) const;
111 
114  TF_API bool operator!=(TfPyObjWrapper const &other) const;
115 
116 private:
117 
118  // Befriend object_operators to allow it access to implicit conversion to
119  // boost::python::object.
120  friend class boost::python::api::object_operators<TfPyObjWrapper>;
121  operator object const &() const {
122  return Get();
123  }
124 
125  // Store a shared_ptr to a python object.
126  std::shared_ptr<object> _objectPtr;
127 };
128 
129 PXR_NAMESPACE_CLOSE_SCOPE
130 
131 #endif // PXR_BASE_TF_PY_OBJ_WRAPPER_H
TF_API PyObject * ptr() const
Underlying PyObject* access.
TF_API bool operator==(TfPyObjWrapper const &other) const
Equality.
TF_API TfPyObjWrapper()
Default construct a TfPyObjWrapper holding a reference to python None.
TF_API bool operator!=(TfPyObjWrapper const &other) const
Inequality.
object const & Get() const
Underlying object access.
Definition: pyObjWrapper.h:87
friend size_t hash_value(TfPyObjWrapper const &o)
Produce a hash code for this object.
Definition: pyObjWrapper.h:104
Boost Python object wrapper.
Definition: pyObjWrapper.h:66