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
24 #include "wtf/OwnPtr.h"
25 #include "wtf/RefPtr.h"
26 #include "wtf/TypeTraits.h"
36 struct VectorTraitsBase
38 static const bool needsDestruction = !IsPod<T>::value;
39 static const bool needsInitialization = !IsPod<T>::value;
40 static const bool canInitializeWithMemset = IsPod<T>::value;
41 static const bool canMoveWithMemcpy = IsPod<T>::value;
42 static const bool canCopyWithMemcpy = IsPod<T>::value;
43 static const bool canFillWithMemset = IsPod<T>::value && (sizeof(T) == sizeof(char));
44 static const bool canCompareWithMemcmp = IsPod<T>::value;
45 static const bool needsTracing = NeedsTracing<T>::value;
46 static const bool isWeak = IsWeak<T>::value;
50 struct VectorTraits : VectorTraitsBase<T> { };
53 struct SimpleClassVectorTraits : VectorTraitsBase<T>
55 static const bool canInitializeWithMemset = true;
56 static const bool canMoveWithMemcpy = true;
57 static const bool canCompareWithMemcmp = true;
60 // We know OwnPtr and RefPtr are simple enough that initializing to 0 and
61 // moving with memcpy (and then not destructing the original) will totally
64 struct VectorTraits<RefPtr<P> > : SimpleClassVectorTraits<RefPtr<P> > { };
67 struct VectorTraits<OwnPtr<P> > : SimpleClassVectorTraits<OwnPtr<P> > { };
69 template<typename First, typename Second>
70 struct VectorTraits<pair<First, Second> >
72 typedef VectorTraits<First> FirstTraits;
73 typedef VectorTraits<Second> SecondTraits;
75 static const bool needsDestruction = FirstTraits::needsDestruction || SecondTraits::needsDestruction;
76 static const bool needsInitialization = FirstTraits::needsInitialization || SecondTraits::needsInitialization;
77 static const bool canInitializeWithMemset = FirstTraits::canInitializeWithMemset && SecondTraits::canInitializeWithMemset;
78 static const bool canMoveWithMemcpy = FirstTraits::canMoveWithMemcpy && SecondTraits::canMoveWithMemcpy;
79 static const bool canCopyWithMemcpy = FirstTraits::canCopyWithMemcpy && SecondTraits::canCopyWithMemcpy;
80 static const bool canFillWithMemset = false;
81 static const bool canCompareWithMemcmp = FirstTraits::canCompareWithMemcmp && SecondTraits::canCompareWithMemcmp;
82 static const bool needsTracing = FirstTraits::needsTracing || SecondTraits::needsTracing;
83 static const bool isWeak = FirstTraits::isWeak || SecondTraits::isWeak;
88 using WTF::VectorTraits;
89 using WTF::SimpleClassVectorTraits;
91 #endif // WTF_VectorTraits_h