direction.h
Go to the documentation of this file.
00001 #ifndef OSL_DIRECTION_H
00002 #define OSL_DIRECTION_H
00003 #include <cassert>
00004 #include <iosfwd>
00005 
00006 namespace osl
00007 {
00008   enum Direction{
00009     SHORT_DIRECTION_MIN=0,
00010     SHORT8_DIRECTION_MIN=0,
00011     UL=0,
00012     U=1,
00013     UR=2,
00014     L=3,
00015     R=4,
00016     DL=5,
00017     D=6,
00018     DR=7,
00019     SHORT8_DIRECTION_MAX=7,
00020     UUL=8,
00021     UUR=9,
00022     LONG_DIRECTION_MIN=10,
00023     LONG_UL=10,
00024     LONG_U=11,
00025     LONG_UR=12,
00026     LONG_L=13,
00027     LONG_R=14,
00028     LONG_DL=15,
00029     LONG_D=16,
00030     LONG_DR=17,
00031     LONG_DIRECTION_MAX=17,
00032     DIRECTION_MIN=0,
00033     SHORT_DIRECTION_MAX=9,
00034     SHORT_DIRECTION_SIZE=10,
00035     DIRECTION_MAX=17,
00036     DIRECTION_INVALID_VALUE=18,
00037     DIRECTION_SIZE=18
00038   };
00039   
00040   inline bool isShort(Direction d){
00041     return d<=SHORT_DIRECTION_MAX;
00042   }
00043 
00044   inline bool isShort8(Direction d){
00045     return d<=SHORT8_DIRECTION_MAX;
00046   }
00047 
00048   inline bool isLong(Direction d){
00049     return d>=LONG_DIRECTION_MIN;
00050   }
00051 
00052   inline Direction inverseUnsafe(Direction d){
00053     return static_cast<Direction>(7 - d);
00054   }
00055 
00056   inline Direction inverse(Direction d){
00057     assert(isShort8(d) );
00058     return inverseUnsafe(d);
00059   }
00060 
00064   inline Direction primDir(Direction d){
00065     assert(isShort8(d) );
00066     if(d<4) return d;
00067     else return inverse(d);
00068   }
00073   inline Direction primDirUnsafe(Direction d){
00074     if(d<4) return d;
00075     else return inverseUnsafe(d);
00076   }
00077 
00078   bool isValid(Direction d);
00079   
00080   inline Direction longToShort(Direction d){
00081     assert(isLong(d));
00082     return static_cast<Direction>(static_cast<int>(d)-LONG_UL);
00083   }
00084   
00088   inline Direction shortToLong(Direction d){
00089     assert(isShort(d));
00090     return static_cast<Direction>(static_cast<int>(d)+LONG_UL);
00091   }
00092 
00093   inline int dirToMask(Direction dir){
00094     return (1<<static_cast<int>(dir));
00095   }
00096   
00097   std::ostream& operator<<(std::ostream& os,const Direction d);
00098 }
00099 #endif /* OSL_DIRECTION_H */
00100 // ;;; Local Variables:
00101 // ;;; mode:c++
00102 // ;;; c-basic-offset:2
00103 // ;;; End:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines