WTF
VectorTraits.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef WTF_VectorTraits_h
00024 #define WTF_VectorTraits_h
00025
00026 #include "RefPtr.h"
00027 #include <utility>
00028
00029 using std::pair;
00030
00031 namespace WTF {
00032
00033 template <typename T> struct IsPod { static const bool value = false; };
00034 template <> struct IsPod<bool> { static const bool value = true; };
00035 template <> struct IsPod<char> { static const bool value = true; };
00036 template <> struct IsPod<signed char> { static const bool value = true; };
00037 template <> struct IsPod<unsigned char> { static const bool value = true; };
00038 template <> struct IsPod<short> { static const bool value = true; };
00039 template <> struct IsPod<unsigned short> { static const bool value = true; };
00040 template <> struct IsPod<int> { static const bool value = true; };
00041 template <> struct IsPod<unsigned int> { static const bool value = true; };
00042 template <> struct IsPod<long> { static const bool value = true; };
00043 template <> struct IsPod<unsigned long> { static const bool value = true; };
00044 template <> struct IsPod<long long> { static const bool value = true; };
00045 template <> struct IsPod<unsigned long long> { static const bool value = true; };
00046 template <> struct IsPod<float> { static const bool value = true; };
00047 template <> struct IsPod<double> { static const bool value = true; };
00048 template <> struct IsPod<long double> { static const bool value = true; };
00049 template <typename P> struct IsPod<P *> { static const bool value = true; };
00050
00051 template<bool isPod, typename T>
00052 struct VectorTraitsBase;
00053
00054 template<typename T>
00055 struct VectorTraitsBase<false, T>
00056 {
00057 static const bool needsDestruction = true;
00058 static const bool needsInitialization = true;
00059 static const bool canInitializeWithMemset = false;
00060 static const bool canMoveWithMemcpy = false;
00061 static const bool canCopyWithMemcpy = false;
00062 static const bool canFillWithMemset = false;
00063 };
00064
00065 template<typename T>
00066 struct VectorTraitsBase<true, T>
00067 {
00068 static const bool needsDestruction = false;
00069 static const bool needsInitialization = false;
00070 static const bool canInitializeWithMemset = false;
00071 static const bool canMoveWithMemcpy = true;
00072 static const bool canCopyWithMemcpy = true;
00073 static const bool canFillWithMemset = sizeof(T) == sizeof(char);
00074 };
00075
00076 template<typename T>
00077 struct VectorTraits : VectorTraitsBase<IsPod<T>::value, T> { };
00078
00079 struct SimpleClassVectorTraits
00080 {
00081 static const bool needsDestruction = true;
00082 static const bool needsInitialization = true;
00083 static const bool canInitializeWithMemset = true;
00084 static const bool canMoveWithMemcpy = true;
00085 static const bool canCopyWithMemcpy = false;
00086 static const bool canFillWithMemset = false;
00087 };
00088
00089
00090
00091 template<typename P>
00092 struct VectorTraits<RefPtr<P> > : SimpleClassVectorTraits { };
00093
00094 template<typename First, typename Second>
00095 struct VectorTraits<pair<First, Second> >
00096 {
00097 typedef VectorTraits<First> FirstTraits;
00098 typedef VectorTraits<Second> SecondTraits;
00099
00100 static const bool needsDestruction = FirstTraits::needsDestruction || SecondTraits::needsDestruction;
00101 static const bool needsInitialization = FirstTraits::needsInitialization || SecondTraits::needsInitialization;
00102 static const bool canInitializeWithMemset = FirstTraits::canInitializeWithMemset && SecondTraits::canInitializeWithMemset;
00103 static const bool canMoveWithMemcpy = FirstTraits::canMoveWithMemcpy && SecondTraits::canMoveWithMemcpy;
00104 static const bool canCopyWithMemcpy = FirstTraits::canCopyWithMemcpy && SecondTraits::canCopyWithMemcpy;
00105 static const bool canFillWithMemset = false;
00106 };
00107
00108 }
00109
00110 using WTF::VectorTraits;
00111 using WTF::SimpleClassVectorTraits;
00112
00113 #endif // WTF_VectorTraits_h