Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / wtf / VectorTraits.h
1 /*
2  * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
3  *
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.
8  *
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.
13  *
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.
18  *
19  */
20
21 #ifndef WTF_VectorTraits_h
22 #define WTF_VectorTraits_h
23
24 #include "wtf/OwnPtr.h"
25 #include "wtf/RefPtr.h"
26 #include "wtf/TypeTraits.h"
27 #include <utility>
28
29 using std::pair;
30
31 namespace WTF {
32
33     class AtomicString;
34
35     template<typename T>
36     struct VectorTraitsBase
37     {
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;
47     };
48
49     template<typename T>
50     struct VectorTraits : VectorTraitsBase<T> { };
51
52     template<typename T>
53     struct SimpleClassVectorTraits : VectorTraitsBase<T>
54     {
55         static const bool canInitializeWithMemset = true;
56         static const bool canMoveWithMemcpy = true;
57         static const bool canCompareWithMemcmp = true;
58     };
59
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
62     // work.
63     template<typename P>
64     struct VectorTraits<RefPtr<P> > : SimpleClassVectorTraits<RefPtr<P> > { };
65
66     template<typename P>
67     struct VectorTraits<OwnPtr<P> > : SimpleClassVectorTraits<OwnPtr<P> > { };
68
69     template<typename First, typename Second>
70     struct VectorTraits<pair<First, Second> >
71     {
72         typedef VectorTraits<First> FirstTraits;
73         typedef VectorTraits<Second> SecondTraits;
74
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;
84     };
85
86 } // namespace WTF
87
88 using WTF::VectorTraits;
89 using WTF::SimpleClassVectorTraits;
90
91 #endif // WTF_VectorTraits_h