PageRenderTime 45ms CodeModel.GetById 32ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 1ms

/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
 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
31#if ! defined(LL_LLPTRTO_H)
32#define LL_LLPTRTO_H
33
34#include "llpointer.h"
35#include "llrefcount.h"             // LLRefCount
36#include "llthread.h"               // LLThreadSafeRefCount
37#include <boost/type_traits/is_base_of.hpp>
38#include <boost/type_traits/remove_pointer.hpp>
39#include <boost/utility/enable_if.hpp>
40
41/**
42 * LLPtrTo<TARGET>::type is either of two things:
43 *
44 * * When TARGET is a subclass of either LLRefCount or LLThreadSafeRefCount,
45 *   LLPtrTo<TARGET>::type is LLPointer<TARGET>.
46 * * Otherwise, LLPtrTo<TARGET>::type is TARGET*.
47 *
48 * This way, a class template can use LLPtrTo<TARGET>::type to select an
49 * appropriate pointer type to store.
50 */
51template <class T, class ENABLE=void>
52struct LLPtrTo
53{
54    typedef T* type;
55};
56
57/// specialize for subclasses of LLRefCount
58template <class T>
59struct LLPtrTo<T, typename boost::enable_if< boost::is_base_of<LLRefCount, T> >::type>
60{
61    typedef LLPointer<T> type;
62};
63
64/// specialize for subclasses of LLThreadSafeRefCount
65template <class T>
66struct LLPtrTo<T, typename boost::enable_if< boost::is_base_of<LLThreadSafeRefCount, T> >::type>
67{
68    typedef LLPointer<T> type;
69};
70
71/**
72 * LLRemovePointer<PTRTYPE>::type gets you the underlying (pointee) type.
73 */
74template <typename PTRTYPE>
75struct LLRemovePointer
76{
77    typedef typename boost::remove_pointer<PTRTYPE>::type type;
78};
79
80/// specialize for LLPointer<SOMECLASS>
81template <typename SOMECLASS>
82struct LLRemovePointer< LLPointer<SOMECLASS> >
83{
84    typedef SOMECLASS type;
85};
86
87#endif /* ! defined(LL_LLPTRTO_H) */