00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef VERSEKEY_H
00024 #define VERSEKEY_H
00025
00026 #include <swkey.h>
00027 #include <swmacs.h>
00028 #include <listkey.h>
00029 #include <ctype.h>
00030
00031 #include <defs.h>
00032
00033 #define POS_MAXVERSE ((char)3)
00034 #define POS_MAXCHAPTER ((char)4)
00035 #define POS_MAXBOOK ((char)5)
00036
00037 #define MAXVERSE SW_POSITION(POS_MAXVERSE)
00038 #define MAXCHAPTER SW_POSITION(POS_MAXCHAPTER)
00039 #define MAXBOOK SW_POSITION(POS_MAXBOOK)
00040
00041 struct sbook
00042 {
00045 const char *name;
00046
00049 const char *prefAbbrev;
00050
00053 unsigned char chapmax;
00056 int *versemax;
00057 };
00058
00059 struct abbrev
00060 {
00061 const char *ab;
00062 int book;
00063 };
00064
00065
00066 class SWLocale;
00067
00072 class SWDLLEXPORT VerseKey:public SWKey
00073 {
00074 class LocaleCache
00075 {
00076 public:
00077 char *name;
00078 unsigned int abbrevsCnt;
00079 SWLocale *locale;
00080 LocaleCache()
00081 {
00082 name = 0;
00083 abbrevsCnt = 0;
00084 locale = 0;
00085 }
00086 virtual ~LocaleCache()
00087 {
00088 if (name)
00089 delete[]name;
00090 }
00091 };
00092
00093 static SWClass classdef;
00094
00095 static long *offsets[2][2];
00096 static int offsize[2][2];
00099 static int instance;
00100 static struct sbook otbooks[];
00101 static struct sbook ntbooks[];
00102 static long otbks[];
00103 static long otcps[];
00104 static long ntbks[];
00105 static long ntcps[];
00106 static int vm[];
00107 static LocaleCache localeCache;
00108 ListKey internalListKey;
00109
00110 const struct abbrev *abbrevs;
00111 char *locale;
00112 int abbrevsCnt;
00115 signed char testament;
00116 mutable signed char book;
00117 mutable signed int chapter;
00118 mutable signed int verse;
00121 char autonorm;
00124 char headings;
00125
00126 int getBookAbbrev(const char *abbr);
00127 void initBounds() const;
00130 void initstatics();
00133 void init();
00138 void freshtext() const;
00142 virtual char parse();
00151 int findindex(long *array, int size, long value);
00152 mutable VerseKey *lowerBound, *upperBound;
00153
00154 public:
00155 static const char builtin_BMAX[2];
00156 static struct sbook *builtin_books[2];
00157 static const struct abbrev builtin_abbrevs[];
00158 const char *BMAX;
00159 struct sbook **books;
00160
00167 VerseKey(const char *ikey = 0);
00168
00175 VerseKey(const SWKey * ikey);
00176
00183 VerseKey(const char *min, const char *max);
00184
00190 VerseKey(const VerseKey &k);
00191
00195 virtual ~ VerseKey();
00196
00203 VerseKey & LowerBound(const char *lb);
00204
00210 VerseKey & UpperBound(const char *ub);
00211
00215 VerseKey & LowerBound() const;
00216
00220 VerseKey & UpperBound() const;
00221
00224 void ClearBounds();
00225
00229 virtual SWKey *clone() const;
00230
00234 virtual const char *getText() const;
00235 virtual const char *getShortText() const;
00236 virtual void setText(const char *ikey) { SWKey::setText(ikey); parse (); }
00237 virtual void copyFrom(const SWKey & ikey);
00238
00241 virtual void copyFrom(const VerseKey & ikey);
00242
00248 virtual void setPosition(SW_POSITION);
00249
00255 virtual void decrement(int step);
00256
00262 virtual void increment(int step);
00263 virtual char Traversable() { return 1; }
00264
00265 virtual const char *getBookName() const;
00266 virtual const char *getBookAbbrev() const;
00271 virtual char Testament() const;
00272
00277 virtual char Book() const;
00278
00283 virtual int Chapter() const;
00284
00289 virtual int Verse() const;
00290
00298 virtual char Testament(char itestament);
00299
00307 virtual char Book(char ibook);
00308
00316 virtual int Chapter(int ichapter);
00317
00325 virtual int Verse(int iverse);
00326
00333 virtual void Normalize(char autocheck = 0);
00334
00343 virtual char AutoNormalize(char iautonorm = MAXPOS (char));
00344
00353 virtual char Headings(char iheadings = MAXPOS (char));
00354
00355 virtual long NewIndex() const;
00356
00361 virtual long Index() const;
00362
00368 virtual long Index(long iindex);
00369
00370 virtual const char *getOSISRef() const;
00371
00372 virtual ListKey ParseVerseList(const char *buf, const char *defaultKey = "Genesis 1:1", bool expandRange = false);
00380 virtual int compare(const SWKey & ikey);
00381
00389 virtual int _compare(const VerseKey & ikey);
00390
00391 virtual void setBookAbbrevs(const struct abbrev *bookAbbrevs, unsigned int size = 0 );
00392 virtual void setBooks(const char *iBMAX, struct sbook **ibooks);
00393 virtual void setLocale(const char *name);
00394 virtual const char *getLocale() const { return locale; }
00395
00396 SWKEY_OPERATORS
00397
00398 virtual SWKey & operator = (const VerseKey & ikey) { copyFrom(ikey); return *this; }
00399 };
00400
00401
00402 #endif