ptr.hpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #ifndef PTR_DWA20020601_HPP
  2. # define PTR_DWA20020601_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 (jaakko.jarvi@cs.utu.fi)
  11. // Copyright (C) 2001 Peter Dimov
  12. # pragma once
  13. # include <boost/config.hpp>
  14. # include <boost/mpl/bool.hpp>
  15. namespace boost { namespace python {
  16. template<class Ptr> class pointer_wrapper
  17. {
  18. public:
  19. typedef Ptr type;
  20. explicit pointer_wrapper(Ptr x): p_(x) {}
  21. operator Ptr() const { return p_; }
  22. Ptr get() const { return p_; }
  23. private:
  24. Ptr p_;
  25. };
  26. template<class T>
  27. inline pointer_wrapper<T> ptr(T t)
  28. {
  29. return pointer_wrapper<T>(t);
  30. }
  31. template<typename T>
  32. class is_pointer_wrapper
  33. : public mpl::false_
  34. {
  35. };
  36. template<typename T>
  37. class is_pointer_wrapper<pointer_wrapper<T> >
  38. : public mpl::true_
  39. {
  40. };
  41. template<typename T>
  42. class unwrap_pointer
  43. {
  44. public:
  45. typedef T type;
  46. };
  47. template<typename T>
  48. class unwrap_pointer<pointer_wrapper<T> >
  49. {
  50. public:
  51. typedef T type;
  52. };
  53. }} // namespace boost::python
  54. #endif // #ifndef PTR_DWA20020601_HPP