mobilityTable.h
Go to the documentation of this file.
00001 /* mobilityTable.h
00002  */
00003 #ifndef _MOBILITY_TABLE_H
00004 #define _MOBILITY_TABLE_H
00005 #include "osl/direction.h"
00006 #include "osl/misc/carray.h"
00007 #include "osl/state/simpleState.h"
00008 #include <cassert>
00009 #include <iosfwd>
00010 
00011 namespace osl
00012 {
00013   namespace mobility
00014   {
00015     union V4 {
00016       unsigned int lv;
00017       CArray<unsigned char,4> uc;
00018     }
00019 #ifdef __GNUC__
00020   __attribute__((aligned(4)))
00021 #endif
00022     ;
00030     class MobilityContent
00031     {
00032       V4 v;
00033     public:
00034       MobilityContent() {
00035         clear();
00036       }
00037       void clear(){
00038         v.lv=0u;
00039       }
00040       const Square get(Direction d) const{
00041         return Square::makeDirect(v.uc[((unsigned int)d)>>1]);
00042       }
00043       void set(Direction d,Square pos){
00044         v.uc[((unsigned int)d)>>1]=static_cast<unsigned char>(pos.uintValue());
00045       }
00046     };
00047     std::ostream& operator<<(std::ostream& os,MobilityContent const& mc);
00048 
00052     class MobilityTable
00053     {
00054       CArray<MobilityContent,8> table
00055 #ifdef __GNUC__
00056       __attribute__((aligned(16)))
00057 #endif
00058         ;
00059     public:
00060       MobilityTable(){}
00061       MobilityTable(SimpleState const& state);
00062       void set(Direction d,int num,Square pos){
00063         assert(0<=(int)d && (int)d<=7);
00064         return table[num-32].set(d,pos);
00065       }
00066       const Square get(Direction d,int num) const{
00067         assert(0<=(int)d && (int)d<=7);
00068         return table[num-32].get(d);
00069       }
00070       friend bool operator==(const MobilityTable& mt1,const MobilityTable& mt2);
00071     };
00072     std::ostream& operator<<(std::ostream& os,MobilityTable const& mt);
00073     bool operator==(const MobilityTable&,const MobilityTable&);
00074   }
00075   using mobility::MobilityTable;
00076 }
00077 #endif /* _MOBILITY_TABLE_H */
00078 // ;;; Local Variables:
00079 // ;;; mode:c++
00080 // ;;; c-basic-offset:2
00081 // ;;; End:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines