00001 //---------------------------------------------------------------------------- 00002 /** @file SgEBWArray.h 00003 Arrays indexed by color. */ 00004 //---------------------------------------------------------------------------- 00005 00006 #ifndef SG_EBWARRAY_H 00007 #define SG_EBWARRAY_H 00008 00009 #include "SgBoardColor.h" 00010 00011 //---------------------------------------------------------------------------- 00012 00013 /** An array of three values of type T, indexed by SG_EMPTY, SG_BLACK and 00014 SG_WHITE. 00015 Stores index SG_EMPTY (=4) at array[0]. */ 00016 template <class T> 00017 class SgEBWArray 00018 { 00019 public: 00020 /** Constructor. 00021 Constructs elements with the default constructor of type T. 00022 @note Previously, EBWArray automatically initialized primitive types 00023 like ints or pointers with 0, and there was a second class 00024 EBWConstrArray used for non-primitive types. This has changed, 00025 because it is not the standard semantics for container classes in C++, 00026 and because it does not allow use cases with incremental 00027 initialization after construction. If you want to initialize for 00028 example an SgBWArray<int> with 0, use the constructor that takes a 00029 default value. */ 00030 SgEBWArray() 00031 { 00032 } 00033 00034 SgEBWArray(const T& val) 00035 { 00036 m_array[SG_BLACK] = val; 00037 m_array[SG_WHITE] = val; 00038 m_array[SG_EMPTY] = val; 00039 } 00040 00041 SgEBWArray(const T& empty, const T& black, const T& white) 00042 { 00043 m_array[SG_BLACK] = black; 00044 m_array[SG_WHITE] = white; 00045 m_array[SG_EMPTY] = empty; 00046 } 00047 00048 const T& operator[](SgEmptyBlackWhite c) const 00049 { 00050 SG_ASSERT_EBW(c); 00051 return m_array[c]; 00052 } 00053 00054 T& operator[](SgEmptyBlackWhite c) 00055 { 00056 SG_ASSERT_EBW(c); 00057 return m_array[c]; 00058 } 00059 00060 private: 00061 T m_array[3]; 00062 }; 00063 00064 //---------------------------------------------------------------------------- 00065 00066 #endif // SG_EBWARRAY_H