]>
git.saurik.com Git - apple/javascriptcore.git/blob - wtf/VectorTraits.h
2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
21 #ifndef WTF_VectorTraits_h
22 #define WTF_VectorTraits_h
26 #include "TypeTraits.h"
34 template<bool isPod
, typename T
>
35 struct VectorTraitsBase
;
38 struct VectorTraitsBase
<false, T
>
40 static const bool needsDestruction
= true;
41 static const bool needsInitialization
= true;
42 static const bool canInitializeWithMemset
= false;
43 static const bool canMoveWithMemcpy
= false;
44 static const bool canCopyWithMemcpy
= false;
45 static const bool canFillWithMemset
= false;
46 static const bool canCompareWithMemcmp
= false;
50 struct VectorTraitsBase
<true, T
>
52 static const bool needsDestruction
= false;
53 static const bool needsInitialization
= false;
54 static const bool canInitializeWithMemset
= false;
55 static const bool canMoveWithMemcpy
= true;
56 static const bool canCopyWithMemcpy
= true;
57 static const bool canFillWithMemset
= sizeof(T
) == sizeof(char);
58 static const bool canCompareWithMemcmp
= true;
62 struct VectorTraits
: VectorTraitsBase
<IsPod
<T
>::value
, T
> { };
64 struct SimpleClassVectorTraits
66 static const bool needsDestruction
= true;
67 static const bool needsInitialization
= true;
68 static const bool canInitializeWithMemset
= true;
69 static const bool canMoveWithMemcpy
= true;
70 static const bool canCopyWithMemcpy
= false;
71 static const bool canFillWithMemset
= false;
72 static const bool canCompareWithMemcmp
= true;
75 // we know OwnPtr and RefPtr are simple enough that initializing to 0 and moving with memcpy
76 // (and then not destructing the original) will totally work
78 struct VectorTraits
<RefPtr
<P
> > : SimpleClassVectorTraits
{ };
81 struct VectorTraits
<OwnPtr
<P
> > : SimpleClassVectorTraits
{ };
84 struct VectorTraits
<std::auto_ptr
<P
> > : SimpleClassVectorTraits
{ };
86 template<typename First
, typename Second
>
87 struct VectorTraits
<pair
<First
, Second
> >
89 typedef VectorTraits
<First
> FirstTraits
;
90 typedef VectorTraits
<Second
> SecondTraits
;
92 static const bool needsDestruction
= FirstTraits::needsDestruction
|| SecondTraits::needsDestruction
;
93 static const bool needsInitialization
= FirstTraits::needsInitialization
|| SecondTraits::needsInitialization
;
94 static const bool canInitializeWithMemset
= FirstTraits::canInitializeWithMemset
&& SecondTraits::canInitializeWithMemset
;
95 static const bool canMoveWithMemcpy
= FirstTraits::canMoveWithMemcpy
&& SecondTraits::canMoveWithMemcpy
;
96 static const bool canCopyWithMemcpy
= FirstTraits::canCopyWithMemcpy
&& SecondTraits::canCopyWithMemcpy
;
97 static const bool canFillWithMemset
= false;
98 static const bool canCompareWithMemcmp
= FirstTraits::canCompareWithMemcmp
&& SecondTraits::canCompareWithMemcmp
;
103 using WTF::VectorTraits
;
104 using WTF::SimpleClassVectorTraits
;
106 #endif // WTF_VectorTraits_h