00001
00002
00003
00004 #ifndef _H_Acd_Id
00005 #define _H_Acd_Id
00006
00007 #include "facilities/bitmanip.h"
00008 #include "idents/ModuleId.h"
00035 namespace idents {
00036 class AcdId {
00037 public:
00038 AcdId ();
00039 AcdId ( const AcdId& );
00040 AcdId ( unsigned int id ) : m_id (id) { }
00041 AcdId (short l, short f, short r, short c);
00042 virtual ~AcdId ();
00043
00044
00045 operator const unsigned int& () const { return m_id; }
00046
00047 void write (std::ostream& out) const
00048 {
00049 out << m_id;
00050 }
00051
00052 void read (std::istream& in)
00053 {
00054 in >> m_id;
00055 }
00056
00057
00059
00061
00063
00065
00067
00069
00071
00072
00073 private:
00075 inline void layer( unsigned int val );
00077 inline void face (unsigned int f);
00079 inline void row( unsigned int r );
00081 inline void column( unsigned int c );
00082
00083 enum {
00084 _layermask = 0x1800,
00085 _facemask = 0x0700,
00086 _rowmask = 0x00F0,
00087 _colmask = 0x000F,
00088 layerShift = 11
00089 };
00090
00091 unsigned int m_id;
00092
00093 };
00094
00095
00096
00097 inline AcdId::AcdId () : m_id (0) {}
00098 inline AcdId::AcdId ( const AcdId& r ) : m_id (r.m_id) {}
00099 inline AcdId::AcdId (short l, short f, short r, short c) {
00100 m_id = 0;
00101 layer(l);
00102 face(f);
00103 row(r);
00104 column(c);
00105 }
00106 inline AcdId::~AcdId () {}
00107
00108 inline unsigned int AcdId::id() const
00109 { return (layer() * 1000 + face() * 100 + row() * 10 + column()); }
00110
00111 inline bool AcdId::top () const
00112 { return (face() == 0); }
00113
00114 inline bool AcdId::side () const
00115 { return (face() != 0); }
00116
00117 inline short AcdId::layer () const
00118 { return (m_id & _layermask) >> layerShift; }
00119
00120 inline short AcdId::face () const
00121 { return bitmanip::word(2, (m_id & _facemask)); }
00122
00123 inline short AcdId::row () const
00124 { return bitmanip::word (1, m_id); }
00125
00126 inline short AcdId::column () const
00127 { return bitmanip::word (0, m_id); }
00128
00129 inline void AcdId::layer( unsigned int val)
00130 {
00131 short two = 2;
00132
00133 bitmanip::set_word<unsigned int>(
00134 two, m_id,
00135 ((val == 0) ? 0 : 8) | ((_facemask & m_id) >> 8) );
00136 }
00137
00138 inline void AcdId::face( unsigned int f )
00139 {
00140 short two = 2;
00141 bitmanip::set_word<unsigned int> (
00142 two, m_id,
00143 f | ((_layermask & m_id ) >> 8) );
00144 }
00145
00146 inline void AcdId::row( unsigned int r )
00147 {
00148 short one = 1;
00149 bitmanip::set_word<unsigned int>( one, m_id, r );
00150 }
00151
00152 inline void AcdId::column( unsigned int c )
00153 {
00154 short zero = 0;
00155 bitmanip::set_word<unsigned int>( zero, m_id, c );
00156 }
00157
00158
00159 inline std::ostream& operator<<(std::ostream& out,const AcdId& id){id.write(out); return out;}
00160 inline std::istream& operator>>(std::istream& in, AcdId& id){id.read(in); return in;}
00161 }
00162
00163 #endif // _H_Acd_Id