PageRenderTime 58ms CodeModel.GetById 25ms app.highlight 27ms RepoModel.GetById 1ms 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
  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
 29// Precompiled header
 30#include "linden_common.h"
 31// associated header
 32#include "llptrto.h"
 33// STL headers
 34// std headers
 35// external library headers
 36#include <boost/type_traits/is_same.hpp>
 37#include <boost/static_assert.hpp>
 38// other Linden headers
 39#include "llmemory.h"
 40
 41// a refcounted class
 42class RCFoo: public LLRefCount
 43{
 44public:
 45    RCFoo() {}
 46};
 47
 48// a refcounted subclass
 49class RCSubFoo: public RCFoo
 50{
 51public:
 52    RCSubFoo() {}
 53};
 54
 55// a refcounted class using the other refcount base class
 56class TSRCFoo: public LLThreadSafeRefCount
 57{
 58public:
 59    TSRCFoo() {}
 60};
 61
 62// a non-refcounted class
 63class Bar
 64{
 65public:
 66    Bar() {}
 67};
 68
 69// a non-refcounted subclass
 70class SubBar: public Bar
 71{
 72public:
 73    SubBar() {}
 74};
 75
 76int main(int argc, char *argv[])
 77{
 78    // test LLPtrTo<>
 79    BOOST_STATIC_ASSERT((boost::is_same<LLPtrTo<RCFoo>::type, LLPointer<RCFoo> >::value));
 80    BOOST_STATIC_ASSERT((boost::is_same<LLPtrTo<RCSubFoo>::type, LLPointer<RCSubFoo> >::value));
 81    BOOST_STATIC_ASSERT((boost::is_same<LLPtrTo<TSRCFoo>::type, LLPointer<TSRCFoo> >::value));
 82    BOOST_STATIC_ASSERT((boost::is_same<LLPtrTo<Bar>::type, Bar*>::value));
 83    BOOST_STATIC_ASSERT((boost::is_same<LLPtrTo<SubBar>::type, SubBar*>::value));
 84    BOOST_STATIC_ASSERT((boost::is_same<LLPtrTo<int>::type, int*>::value));
 85
 86    // Test LLRemovePointer<>. Note that we remove both pointer variants from
 87    // each kind of type, regardless of whether the variant makes sense.
 88    BOOST_STATIC_ASSERT((boost::is_same<LLRemovePointer<RCFoo*>::type, RCFoo>::value));
 89    BOOST_STATIC_ASSERT((boost::is_same<LLRemovePointer< LLPointer<RCFoo> >::type, RCFoo>::value));
 90    BOOST_STATIC_ASSERT((boost::is_same<LLRemovePointer<RCSubFoo*>::type, RCSubFoo>::value));
 91    BOOST_STATIC_ASSERT((boost::is_same<LLRemovePointer< LLPointer<RCSubFoo> >::type, RCSubFoo>::value));
 92    BOOST_STATIC_ASSERT((boost::is_same<LLRemovePointer<TSRCFoo*>::type, TSRCFoo>::value));
 93    BOOST_STATIC_ASSERT((boost::is_same<LLRemovePointer< LLPointer<TSRCFoo> >::type, TSRCFoo>::value));
 94    BOOST_STATIC_ASSERT((boost::is_same<LLRemovePointer<Bar*>::type, Bar>::value));
 95    BOOST_STATIC_ASSERT((boost::is_same<LLRemovePointer< LLPointer<Bar> >::type, Bar>::value));
 96    BOOST_STATIC_ASSERT((boost::is_same<LLRemovePointer<SubBar*>::type, SubBar>::value));
 97    BOOST_STATIC_ASSERT((boost::is_same<LLRemovePointer< LLPointer<SubBar> >::type, SubBar>::value));
 98    BOOST_STATIC_ASSERT((boost::is_same<LLRemovePointer<int*>::type, int>::value));
 99    BOOST_STATIC_ASSERT((boost::is_same<LLRemovePointer< LLPointer<int> >::type, int>::value));
100
101    return 0;
102}