PageRenderTime 16ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/llcommon/llptrto.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 102 lines | 52 code | 9 blank | 41 comment | 0 complexity | c1c68979b76adfff808d3876ad7cb8c5 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llptrto.cpp
  3. * @author Nat Goodspeed
  4. * @date 2008-08-20
  5. * @brief Test for llptrto.h
  6. *
  7. * $LicenseInfo:firstyear=2008&license=viewerlgpl$
  8. * Second Life Viewer Source Code
  9. * Copyright (C) 2010, Linden Research, Inc.
  10. *
  11. * This library is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU Lesser General Public
  13. * License as published by the Free Software Foundation;
  14. * version 2.1 of the License only.
  15. *
  16. * This library is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  19. * Lesser General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Lesser General Public
  22. * License along with this library; if not, write to the Free Software
  23. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  24. *
  25. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  26. * $/LicenseInfo$
  27. */
  28. // Precompiled header
  29. #include "linden_common.h"
  30. // associated header
  31. #include "llptrto.h"
  32. // STL headers
  33. // std headers
  34. // external library headers
  35. #include <boost/type_traits/is_same.hpp>
  36. #include <boost/static_assert.hpp>
  37. // other Linden headers
  38. #include "llmemory.h"
  39. // a refcounted class
  40. class RCFoo: public LLRefCount
  41. {
  42. public:
  43. RCFoo() {}
  44. };
  45. // a refcounted subclass
  46. class RCSubFoo: public RCFoo
  47. {
  48. public:
  49. RCSubFoo() {}
  50. };
  51. // a refcounted class using the other refcount base class
  52. class TSRCFoo: public LLThreadSafeRefCount
  53. {
  54. public:
  55. TSRCFoo() {}
  56. };
  57. // a non-refcounted class
  58. class Bar
  59. {
  60. public:
  61. Bar() {}
  62. };
  63. // a non-refcounted subclass
  64. class SubBar: public Bar
  65. {
  66. public:
  67. SubBar() {}
  68. };
  69. int main(int argc, char *argv[])
  70. {
  71. // test LLPtrTo<>
  72. BOOST_STATIC_ASSERT((boost::is_same<LLPtrTo<RCFoo>::type, LLPointer<RCFoo> >::value));
  73. BOOST_STATIC_ASSERT((boost::is_same<LLPtrTo<RCSubFoo>::type, LLPointer<RCSubFoo> >::value));
  74. BOOST_STATIC_ASSERT((boost::is_same<LLPtrTo<TSRCFoo>::type, LLPointer<TSRCFoo> >::value));
  75. BOOST_STATIC_ASSERT((boost::is_same<LLPtrTo<Bar>::type, Bar*>::value));
  76. BOOST_STATIC_ASSERT((boost::is_same<LLPtrTo<SubBar>::type, SubBar*>::value));
  77. BOOST_STATIC_ASSERT((boost::is_same<LLPtrTo<int>::type, int*>::value));
  78. // Test LLRemovePointer<>. Note that we remove both pointer variants from
  79. // each kind of type, regardless of whether the variant makes sense.
  80. BOOST_STATIC_ASSERT((boost::is_same<LLRemovePointer<RCFoo*>::type, RCFoo>::value));
  81. BOOST_STATIC_ASSERT((boost::is_same<LLRemovePointer< LLPointer<RCFoo> >::type, RCFoo>::value));
  82. BOOST_STATIC_ASSERT((boost::is_same<LLRemovePointer<RCSubFoo*>::type, RCSubFoo>::value));
  83. BOOST_STATIC_ASSERT((boost::is_same<LLRemovePointer< LLPointer<RCSubFoo> >::type, RCSubFoo>::value));
  84. BOOST_STATIC_ASSERT((boost::is_same<LLRemovePointer<TSRCFoo*>::type, TSRCFoo>::value));
  85. BOOST_STATIC_ASSERT((boost::is_same<LLRemovePointer< LLPointer<TSRCFoo> >::type, TSRCFoo>::value));
  86. BOOST_STATIC_ASSERT((boost::is_same<LLRemovePointer<Bar*>::type, Bar>::value));
  87. BOOST_STATIC_ASSERT((boost::is_same<LLRemovePointer< LLPointer<Bar> >::type, Bar>::value));
  88. BOOST_STATIC_ASSERT((boost::is_same<LLRemovePointer<SubBar*>::type, SubBar>::value));
  89. BOOST_STATIC_ASSERT((boost::is_same<LLRemovePointer< LLPointer<SubBar> >::type, SubBar>::value));
  90. BOOST_STATIC_ASSERT((boost::is_same<LLRemovePointer<int*>::type, int>::value));
  91. BOOST_STATIC_ASSERT((boost::is_same<LLRemovePointer< LLPointer<int> >::type, int>::value));
  92. return 0;
  93. }