Go to the documentation of this file.00001
00002
00003
00004
00005 #ifndef ROSS_H
00006 #define ROSS_H
00007 #pragma warning (disable : 4530)
00008
00009 #include "../common/utilit.h"
00010
00011 #include <time.h>
00012
00013
00014 #include "ItemsContainer.h"
00015
00016
00017 const int NullItemId = 1;
00018
00019 const size_t MaxItemStr = 100;
00020
00021
00022 const int InitialStartPos = 5000000;
00023 const int InitialEndPos = -1;
00024
00025 class CStructEntry {
00026 public:
00027 int m_EntryId;
00028 char m_EntryStr[EntryStrSize];
00029 BYTE m_MeanNum;
00030 int m_StartCortegeNo;
00031 int m_LastCortegeNo;
00032 bool m_bSelected;
00033
00034 BYTE __dummy;
00035 char m_AuthorStr[AuthorNameSize];
00036
00037
00038 CStructEntry (const char* _Lemma = "\x0", int _MeanNum = 0)
00039 {
00040 m_StartCortegeNo = InitialStartPos;
00041 m_LastCortegeNo = InitialEndPos;
00042 size_t l = strlen (_Lemma);
00043 if (l < EntryStrSize - 1)
00044 strcpy (m_EntryStr, _Lemma);
00045 else
00046 {
00047 strncpy (m_EntryStr, _Lemma, EntryStrSize - 1);
00048 m_EntryStr[EntryStrSize - 1] = 0;
00049 };
00050
00051 m_MeanNum = _MeanNum;
00052 m_bSelected = true;
00053 }
00054
00055 bool HasEmptyArticle () const {return m_StartCortegeNo == InitialStartPos;};
00056
00057 bool operator==(const CStructEntry& X) const
00058 {
00059 return !strcmp (m_EntryStr, X.m_EntryStr)
00060 && (m_MeanNum == X.m_MeanNum);
00061 }
00062
00063 bool operator<(const CStructEntry& X) const
00064 {
00065 int i = strcmp (m_EntryStr, X.m_EntryStr);
00066 return (i < 0)
00067 ||( (i == 0)
00068 && (m_MeanNum < X.m_MeanNum));
00069 }
00070
00071 };
00072
00073
00074 const size_t UnitCommentSize = 100;
00075 class TUnitComment {
00076 public:
00077 int m_EntryId;
00078 char Editor[AuthorNameSize];
00079 char Comments[UnitCommentSize];
00080 tm modif_tm;
00081
00082 TUnitComment();
00083 TUnitComment(int _UnitId);
00084
00085 bool operator==(const TUnitComment& X) const
00086 {return m_EntryId == X.m_EntryId; }
00087
00088 bool operator<(const TUnitComment& X) const
00089 { return m_EntryId < X.m_EntryId;}
00090
00091
00092 };
00093
00094
00095 class TCortegeContainer
00096 {
00097 typedef TBasicCortege<3> CortegeType3;
00098 typedef TBasicCortege<10> CortegeType10;
00099
00100 vector<CortegeType3> m_Corteges3;
00101 vector<CortegeType10> m_Corteges10;
00102 public :
00103 BYTE m_MaxNumDom;
00104
00105 TCortegeContainer(BYTE MaxNumDom);
00106 TCortege10* GetCortege (size_t i);
00107 const TCortege10* GetCortege (size_t i) const;
00108
00109 void _AddCortege(const TCortege10& C);
00110 size_t _GetCortegesSize () const;
00111 void ClearCorteges();
00112 void EraseCorteges (size_t start, size_t last);
00113 void WriteCorteges (const char* CortegeFile) const;
00114 void ReadCorteges (const char* CortegeFile);
00115
00116 };
00117
00118
00119
00120
00121 class TRoss : public TCortegeContainer, public TItemContainer
00122 {
00123 char UnitsFile[_MAX_PATH];
00124 char CortegeFile[_MAX_PATH];
00125 char UnitCommentsFile[_MAX_PATH];
00126 char ConfigFile[_MAX_PATH];
00127
00128
00129 public:
00130 BYTE m_MaxMeanNum;
00131 string m_DictName;
00132
00133 vector<CStructEntry> m_Units;
00134 vector<TUnitComment> m_UnitComments;
00135 bool m_bShouldSaveComments;
00136
00137
00138 TRoss (BYTE MaxNumDom);
00139 ~TRoss ();
00140 bool FullLoad(const char* _RossPath);
00141 bool LoadOnlyConstants(const char* _RossPath);
00142 bool Save ();
00143
00144
00145
00146
00147
00148
00149 void BuildUnits();
00150 WORD GetUnitsSize() const { return (WORD)m_Units.size(); };
00151 bool ClearUnits();
00152 void ClearUnit(WORD UnitNo);
00153 void DelUnit(vector<CStructEntry>::iterator It);
00154 WORD LocateUnit (const char * EntryStr, int MeanNum) const;
00155 WORD GetSelectedUnitNo (WORD i) const;
00156 WORD GetSelectedUnitsSize() const;
00157 WORD InsertUnit (CStructEntry& T);
00158 WORD InsertUnit(const char* EntryStr, BYTE MeanNum);
00159 WORD UnitsLowerBound(const char* EntryStr) const
00160 {
00161 return lower_bound(m_Units.begin() , m_Units.end(), CStructEntry(EntryStr, 1)) - m_Units.begin();
00162 };
00163
00164
00165
00166
00167
00168
00169 bool ReadUnitComments();
00170 WORD InsertUnitComment (WORD m_EntryId);
00171 TUnitComment* GetCommentsByUnitId(WORD m_EntryId);
00172 const TUnitComment* GetCommentsByUnitId(WORD EntryId) const;
00173
00174
00175
00176
00177
00178
00179 bool BuildCorteges();
00180 virtual bool UpdateSignatsOfTheFieldInCorteges (BYTE FieldNo, vector<CSignat>& Signats);
00181 void DelCorteges (size_t start, size_t last);
00182
00183
00184
00185
00186
00187
00188 bool ReadFromStrWithOneSignatura (const char* s, TCortege10& C, BYTE SignatNo);
00189 bool ReadFromStr (const char* s, TCortege10& C);
00190 void WriteToStr (const int* Items, const char* Frmt, char* OutBuffer) const;
00191 void CortegeToStr (const TCortege10& C, char* OutBuffer) const;
00192
00193
00194
00195
00196
00197 bool InsertDomItem (const char* ItemStr, BYTE DomNo, int& ItemNo);
00198 void DelDomItem (int ItemNo);
00199
00200 const char* GetTitleFieldName() const;
00201 const char* GetSenseFieldName() const;
00202 const char* GetCommFieldName() const;
00203 const char* GetAuthorFieldName() const;
00204 const char* GetTimeCreatFieldName() const;
00205 const char* GetRedactFieldName() const;
00206
00207
00208 void SetUnitCommentStr(WORD UnitNo, const char* Str);
00209 void SetUnitAuthor(WORD UnitNo, const char* Author);
00210 void SetUnitModifTimeStr(WORD UnitNo, const char* TimeStr);
00211 void SetUnitEditor(WORD UnitNo, const char* Editor);
00212 string GetUnitModifTimeStr(WORD UnitNo) const;
00213 string GetUnitTextHeader(WORD UnitNo) const;
00214
00215 bool ReadConfig();
00216
00217 };
00218
00219
00220 typedef enum { iceOverwrite = 0, iceSkip = 1, iceAppend = 2} ImportConflictEnum;
00221
00222 struct CSourceLine
00223 {
00224 string m_Line;
00225 int m_SourceLineNo;
00226 CSourceLine (string Line, int SourceLineNo)
00227 {
00228 m_Line = Line;
00229 m_SourceLineNo = SourceLineNo;
00230 };
00231 };
00232
00233
00234
00235 class CDictionary : public TRoss
00236 {
00237 public:
00238
00239
00240
00241
00242
00243 vector<CStructEntry>& GetUnits();
00244
00245 CDictionary();
00246
00247 BYTE GetCortegeFieldNo(size_t i) const;
00248 BYTE GetCortegeLeafId(size_t i) const;
00249 BYTE GetCortegeBracketLeafId(size_t i) const;
00250 const char* GetDomItemStrInner(int ItemNo) const;
00251 bool IsEmptyArticle(WORD UnitNo) const;
00252 int GetUnitStartPos(WORD UnitNo) const;
00253 int GetUnitEndPos(WORD UnitNo) const;
00254 BYTE GetFieldNoByFieldStr(const char* Str) const;
00255 BYTE GetDomItemDomNo (int ItemNo) const;
00256 int GetCortegeItem(long CortegeNo, BYTE PositionInCortege) const;
00257 const char* GetDomItemStr(int ItemNo) const;
00258 string GetEntryStr (WORD EntryNo) const;
00259 BYTE GetUnitMeanNum(WORD EntryNo) const;
00260 bool IncludeArticle(WORD UnitNo, string Article) const;
00261
00262 bool Load(const char* Path);
00263 bool ProcessOneArticle ( vector<CSourceLine>& L, int start, int last, bool bSimulating, ImportConflictEnum ConflictSolver, string& Messages);
00264 bool ImportFromText(string FileName, bool bSimulating, ImportConflictEnum ConflictSolver, int StartEntry,string& Messages);
00265 void SetUnitCurrentTime(WORD UnitNo);
00266 bool AddField(string FieldStr);
00267 string GetUnitEditor(WORD UnitNo) const;
00268 void SetUnitStr(WORD UnitNo, const char* UnitStr);
00269
00270
00271 };
00272
00273
00274
00275
00276 #endif