Go to the documentation of this file.00001
00002
00003
00004
00005
00006 #ifndef cortege_h
00007 #define cortege_h
00008
00009 #include <assert.h>
00010 #include "../common/utilit.h"
00011
00012 const BYTE ErrUChar = 254;
00013
00014 struct TCortege10;
00015
00016 const char _FieldFormat[] = "%-8s= %s";
00017 const char _FieldFormatEqual[] = "%-8s== %s";
00018
00019
00020 template <int MaxNumDom>
00021 struct TBasicCortege {
00022 public:
00023 BYTE m_FieldNo;
00024 BYTE m_SignatNo;
00025 BYTE m_LevelId;
00026 BYTE m_LeafId;
00027 BYTE m_BracketLeafId;
00028 int m_DomItemNos[MaxNumDom];
00029
00030 int GetItem (size_t index) const
00031 {
00032 assert (index<MaxNumDom);
00033 return m_DomItemNos[index];
00034 };
00035 int SetItem (size_t index, long Value)
00036 {
00037 assert (index<MaxNumDom);
00038 return m_DomItemNos[index] = Value;
00039 };
00040
00041 TBasicCortege()
00042 {
00043 for (size_t i=0; i< MaxNumDom;i++)
00044 SetItem(i,-1);
00045 m_SignatNo = 0;
00046 m_FieldNo = ErrUChar;
00047 m_LeafId = 0;
00048 m_BracketLeafId = 0;
00049 };
00050 BYTE GetSignatNo() const
00051 {
00052 return (m_SignatNo & (~128)) ;
00053 };
00054
00055 void SetSignatNo(BYTE SignatNo)
00056 {
00057 m_SignatNo = SignatNo | (128 & m_SignatNo);
00058 };
00059
00060 bool IsEqual() const
00061 {
00062 return (m_SignatNo & 128) > 0 ;
00063 };
00064
00065 void SetEqual()
00066 {
00067 m_SignatNo |= 128;
00068 };
00069 const char* GetFieldFormat() const
00070 {
00071 return IsEqual() ? _FieldFormatEqual : _FieldFormat;
00072
00073 };
00074
00075 bool HasEqualItems(const TBasicCortege& X, BYTE _MaxNumDom) const
00076 {
00077 for (BYTE i=0; i< _MaxNumDom;i++)
00078 if (GetItem(i) != X.GetItem(i))
00079 return false;
00080 return true;
00081 };
00082
00083 bool EqualCortege(const TBasicCortege& X, BYTE _MaxNumDom) const
00084 {
00085 return (m_FieldNo == X.m_FieldNo)
00086 && (m_SignatNo == X.m_SignatNo)
00087 && (m_LevelId == X.m_LevelId)
00088 && (m_LeafId == X.m_LeafId)
00089 && (m_BracketLeafId == X.m_BracketLeafId)
00090 && HasEqualItems (X, _MaxNumDom);
00091 };
00092
00093 bool IsEqualWithWildCard(const TBasicCortege& X, WORD EmptyDomItem, BYTE _MaxNumDom) const
00094 {
00095 if (!( (m_FieldNo == X.m_FieldNo)
00096 && ( (m_LevelId == ErrUChar)
00097 || (X.m_LevelId == ErrUChar)
00098 || (m_LevelId == X.m_LevelId)
00099 )
00100 && ( (m_LeafId == ErrUChar)
00101 || (X.m_LeafId == ErrUChar)
00102 || (m_LeafId == X.m_LeafId)
00103 )
00104 && ( (m_BracketLeafId == ErrUChar)
00105 || (X.m_BracketLeafId == ErrUChar)
00106 || (m_BracketLeafId == X.m_BracketLeafId)
00107 )
00108
00109 )) return false;
00110
00111 for (size_t i=0; i< _MaxNumDom;i++)
00112 if ( (GetItem(i) != X.GetItem(i))
00113 && (GetItem(i) != EmptyDomItem)
00114 && (X.GetItem(i) != EmptyDomItem)
00115 )
00116 return false;
00117
00118 return true;
00119 };
00120
00121 TBasicCortege<MaxNumDom>& operator = (const TBasicCortege<10>& X)
00122 {
00123 m_FieldNo = X.m_FieldNo;
00124 m_LeafId = X.m_LeafId;
00125 m_BracketLeafId = X.m_BracketLeafId;
00126 m_LevelId = X.m_LevelId;
00127 m_SignatNo = X.m_SignatNo;
00128 for (int i =0; i < MaxNumDom; i++)
00129 SetItem(i, X.GetItem(i));
00130
00131 return *this;
00132 };
00133
00134 };
00135
00136
00137 template <int MaxNumDom>
00138 size_t get_size_in_bytes (const TBasicCortege<MaxNumDom>& t)
00139 {
00140
00141 return get_size_in_bytes(t.m_FieldNo)
00142 + get_size_in_bytes(t.m_SignatNo)
00143 + get_size_in_bytes(t.m_LevelId)
00144 + get_size_in_bytes(t.m_LeafId)
00145 + get_size_in_bytes(t.m_BracketLeafId)
00146 + get_size_in_bytes(t.m_DomItemNos[0])*MaxNumDom;
00147 };
00148
00149 template <int MaxNumDom>
00150 size_t save_to_bytes(const TBasicCortege<MaxNumDom>& i, BYTE* buf)
00151 {
00152 buf += save_to_bytes(i.m_FieldNo, buf);
00153 buf += save_to_bytes(i.m_SignatNo, buf);
00154 buf += save_to_bytes(i.m_LevelId, buf);
00155 buf += save_to_bytes(i.m_LeafId, buf);
00156 buf += save_to_bytes(i.m_BracketLeafId, buf);
00157 for (int j = 0; j < MaxNumDom; j++)
00158 buf += save_to_bytes(i.m_DomItemNos[j], buf);
00159
00160 return get_size_in_bytes(i);
00161 };
00162
00163 template <int MaxNumDom>
00164 size_t restore_from_bytes(TBasicCortege<MaxNumDom>& i, const BYTE* buf)
00165 {
00166 buf += restore_from_bytes(i.m_FieldNo, buf);
00167 buf += restore_from_bytes(i.m_SignatNo, buf);
00168 buf += restore_from_bytes(i.m_LevelId, buf);
00169 buf += restore_from_bytes(i.m_LeafId, buf);
00170 buf += restore_from_bytes(i.m_BracketLeafId, buf);
00171 for (int j = 0; j < MaxNumDom; j++)
00172 buf += restore_from_bytes(i.m_DomItemNos[j], buf);
00173 return get_size_in_bytes(i);
00174 };
00175
00176
00177
00178
00179 struct TCortege10 : public TBasicCortege<10>
00180 {
00181 TCortege10()
00182 {
00183 for (size_t i=0; i< 10;i++)
00184 SetItem(i,-1);
00185 m_SignatNo = 0;
00186 m_FieldNo = ErrUChar;
00187 m_LeafId = 0;
00188 m_BracketLeafId = 0;
00189 };
00190
00191 TCortege10 (const TBasicCortege<3>& X)
00192 {
00193 m_FieldNo = X.m_FieldNo;
00194 m_LeafId = X.m_LeafId;
00195 m_BracketLeafId = X.m_BracketLeafId;
00196 m_LevelId = X.m_LevelId;
00197 m_SignatNo = X.m_SignatNo;
00198 for (int i =0; i < 3; i++)
00199 SetItem(i, X.GetItem(i));
00200 };
00201 TCortege10 (const TBasicCortege<10>& X)
00202 {
00203 m_FieldNo = X.m_FieldNo;
00204 m_LeafId = X.m_LeafId;
00205 m_BracketLeafId = X.m_BracketLeafId;
00206 m_LevelId = X.m_LevelId;
00207 m_SignatNo = X.m_SignatNo;
00208 for (int i =0; i < 10; i++)
00209 SetItem(i, X.GetItem(i));
00210 };
00211
00212
00213 };
00214
00215
00216
00217
00218
00219
00220
00221 #endif