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 SWORD_NAMESPACE_START
00034
00035 #define POS_MAXVERSE ((char)3)
00036 #define POS_MAXCHAPTER ((char)4)
00037 #define POS_MAXBOOK ((char)5)
00038
00039 #define MAXVERSE SW_POSITION(POS_MAXVERSE)
00040 #define MAXCHAPTER SW_POSITION(POS_MAXCHAPTER)
00041 #define MAXBOOK SW_POSITION(POS_MAXBOOK)
00042
00043 struct sbook
00044 {
00047 const char *name;
00048
00051 const char *prefAbbrev;
00052
00055 unsigned char chapmax;
00058 int *versemax;
00059 };
00060
00061 struct abbrev
00062 {
00063 const char *ab;
00064 int book;
00065 };
00066
00067
00068 class SWLocale;
00069
00074 class SWDLLEXPORT VerseKey:public SWKey
00075 {
00076 class LocaleCache
00077 {
00078 public:
00079 char *name;
00080 unsigned int abbrevsCnt;
00081 SWLocale *locale;
00082 LocaleCache()
00083 {
00084 name = 0;
00085 abbrevsCnt = 0;
00086 locale = 0;
00087 }
00088 virtual ~LocaleCache()
00089 {
00090 if (name)
00091 delete[]name;
00092 }
00093 };
00094
00095 static SWClass classdef;
00096
00097 static long *offsets[2][2];
00098 static int offsize[2][2];
00101 static int instance;
00102 static struct sbook otbooks[];
00103 static struct sbook ntbooks[];
00104 static long otbks[];
00105 static long otcps[];
00106 static long ntbks[];
00107 static long ntcps[];
00108 static int vm[];
00109 static LocaleCache localeCache;
00110 ListKey internalListKey;
00111
00112 const struct abbrev *abbrevs;
00113 char *locale;
00114 int abbrevsCnt;
00117 signed char testament;
00118 mutable signed char book;
00119 mutable signed int chapter;
00120 mutable signed int verse;
00123 char autonorm;
00126 char headings;
00127
00128 int getBookAbbrev(const char *abbr);
00129 void initBounds() const;
00132 void initstatics();
00135 void init();
00140 void freshtext() const;
00144 virtual char parse();
00153 int findindex(long *array, int size, long value);
00154 mutable VerseKey *lowerBound, *upperBound;
00155
00156 public:
00157 static const char builtin_BMAX[2];
00158 static struct sbook *builtin_books[2];
00159 static const struct abbrev builtin_abbrevs[];
00160 const char *BMAX;
00161 struct sbook **books;
00162
00169 VerseKey(const char *ikey = 0);
00170
00177 VerseKey(const SWKey * ikey);
00178
00185 VerseKey(const char *min, const char *max);
00186
00192 VerseKey(const VerseKey &k);
00193
00197 virtual ~ VerseKey();
00198
00205 VerseKey & LowerBound(const char *lb);
00206
00212 VerseKey & UpperBound(const char *ub);
00213
00217 VerseKey & LowerBound() const;
00218
00222 VerseKey & UpperBound() const;
00223
00226 void ClearBounds();
00227
00231 virtual SWKey *clone() const;
00232
00236 virtual const char *getText() const;
00237 virtual const char *getShortText() const;
00238 virtual void setText(const char *ikey) { SWKey::setText(ikey); parse (); }
00239 virtual void copyFrom(const SWKey & ikey);
00240
00243 virtual void copyFrom(const VerseKey & ikey);
00244
00250 virtual void setPosition(SW_POSITION newpos);
00251
00257 virtual void decrement(int steps);
00258
00264 virtual void increment(int steps);
00265 virtual char Traversable() { return 1; }
00266
00267 virtual const char *getBookName() const;
00268 virtual const char *getBookAbbrev() const;
00273 virtual char Testament() const;
00274
00279 virtual char Book() const;
00280
00285 virtual int Chapter() const;
00286
00291 virtual int Verse() const;
00292
00300 virtual char Testament(char itestament);
00301
00309 virtual char Book(char ibook);
00310
00318 virtual int Chapter(int ichapter);
00319
00327 virtual int Verse(int iverse);
00328
00335 virtual void Normalize(char autocheck = 0);
00336
00345 virtual char AutoNormalize(char iautonorm = MAXPOS (char));
00346
00355 virtual char Headings(char iheadings = MAXPOS (char));
00356
00357 virtual long NewIndex() const;
00358
00363 virtual long Index() const;
00364
00370 virtual long Index(long iindex);
00371
00372 virtual const char *getOSISRef() const;
00373
00374 virtual ListKey ParseVerseList(const char *buf, const char *defaultKey = "Genesis 1:1", bool expandRange = false);
00375 virtual const char *getRangeText() const;
00383 virtual int compare(const SWKey & ikey);
00384
00392 virtual int _compare(const VerseKey & ikey);
00393
00394 virtual void setBookAbbrevs(const struct abbrev *bookAbbrevs, unsigned int size = 0 );
00395 virtual void setBooks(const char *iBMAX, struct sbook **ibooks);
00396 virtual void setLocale(const char *name);
00397 virtual const char *getLocale() const { return locale; }
00398
00399
00400
00401
00402
00403
00404 SWKEY_OPERATORS
00405
00406 virtual SWKey & operator = (const VerseKey & ikey) { copyFrom(ikey); return *this; }
00407 };
00408
00409 SWORD_NAMESPACE_END
00410 #endif