1
/******************************************************************************
2
* versekey.h - code for class 'versekey'- a standard Biblical verse key
4
* $Id: versekey.h,v 1.30 2003/08/13 05:27:02 scribe Exp $
6
* Copyright 1998 CrossWire Bible Society (http://www.crosswire.org)
7
* CrossWire Bible Society
11
* This program is free software; you can redistribute it and/or modify it
12
* under the terms of the GNU General Public License as published by the
13
* Free Software Foundation version 2.
15
* This program is distributed in the hope that it will be useful, but
16
* WITHOUT ANY WARRANTY; without even the implied warranty of
17
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18
* General Public License for more details.
35
#define POS_MAXVERSE ((char)3)
36
#define POS_MAXCHAPTER ((char)4)
37
#define POS_MAXBOOK ((char)5)
39
#define MAXVERSE SW_POSITION(POS_MAXVERSE)
40
#define MAXCHAPTER SW_POSITION(POS_MAXCHAPTER)
41
#define MAXBOOK SW_POSITION(POS_MAXBOOK)
49
/**Preferred Abbreviation
51
const char *prefAbbrev;
53
/**Maximum chapters in book
55
unsigned char chapmax;
56
/** Array[chapmax] of maximum verses in chapters
72
* The SWKey implementation used for verse based modules like Bibles or commentaries.
74
class SWDLLEXPORT VerseKey:public SWKey {
78
unsigned int abbrevsCnt;
85
virtual ~LocaleCache() {
91
static SWClass classdef;
93
static long *offsets[2][2];
94
static int offsize[2][2];
95
/** number of instantiated VerseKey objects or derivitives
98
static struct sbook otbooks[];
99
static struct sbook ntbooks[];
105
static LocaleCache localeCache;
106
ListKey internalListKey;
108
const struct abbrev *abbrevs;
111
/** The Testament: 0 - Old; 1 - New
113
signed char testament;
114
mutable signed char book;
115
mutable signed int chapter;
116
mutable signed int verse;
117
/** flag for auto normalization
120
/** flag for headings on/off
124
int getBookAbbrev(const char *abbr);
125
void initBounds() const;
126
/** initialize and allocate books array
129
/** initializes this VerseKey()
132
/** Refresh keytext based on testament|book|chapter|verse
133
* default auto normalization to true
134
* default display headings option is false
136
void freshtext() const;
137
/** Parse a character array into testament|book|chapter|verse
140
virtual char parse();
141
/** Binary search to find the index closest, but less
142
* than the given value.
144
* @param array long * to array to search
145
* @param size number of elements in the array
146
* @param value value to find
147
* @return the index into the array that is less than but closest to value
149
int findindex(long *array, int size, long value);
150
mutable VerseKey *lowerBound, *upperBound;
153
static const char builtin_BMAX[2];
154
static struct sbook *builtin_books[2];
155
static const struct abbrev builtin_abbrevs[];
157
struct sbook **books;
160
* VerseKey Constructor - initializes Instance of VerseKey
162
* @param ikey text key (will take various forms of 'BOOK CH:VS'.
163
* See parse() for more detailed information)
165
VerseKey(const char *ikey = 0);
168
* VerseKey Constructor - initializes instance of VerseKey
170
* @param ikey base key (will take various forms of 'BOOK CH:VS'.
171
* See parse() for more detailed information)
173
VerseKey(const SWKey * ikey);
175
/** VerseKey Constructor - initializes instance of VerseKey
176
* with boundariess - see also LowerBound()
178
* @param min the lower boundary of the new VerseKey
179
* @param max the upper boundary of the new VerseKey
181
VerseKey(const char *min, const char *max);
183
/** VerseKey Copy Constructor - will create a new VerseKey
184
* based on an existing one
186
* @param k the VerseKey to copy from
188
VerseKey(const VerseKey &k);
190
/** VerseKey Destructor
191
* Cleans up an instance of VerseKey
193
virtual ~ VerseKey();
195
/** sets the lower boundary for this VerseKey
196
* and returns the new boundary
198
* @param lb the new lower boundary for this VerseKey
199
* @return the lower boundary the key was set to
201
VerseKey & LowerBound(const char *lb);
203
/** sets the upper boundary for this VerseKey
204
* and returns the new boundary
205
* @param ub the new upper boundary for this VerseKey
206
* @return the upper boundary the key was set to
208
VerseKey & UpperBound(const char *ub);
210
/** gets the lower boundary of this VerseKey
211
* @return the lower boundary of this VerseKey
213
VerseKey & LowerBound() const;
215
/** gets the upper boundary of this VerseKey
216
* @return the upper boundary of this VerseKey
218
VerseKey & UpperBound() const;
220
/** clears the boundaries of this VerseKey
224
/** Creates a new SWKey based on the current VerseKey
225
* see also the Copy Constructor
227
virtual SWKey *clone() const;
229
/** refreshes keytext before returning if cast to
230
* a (char *) is requested
232
virtual const char *getText() const;
233
virtual const char *getShortText() const;
234
virtual void setText(const char *ikey) { SWKey::setText(ikey); parse (); }
235
virtual void copyFrom(const SWKey & ikey);
237
/** Equates this VerseKey to another VerseKey
239
virtual void copyFrom(const VerseKey & ikey);
241
/** Positions this key
243
* @param newpos Position to set to.
246
virtual void setPosition(SW_POSITION newpos);
248
/** Decrements key a number of verses
250
* @param steps Number of verses to jump backward
253
virtual void decrement(int steps);
255
/** Increments key a number of verses
257
* @param steps Number of verses to jump forward
260
virtual void increment(int steps);
261
virtual char Traversable() { return 1; }
263
virtual const char *getBookName() const;
264
virtual const char *getBookAbbrev() const;
267
* @return value of testament
269
virtual char Testament() const;
273
* @return value of book
275
virtual char Book() const;
279
* @return value of chapter
281
virtual int Chapter() const;
285
* @return value of verse
287
virtual int Verse() const;
289
/** Sets/gets testament
291
* @param itestament value which to set testament
292
* [MAXPOS(char)] - only get
293
* @return if unchanged -> value of testament,
294
* if changed -> previous value of testament
296
virtual char Testament(char itestament);
300
* @param ibook value which to set book
301
* [MAXPOS(char)] - only get
302
* @return if unchanged -> value of book,
303
* if changed -> previous value of book
305
virtual char Book(char ibook);
307
/** Sets/gets chapter
309
* @param ichapter value which to set chapter
310
* [MAXPOS(int)] - only get
311
* @return if unchanged -> value of chapter,
312
* if changed -> previous value of chapter
314
virtual int Chapter(int ichapter);
318
* @param iverse value which to set verse
319
* [MAXPOS(int)] - only get
320
* @return if unchanged -> value of verse,
321
* if changed -> previous value of verse
323
virtual int Verse(int iverse);
325
/** checks limits and normalizes if necessary (e.g.
326
* Matthew 29:47 = Mark 2:2). If last verse is
327
* exceeded, key is set to last Book CH:VS
331
virtual void Normalize(char autocheck = 0);
333
/** Sets/gets flag that tells VerseKey to
334
* automatically normalize itself when modified
336
* @param iautonorm value which to set autonorm
337
* [MAXPOS(char)] - only get
338
* @return if unchanged -> value of autonorm,
339
* if changed -> previous value of autonorm
341
virtual char AutoNormalize(char iautonorm = MAXPOS (char));
343
/** Sets/gets flag that tells VerseKey to include
344
* chapter/book/testament/module headings
346
* @param iheadings value which to set headings
347
* [MAXPOS(char)] - only get
348
* @return if unchanged -> value of headings,
349
* if changed -> previous value of headings
351
virtual char Headings(char iheadings = MAXPOS (char));
353
virtual long NewIndex() const;
355
/** Gets index based upon current verse
359
virtual long Index() const;
361
/** Sets index based upon current verse
363
* @param iindex value to set index to
366
virtual long Index(long iindex);
368
virtual const char *getOSISRef() const;
370
virtual ListKey ParseVerseList(const char *buf, const char *defaultKey = "Genesis 1:1", bool expandRange = false);
371
virtual const char *getRangeText() const;
372
/** Compares another SWKey object
374
* @param ikey key to compare with this one
375
* @return >0 if this VerseKey is greater than compare SWKey,
376
* <0 if this VerseKey is smaller than compare SWKey,
377
* 0 if the keys are the same
379
virtual int compare(const SWKey & ikey);
381
/** Compares another VerseKey object
383
* @param ikey key to compare with this one
384
* @return >0 if this VerseKey is greater than compare VerseKey,
385
* <0 if this VerseKey is smaller than compare VerseKey,
386
* 0 if the keys are the same
388
virtual int _compare(const VerseKey & ikey);
390
virtual void setBookAbbrevs(const struct abbrev *bookAbbrevs, unsigned int size = 0 /* default determine size */ );
391
virtual void setBooks(const char *iBMAX, struct sbook **ibooks);
392
virtual void setLocale(const char *name);
393
virtual const char *getLocale() const { return locale; }
397
// OPERATORS --------------------------------------------------------------------
402
virtual SWKey & operator = (const VerseKey & ikey) { copyFrom(ikey); return *this; }