PageRenderTime 25ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llcommon/llptrto.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 87 lines | 34 code | 8 blank | 45 comment | 0 complexity | 6746773a9413ee7b447a000537a57202 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llptrto.h
  3. * @author Nat Goodspeed
  4. * @date 2008-08-19
  5. * @brief LLPtrTo<TARGET> is a template helper to pick either TARGET* or -- when
  6. * TARGET is a subclass of LLRefCount or LLThreadSafeRefCount --
  7. * LLPointer<TARGET>. LLPtrTo<> chooses whichever pointer type is best.
  8. *
  9. * $LicenseInfo:firstyear=2008&license=viewerlgpl$
  10. * Second Life Viewer Source Code
  11. * Copyright (C) 2010, Linden Research, Inc.
  12. *
  13. * This library is free software; you can redistribute it and/or
  14. * modify it under the terms of the GNU Lesser General Public
  15. * License as published by the Free Software Foundation;
  16. * version 2.1 of the License only.
  17. *
  18. * This library is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  21. * Lesser General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU Lesser General Public
  24. * License along with this library; if not, write to the Free Software
  25. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  26. *
  27. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  28. * $/LicenseInfo$
  29. */
  30. #if ! defined(LL_LLPTRTO_H)
  31. #define LL_LLPTRTO_H
  32. #include "llpointer.h"
  33. #include "llrefcount.h" // LLRefCount
  34. #include "llthread.h" // LLThreadSafeRefCount
  35. #include <boost/type_traits/is_base_of.hpp>
  36. #include <boost/type_traits/remove_pointer.hpp>
  37. #include <boost/utility/enable_if.hpp>
  38. /**
  39. * LLPtrTo<TARGET>::type is either of two things:
  40. *
  41. * * When TARGET is a subclass of either LLRefCount or LLThreadSafeRefCount,
  42. * LLPtrTo<TARGET>::type is LLPointer<TARGET>.
  43. * * Otherwise, LLPtrTo<TARGET>::type is TARGET*.
  44. *
  45. * This way, a class template can use LLPtrTo<TARGET>::type to select an
  46. * appropriate pointer type to store.
  47. */
  48. template <class T, class ENABLE=void>
  49. struct LLPtrTo
  50. {
  51. typedef T* type;
  52. };
  53. /// specialize for subclasses of LLRefCount
  54. template <class T>
  55. struct LLPtrTo<T, typename boost::enable_if< boost::is_base_of<LLRefCount, T> >::type>
  56. {
  57. typedef LLPointer<T> type;
  58. };
  59. /// specialize for subclasses of LLThreadSafeRefCount
  60. template <class T>
  61. struct LLPtrTo<T, typename boost::enable_if< boost::is_base_of<LLThreadSafeRefCount, T> >::type>
  62. {
  63. typedef LLPointer<T> type;
  64. };
  65. /**
  66. * LLRemovePointer<PTRTYPE>::type gets you the underlying (pointee) type.
  67. */
  68. template <typename PTRTYPE>
  69. struct LLRemovePointer
  70. {
  71. typedef typename boost::remove_pointer<PTRTYPE>::type type;
  72. };
  73. /// specialize for LLPointer<SOMECLASS>
  74. template <typename SOMECLASS>
  75. struct LLRemovePointer< LLPointer<SOMECLASS> >
  76. {
  77. typedef SOMECLASS type;
  78. };
  79. #endif /* ! defined(LL_LLPTRTO_H) */