Index   Main   Namespaces   Classes   Hierarchy   Annotated   Files   Compound   Global   Pages  

SgEBWArray.h

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


17 Jun 2010 Doxygen 1.4.7