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 static const bool canCompareWithMemcmp = false;
00064 };
00065
00066 template<typename T>
00067 struct VectorTraitsBase<true, T>
00068 {
00069 static const bool needsDestruction = false;
00070 static const bool needsInitialization = false;
00071 static const bool canInitializeWithMemset = false;
00072 static const bool canMoveWithMemcpy = true;
00073 static const bool canCopyWithMemcpy = true;
00074 static const bool canFillWithMemset = sizeof(T) == sizeof(char);
00075 static const bool canCompareWithMemcmp = true;
00076 };
00077
00078 template<typename T>
00079 struct VectorTraits : VectorTraitsBase<IsPod<T>::value, T> { };
00080
00081 struct SimpleClassVectorTraits
00082 {
00083 static const bool needsDestruction = true;
00084 static const bool needsInitialization = true;
00085 static const bool canInitializeWithMemset = true;
00086 static const bool canMoveWithMemcpy = true;
00087 static const bool canCopyWithMemcpy = false;
00088 static const bool canFillWithMemset = false;
00089 static const bool canCompareWithMemcmp = true;
00090 };
00091
00092
00093
00094 template<typename P>
00095 struct VectorTraits<RefPtr<P> > : SimpleClassVectorTraits { };
00096
00097 template<typename First, typename Second>
00098 struct VectorTraits<pair<First, Second> >
00099 {
00100 typedef VectorTraits<First> FirstTraits;
00101 typedef VectorTraits<Second> SecondTraits;
00102
00103 static const bool needsDestruction = FirstTraits::needsDestruction || SecondTraits::needsDestruction;
00104 static const bool needsInitialization = FirstTraits::needsInitialization || SecondTraits::needsInitialization;
00105 static const bool canInitializeWithMemset = FirstTraits::canInitializeWithMemset && SecondTraits::canInitializeWithMemset;
00106 static const bool canMoveWithMemcpy = FirstTraits::canMoveWithMemcpy && SecondTraits::canMoveWithMemcpy;
00107 static const bool canCopyWithMemcpy = FirstTraits::canCopyWithMemcpy && SecondTraits::canCopyWithMemcpy;
00108 static const bool canFillWithMemset = false;
00109 static const bool canCompareWithMemcmp = FirstTraits::canCompareWithMemcmp && SecondTraits::canCompareWithMemcmp;
00110 };
00111
00112 }
00113
00114 using WTF::VectorTraits;
00115 using WTF::SimpleClassVectorTraits;
00116
00117 #endif // WTF_VectorTraits_h