ddc
cortege.h
Go to the documentation of this file.
1 //
2 // This file is part of DDC.
3 //
4 // DDC is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Lesser General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // DDC is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Lesser General Public License for more details.
13 //
14 // You should have received a copy of the GNU Lesser General Public License
15 // along with DDC. If not, see <http://www.gnu.org/licenses/>.
16 //
17 // ========== Dialing Structural Dictionary (www.aot.ru)
18 // ========== Copyright by Alexey Sokirko (1998-2002), Bryan Jurish (2011)
19 
20 
21 #ifndef cortege_h
22 #define cortege_h
23 
24 #include "utilit.h"
25 #include <assert.h>
26 
27 const BYTE ErrUChar = 254;
28 
29 struct TCortege10;
30 
31 const char _FieldFormat[] = "%-8s= %s";
32 const char _FieldFormatEqual[] = "%-8s== %s";
33 
34 
35 template <int MaxNumDom>
36 struct TBasicCortege {
37 public:
38  BYTE m_FieldNo; // reference to Ross :: Fields
39  BYTE m_SignatNo; // reference to Ross :: Fields[FunNo].m_Signats
43  int m_DomItemNos[MaxNumDom];
44 
45  int GetItem (size_t index) const
46  {
47  assert (index<MaxNumDom);
48  return m_DomItemNos[index];
49  };
50  int SetItem (size_t index, long Value)
51  {
52  assert (index<MaxNumDom);
53  return m_DomItemNos[index] = Value;
54  };
55 
57  {
58  for (size_t i=0; i< MaxNumDom;i++)
59  SetItem(i,-1);
60  m_SignatNo = 0;
61  m_FieldNo = ErrUChar;
62  m_LeafId = 0;
63  m_BracketLeafId = 0;
64  };
65  BYTE GetSignatNo() const
66  {
67  return (m_SignatNo & (~128)) ;
68  };
69 
70  void SetSignatNo(BYTE SignatNo)
71  {
72  m_SignatNo = SignatNo | (128 & m_SignatNo);
73  };
74 
75  bool IsEqual() const
76  {
77  return (m_SignatNo & 128) > 0 ;
78  };
79 
80  void SetEqual()
81  {
82  m_SignatNo |= 128;
83  };
84  const char* GetFieldFormat() const
85  {
87 
88  };
89 
90  bool HasEqualItems(const TBasicCortege& X, BYTE _MaxNumDom) const
91  {
92  for (BYTE i=0; i< _MaxNumDom;i++)
93  if (GetItem(i) != X.GetItem(i))
94  return false;
95  return true;
96  };
97 
98  bool EqualCortege(const TBasicCortege& X, BYTE _MaxNumDom) const
99  {
100  return (m_FieldNo == X.m_FieldNo)
101  && (m_SignatNo == X.m_SignatNo)
102  && (m_LevelId == X.m_LevelId)
103  && (m_LeafId == X.m_LeafId)
104  && (m_BracketLeafId == X.m_BracketLeafId)
105  && HasEqualItems (X, _MaxNumDom);
106  };
107 
108  bool IsEqualWithWildCard(const TBasicCortege& X, WORD EmptyDomItem, BYTE _MaxNumDom) const
109  {
110  if (!( (m_FieldNo == X.m_FieldNo)
111  && ( (m_LevelId == ErrUChar)
112  || (X.m_LevelId == ErrUChar)
113  || (m_LevelId == X.m_LevelId)
114  )
115  && ( (m_LeafId == ErrUChar)
116  || (X.m_LeafId == ErrUChar)
117  || (m_LeafId == X.m_LeafId)
118  )
119  && ( (m_BracketLeafId == ErrUChar)
120  || (X.m_BracketLeafId == ErrUChar)
121  || (m_BracketLeafId == X.m_BracketLeafId)
122  )
123 
124  )) return false;
125 
126  for (size_t i=0; i< _MaxNumDom;i++)
127  if ( (GetItem(i) != X.GetItem(i))
128  && (GetItem(i) != EmptyDomItem)
129  && (X.GetItem(i) != EmptyDomItem)
130  )
131  return false;
132 
133  return true;
134  };
135 
137  {
138  m_FieldNo = X.m_FieldNo;
139  m_LeafId = X.m_LeafId;
140  m_BracketLeafId = X.m_BracketLeafId;
141  m_LevelId = X.m_LevelId;
142  m_SignatNo = X.m_SignatNo;
143  for (int i =0; i < MaxNumDom; i++)
144  SetItem(i, X.GetItem(i));
145 
146  return *this;
147  };
148 
149 };
150 
151 
152 template <int MaxNumDom>
154 {
155 
156  return get_size_in_bytes(t.m_FieldNo)
161  + get_size_in_bytes(t.m_DomItemNos[0])*MaxNumDom;
162 };
163 
164 template <int MaxNumDom>
166 {
167  buf += save_to_bytes(i.m_FieldNo, buf);
168  buf += save_to_bytes(i.m_SignatNo, buf);
169  buf += save_to_bytes(i.m_LevelId, buf);
170  buf += save_to_bytes(i.m_LeafId, buf);
171  buf += save_to_bytes(i.m_BracketLeafId, buf);
172  for (int j = 0; j < MaxNumDom; j++)
173  buf += save_to_bytes(i.m_DomItemNos[j], buf);
174 
175  return get_size_in_bytes(i);
176 };
177 
178 template <int MaxNumDom>
180 {
181  buf += restore_from_bytes(i.m_FieldNo, buf);
182  buf += restore_from_bytes(i.m_SignatNo, buf);
183  buf += restore_from_bytes(i.m_LevelId, buf);
184  buf += restore_from_bytes(i.m_LeafId, buf);
185  buf += restore_from_bytes(i.m_BracketLeafId, buf);
186  for (int j = 0; j < MaxNumDom; j++)
187  buf += restore_from_bytes(i.m_DomItemNos[j], buf);
188  return get_size_in_bytes(i);
189 };
190 
191 
192 
193 
194 struct TCortege10 : public TBasicCortege<10>
195 {
197  {
198  for (size_t i=0; i< 10;i++)
199  SetItem(i,-1);
200  m_SignatNo = 0;
202  m_LeafId = 0;
203  m_BracketLeafId = 0;
204  };
205 
207  {
208  m_FieldNo = X.m_FieldNo;
209  m_LeafId = X.m_LeafId;
211  m_LevelId = X.m_LevelId;
213  for (int i =0; i < 3; i++)
214  SetItem(i, X.GetItem(i));
215  };
217  {
218  m_FieldNo = X.m_FieldNo;
219  m_LeafId = X.m_LeafId;
221  m_LevelId = X.m_LevelId;
223  for (int i =0; i < 10; i++)
224  SetItem(i, X.GetItem(i));
225  };
226 
227 
228 };
229 
230 #endif
231 
232 /*--- emacs style variables ---
233  * Local Variables:
234  * mode: C++
235  * c-file-style: "ellemtel"
236  * c-basic-offset: 4
237  * tab-width: 8
238  * indent-tabs-mode: nil
239  * End:
240  */
int GetItem(size_t index) const
Definition: cortege.h:45
BYTE m_LeafId
Definition: cortege.h:41
TBasicCortege()
Definition: cortege.h:56
BYTE m_FieldNo
Definition: cortege.h:38
const BYTE ErrUChar
Definition: cortege.h:27
size_t get_size_in_bytes(const TBasicCortege< MaxNumDom > &t)
Definition: cortege.h:153
const char _FieldFormat[]
Definition: cortege.h:31
const char * GetFieldFormat() const
Definition: cortege.h:84
void SetEqual()
Definition: cortege.h:80
Definition: cortege.h:194
uint16_t WORD
Definition: utilit.h:106
bool IsEqual() const
Definition: cortege.h:75
const char _FieldFormatEqual[]
Definition: cortege.h:32
BYTE m_SignatNo
Definition: cortege.h:39
BYTE GetSignatNo() const
Definition: cortege.h:65
size_t restore_from_bytes(TBasicCortege< MaxNumDom > &i, const BYTE *buf)
Definition: cortege.h:179
int SetItem(size_t index, long Value)
Definition: cortege.h:50
int m_DomItemNos[MaxNumDom]
Definition: cortege.h:43
bool EqualCortege(const TBasicCortege &X, BYTE _MaxNumDom) const
Definition: cortege.h:98
Definition: cortege.h:36
void SetSignatNo(BYTE SignatNo)
Definition: cortege.h:70
TCortege10(const TBasicCortege< 3 > &X)
Definition: cortege.h:206
unsigned char BYTE
Definition: utilit.h:94
bool HasEqualItems(const TBasicCortege &X, BYTE _MaxNumDom) const
Definition: cortege.h:90
bool IsEqualWithWildCard(const TBasicCortege &X, WORD EmptyDomItem, BYTE _MaxNumDom) const
Definition: cortege.h:108
TCortege10()
Definition: cortege.h:196
size_t save_to_bytes(const TBasicCortege< MaxNumDom > &i, BYTE *buf)
Definition: cortege.h:165
TBasicCortege< MaxNumDom > & operator=(const TBasicCortege< 10 > &X)
Definition: cortege.h:136
TCortege10(const TBasicCortege< 10 > &X)
Definition: cortege.h:216
BYTE m_LevelId
Definition: cortege.h:40
BYTE m_BracketLeafId
Definition: cortege.h:42