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
00024 #ifndef ARRAY_H
00025 #define ARRAY_H
00026
00027 #ifndef USE_PCH
00028 #endif
00029
00030 #include "Color.h"
00031 #include "Index.h"
00032
00033 #define DEBUG_ARRAY_RANGE_CHECK 0
00034
00035 #if DEBUG_ARRAY_RANGE_CHECK
00036 #include <cassert>
00037 #endif
00038
00039 namespace cwchess {
00040
00041 template<typename T>
00042 struct ArrayCode {
00043 T M_array[16];
00044
00045 T& operator[](Code const& code)
00046 {
00047 #if DEBUG_ARRAY_RANGE_CHECK
00048 assert(code() < 16);
00049 #endif
00050 return M_array[code()];
00051 }
00052 T const& operator[](Code const& code) const
00053 {
00054 #if DEBUG_ARRAY_RANGE_CHECK
00055 assert(code() < 16);
00056 #endif
00057 return M_array[code()];
00058 }
00059
00060 T& operator[](Color const& color)
00061 {
00062 #if DEBUG_ARRAY_RANGE_CHECK
00063 assert(color() == 0 || color() == 8);
00064 #endif
00065 return M_array[color()];
00066 }
00067 T const& operator[](Color const& color) const
00068 {
00069 #if DEBUG_ARRAY_RANGE_CHECK
00070 assert(color() == 0 || color() == 8);
00071 #endif
00072 return M_array[color()];
00073 }
00074 };
00075
00076 template<typename T>
00077 struct ArrayColor {
00078 T M_array[2];
00079
00080 T& operator[](Code const& code)
00081 {
00082 #if DEBUG_ARRAY_RANGE_CHECK
00083 assert(code() < 16);
00084 #endif
00085 return M_array[code() >> 3];
00086 }
00087 T const& operator[](Code const& code) const
00088 {
00089 #if DEBUG_ARRAY_RANGE_CHECK
00090 assert(code() < 16);
00091 #endif
00092 return M_array[code() >> 3];
00093 }
00094
00095 T& operator[](Color const& color)
00096 {
00097 #if DEBUG_ARRAY_RANGE_CHECK
00098 assert(color.index() < 2);
00099 #endif
00100 return M_array[color.index()];
00101 }
00102 T const& operator[](Color const& color) const
00103 {
00104 #if DEBUG_ARRAY_RANGE_CHECK
00105 assert(color.index() < 2);
00106 #endif
00107 return M_array[color.index()];
00108 }
00109 };
00110
00111 template<typename T>
00112 struct ArrayIndex {
00113 T M_array[64];
00114
00115 T& operator[](Index const& index)
00116 {
00117 #if DEBUG_ARRAY_RANGE_CHECK
00118 assert(index() < 64);
00119 #endif
00120 return M_array[index()];
00121 }
00122 T const& operator[](Index const& index) const
00123 {
00124 #if DEBUG_ARRAY_RANGE_CHECK
00125 assert(index() < 64);
00126 #endif
00127 return M_array[index()];
00128 }
00129 };
00130
00131 }
00132
00133 #endif // ARRAY_H