1 //------------------------------------------------------------------------------ 2 // MessageBoolItemTest.h 3 // 4 //------------------------------------------------------------------------------ 5 6 #ifndef MESSAGEBOOLITEMTEST_H 7 #define MESSAGEBOOLITEMTEST_H 8 9 // Standard Includes ----------------------------------------------------------- 10 11 // System Includes ------------------------------------------------------------- 12 13 // Project Includes ------------------------------------------------------------ 14 15 // Local Includes -------------------------------------------------------------- 16 #include "MessageItemTest.h" 17 18 // Local Defines --------------------------------------------------------------- 19 20 // Globals --------------------------------------------------------------------- 21 22 typedef TMessageItemFuncPolicy 23 < 24 bool, 25 &BMessage::AddBool, 26 &BMessage::FindBool, 27 &BMessage::FindBool, 28 &BMessage::FindBool, 29 &BMessage::HasBool, 30 &BMessage::ReplaceBool 31 > 32 TBoolFuncPolicy; 33 34 template<> 35 struct ArrayTypeBase<bool> 36 { 37 class ArrayType 38 { 39 public: 40 ArrayType() : array(NULL), size(0) {;} 41 ArrayType(const ArrayType& rhs) : array(NULL), size(0) 42 { *this = rhs; } 43 ArrayType(bool* data, uint32 len) : array(NULL), size(0) 44 { Assign(data, len); } 45 ~ArrayType() { if (array) delete[] array; } 46 47 ArrayType& operator=(const ArrayType& rhs) 48 { 49 if (this != &rhs) 50 Assign(rhs.array, rhs.size); 51 return *this; 52 }; 53 54 uint32 Size() { return size; } 55 bool& operator[](int index) 56 { 57 // We're just gonna let a segfault happen 58 return array[index]; 59 } 60 61 private: 62 void Assign(bool* data, uint32 len) 63 { 64 size = len; 65 66 if (array) 67 delete[] array; 68 array = new bool[Size()]; 69 memcpy(array, data, Size()); 70 } 71 bool* array; 72 uint32 size; 73 }; 74 75 typedef uint32 SizeType; 76 static SizeType Size(ArrayType& array) { return array.Size(); } 77 }; 78 79 struct TBoolInitPolicy : public ArrayTypeBase<bool> 80 { 81 inline static bool Zero() { return false; } 82 inline static bool Test1() { return true; } 83 inline static bool Test2() { return false; } 84 inline static size_t SizeOf(const bool&) { return sizeof (bool); } 85 inline static ArrayType Array() 86 { 87 static bool array[] = { true, true, true }; 88 return ArrayType(array, 3); 89 } 90 }; 91 92 //struct TBoolAssertPolicy 93 //{ 94 // inline static bool Zero() { return false; } 95 // inline static bool Invalid() { return false;} 96 //}; 97 typedef TMessageItemAssertPolicy 98 < 99 bool//, 100 // false, 101 // false 102 > 103 TBoolAssertPolicy; 104 105 typedef TMessageItemTest 106 < 107 bool, 108 B_BOOL_TYPE, 109 TBoolFuncPolicy, 110 TBoolInitPolicy, 111 TBoolAssertPolicy 112 > 113 TMessageBoolItemTest; 114 115 #endif // MESSAGEBOOLITEMTEST_H 116 117 /* 118 * $Log $ 119 * 120 * $Id $ 121 * 122 */ 123 124