ptr.hpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #ifndef BOOST_PYTHON_PTR_HPP
  2. # define BOOST_PYTHON_PTR_HPP
  3. # include <boost/python/detail/prefix.hpp>
  4. // Copyright David Abrahams 2002.
  5. // Distributed under the Boost Software License, Version 1.0. (See
  6. // accompanying file LICENSE_1_0.txt or copy at
  7. // http://www.boost.org/LICENSE_1_0.txt)
  8. //
  9. // Based on boost/ref.hpp, thus:
  10. // Copyright (C) 1999, 2000 Jaakko Jarvi ([email protected])
  11. // Copyright (C) 2001 Peter Dimov
  12. # include <boost/config.hpp>
  13. # include <boost/mpl/bool.hpp>
  14. namespace boost { namespace python {
  15. template<class Ptr> class pointer_wrapper
  16. {
  17. public:
  18. typedef Ptr type;
  19. explicit pointer_wrapper(Ptr x): p_(x) {}
  20. operator Ptr() const { return p_; }
  21. Ptr get() const { return p_; }
  22. private:
  23. Ptr p_;
  24. };
  25. template<class T>
  26. inline pointer_wrapper<T> ptr(T t)
  27. {
  28. return pointer_wrapper<T>(t);
  29. }
  30. template<typename T>
  31. class is_pointer_wrapper
  32. : public mpl::false_
  33. {
  34. };
  35. template<typename T>
  36. class is_pointer_wrapper<pointer_wrapper<T> >
  37. : public mpl::true_
  38. {
  39. };
  40. template<typename T>
  41. class unwrap_pointer
  42. {
  43. public:
  44. typedef T type;
  45. };
  46. template<typename T>
  47. class unwrap_pointer<pointer_wrapper<T> >
  48. {
  49. public:
  50. typedef T type;
  51. };
  52. }} // namespace boost::python
  53. #endif