7#ifndef PXR_BASE_TF_PY_SINGLETON_H
8#define PXR_BASE_TF_PY_SINGLETON_H
12#include "pxr/base/tf/api.h"
19#include "pxr/external/boost/python/def_visitor.hpp"
20#include "pxr/external/boost/python/raw_function.hpp"
24PXR_NAMESPACE_OPEN_SCOPE
26namespace Tf_PySingleton {
28namespace bp = pxr_boost::python;
31bp::object _DummyInit(bp::tuple
const & ,
36 return TfCreateWeakPtr(&t);
42 return TfConst_cast<TfWeakPtr<T> >(TfCreateWeakPtr(&t));
50template <
typename PtrType>
51PtrType _GetSingletonWeakPtr(bp::object
const & ) {
52 typedef typename PtrType::DataType Singleton;
53 return GetWeakPtr(Singleton::GetInstance());
57std::string _Repr(bp::object
const &self, std::string
const &prefix);
59struct Visitor : bp::def_visitor<Visitor> {
62 friend class bp::def_visitor_access;
63 template <
typename CLS>
64 void visit(CLS &c)
const {
65 typedef typename CLS::metadata::held_type PtrType;
71 c.def(
"__new__", _GetSingletonWeakPtr<PtrType>).staticmethod(
"__new__");
73 c.def(
"__init__", bp::raw_function(_DummyInit));
80Tf_PySingleton::Visitor TfPySingleton();
82PXR_NAMESPACE_CLOSE_SCOPE
Miscellaneous Utilities for dealing with script.
Pointer storage with deletion detection.
Enables wrapping of Weak or Ref & Weak held types to python.
Manage a single instance of an object.
Pointer storage with deletion detection.