The SWORD Project  1.9.0.svnversion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
versekey.h
Go to the documentation of this file.
1 /******************************************************************************
2  *
3  * versekey.h - class 'VerseKey': an SWKey for biblical verses with a
4  * book ch:vs structure. Includes a freehand text
5  * parser for the many ways one might specify a biblical
6  * verse reference or reference range / list.
7  *
8  * $Id: versekey.h 3820 2020-10-24 20:27:30Z scribe $
9  *
10  * Copyright 1997-2013 CrossWire Bible Society (http://www.crosswire.org)
11  * CrossWire Bible Society
12  * P. O. Box 2528
13  * Tempe, AZ 85280-2528
14  *
15  * This program is free software; you can redistribute it and/or modify it
16  * under the terms of the GNU General Public License as published by the
17  * Free Software Foundation version 2.
18  *
19  * This program is distributed in the hope that it will be useful, but
20  * WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22  * General Public License for more details.
23  *
24  */
25 
26 
27 #ifndef VERSEKEY_H
28 #define VERSEKEY_H
29 
30 #include <swkey.h>
31 #include <swmacs.h>
32 #include <listkey.h>
33 #include <versificationmgr.h>
34 
35 #include <defs.h>
36 
38 
39 #define POS_MAXVERSE ((char)3)
40 #define POS_MAXCHAPTER ((char)4)
41 #define POS_MAXBOOK ((char)5)
42 
43 #define MAXVERSE SW_POSITION(POS_MAXVERSE)
44 #define MAXCHAPTER SW_POSITION(POS_MAXCHAPTER)
45 #define MAXBOOK SW_POSITION(POS_MAXBOOK)
46 
47 
48 
53 class SWDLLEXPORT VerseKey : public SWKey {
54 
55 private:
58  static int instance;
60 
62 
65  char autonorm;
66 
69  char intros;
70 
73  void init(const char *v11n = "KJV");
74 
75  // bounds caching is mutable, thus const
76  void initBounds() const;
77 
78  // private with no bounds check
79  void setFromOther(const VerseKey &vk);
80 
81  void checkBounds();
82 
83  // internal upper/lower bounds optimizations
84  mutable long lowerBound, upperBound; // if autonorms is on
85  mutable VerseKey *tmpClone;
86 
87  typedef struct { int test; int book; int chap; int verse; char suffix; } VerseComponents;
88 
89  mutable VerseComponents lowerBoundComponents, upperBoundComponents; // if autonorms is off, we can't optimize with index
90 
91 protected:
92 
95  signed char testament;
96  signed char book;
97  signed int chapter;
98  signed int verse;
99  signed char suffix;
100 
101  /************************************************************************
102  * VerseKey::getBookFromAbbrev - Attempts to find a book no from a name or
103  * abbreviation
104  *
105  * ENT: @param abbr - key for which to search;
106  * RET: @return book number or < 0 = not valid
107  */
108  virtual int getBookFromAbbrev(const char *abbr) const;
109 
114  void freshtext() const;
118  virtual char parse(bool checkNormalize = true);
119 public:
120  int BMAX[2];
121 
128  VerseKey(const char *ikey = 0);
129 
136  VerseKey(const SWKey *ikey);
137 
144  VerseKey(const char *min, const char *max, const char *v11n = "KJV");
145 
151  VerseKey(const SWKey &k);
152 
158  VerseKey(const VerseKey &k);
159 
163  virtual ~VerseKey();
164 
169  void setLowerBound(const VerseKey &lb);
173  SWDEPRECATED VerseKey &LowerBound(const VerseKey &lb) { setLowerBound(lb); return getLowerBound(); }
174 
178  void setUpperBound(const VerseKey &ub);
182  SWDEPRECATED VerseKey &UpperBound(const VerseKey &ub) { setUpperBound(ub); return getUpperBound(); }
183 
187  VerseKey &getLowerBound() const;
191  SWDEPRECATED VerseKey &LowerBound() const { return getLowerBound(); }
192 
196  VerseKey &getUpperBound() const;
200  SWDEPRECATED VerseKey &UpperBound() const { return getUpperBound(); }
201 
204  void clearBounds() const;
209 
213  virtual SWKey *clone() const;
214 
218  virtual const char *getText() const;
219  virtual const char *getShortText() const;
220  virtual void setText(const char *ikey, bool checkNormalize) { SWKey::setText(ikey); parse(checkNormalize); }
221  virtual void setText(const char *ikey) { SWKey::setText(ikey); parse(); }
222  virtual void copyFrom(const SWKey &ikey);
223 
226  virtual void copyFrom(const VerseKey &ikey);
227 
230  virtual void positionFrom(const SWKey &ikey);
231 
236  virtual void setPosition(SW_POSITION newpos);
237 
242  virtual void decrement(int steps = 1);
243 
248  virtual void increment(int steps = 1);
249  virtual bool isTraversable() const { return true; }
250 
253  virtual const char *getBookName() const;
254  virtual void setBookName(const char *bname);
255 
256  virtual const char *getBookAbbrev() const;
261  virtual char getTestament() const;
265  SWDEPRECATED char Testament() const { return getTestament(); } // deprecated
266  virtual int getTestamentMax() const { return 2; }
267 
272  virtual char getBook() const;
276  SWDEPRECATED char Book() const { return getBook(); } // deprecated
277  virtual int getBookMax() const { return BMAX[testament-1]; }
278 
283  virtual int getChapter() const;
287  SWDEPRECATED int Chapter() const { return getChapter(); } // deprecated
288  virtual int getChapterMax() const;
289 
294  virtual int getVerse() const;
298  SWDEPRECATED int Verse() const { return getVerse(); } // deprecated
299  virtual int getVerseMax() const;
300 
305  virtual char getSuffix() const;
306 
311  virtual void setTestament(char itestament);
315  SWDEPRECATED char Testament(char itestament) { char retVal = getTestament(); setTestament(itestament); return retVal; } // deprecated
316 
321  virtual void setBook(char ibook);
325  SWDEPRECATED char Book(char ibook) { char retVal = getBook(); setBook(ibook); return retVal; } // deprecated
326 
331  virtual void setChapter(int ichapter);
335  SWDEPRECATED int Chapter(int ichapter) { char retVal = getChapter(); setChapter(ichapter); return retVal; } // deprecated
336 
341  virtual void setVerse(int iverse);
345  SWDEPRECATED int Verse(int iverse) { char retVal = getVerse(); setVerse(iverse); return retVal; } // deprecated;
346 
351  virtual void setSuffix(char isuffix);
352 
358  virtual void normalize(bool autocheck = false);
362  SWDEPRECATED void Normalize(char autocheck = 0) { normalize(autocheck!=0); }
363 
369  virtual void setAutoNormalize(bool iautonorm);
370  virtual bool isAutoNormalize() const;
371 
375  SWDEPRECATED char AutoNormalize(char iautonorm) { char retVal = isAutoNormalize()?1:0; setAutoNormalize(iautonorm!=0); return retVal; } // deprecated
379  SWDEPRECATED char AutoNormalize() const { return isAutoNormalize()?1:0; } // deprecated
380 
381 
391  SWDEPRECATED char Headings(char iheadings = MAXPOS(char)) { char retVal = isIntros(); if (iheadings != MAXPOS(char)) setIntros(iheadings!=0); return retVal; }
392 
396  virtual void setIntros(bool val);
397  virtual bool isIntros() const;
398 
399 
404  virtual long getIndex() const;
405 
406 
411  virtual void setIndex(long iindex);
412 
413 
418  virtual long getTestamentIndex() const;
419 
423  SWDEPRECATED long TestamentIndex() const { return getTestamentIndex(); } // deprecated, use getTestamentIndex()
424 
425  virtual const char *getOSISRef() const;
426  virtual const char *getOSISBookName() const;
427 
432  static const char *convertToOSIS(const char *inRef, const SWKey *defaultKey);
433 
434  /******************************************************************************
435  * VerseKey::parseVerseList - Attempts to parse a buffer into separate
436  * verse entries returned in a ListKey
437  *
438  * ENT: buf - buffer to parse;
439  * defaultKey - if verse, chap, book, or testament is left off,
440  * pull info from this key (ie. Gen 2:3; 4:5;
441  * Gen would be used when parsing the 4:5 section)
442  * expandRange - whether or not to expand eg. John 1:10-12 or just
443  * save John 1:10
444  *
445  * RET: ListKey reference filled with verse entries contained in buf
446  *
447  * COMMENT: This code works but wreaks. Rewrite to make more maintainable.
448  */
449  virtual ListKey parseVerseList(const char *buf, const char *defaultKey = 0, bool expandRange = false, bool useChapterAsVerse = false);
453  SWDEPRECATED ListKey ParseVerseList(const char *buf, const char *defaultKey = 0, bool expandRange = false, bool useChapterAsVerse = false) { return parseVerseList(buf, defaultKey, expandRange, useChapterAsVerse); }
454  virtual const char *getRangeText() const;
455  virtual const char *getShortRangeText() const;
456  virtual const char *getOSISRefRangeText() const;
464  virtual int compare(const SWKey &ikey);
465 
473  virtual int _compare(const VerseKey &ikey);
474 
475  virtual void setVersificationSystem(const char *name);
476  virtual const char *getVersificationSystem() const;
477 
478  // DEBUG
479  void validateCurrentLocale() const;
480 
481 
482  // OPERATORS --------------------------------------------------------------------
483 
484 
486 
487  virtual SWKey &operator =(const VerseKey &ikey) { positionFrom(ikey); return *this; }
488 };
489 
491 
492 #endif //VERSEKEY_H
virtual void setText(const char *ikey)
Definition: swkey.cpp:162
#define SWORD_NAMESPACE_START
Definition: defs.h:39
virtual const char * getShortRangeText() const
Definition: swkey.h:187
#define SWKEY_OPERATORS
Definition: swkey.h:37
signed int chapter
Definition: versekey.h:97
virtual const char * getShortText() const
Definition: swkey.h:185
virtual void decrement(int steps=1)
Definition: swkey.cpp:261
SWDEPRECATED void ClearBounds()
Definition: versekey.h:208
SWDEPRECATED char AutoNormalize() const
Definition: versekey.h:379
SWDEPRECATED ListKey ParseVerseList(const char *buf, const char *defaultKey=0, bool expandRange=false, bool useChapterAsVerse=false)
Definition: versekey.h:453
virtual void setIndex(long iindex)
Definition: swkey.h:233
#define SWDLLEXPORT
Definition: defs.h:171
signed char testament
Definition: versekey.h:95
virtual const char * getRangeText() const
Definition: swkey.cpp:193
bool normalize
Definition: tei2mod.cpp:101
virtual void increment(int steps=1)
Definition: swkey.cpp:248
SWDEPRECATED VerseKey & LowerBound() const
Definition: versekey.h:191
signed char suffix
Definition: versekey.h:99
SWDEPRECATED char Book() const
Definition: versekey.h:276
const VersificationMgr::System * refSys
Definition: versekey.h:61
SWBuf v11n
Definition: osis2mod.cpp:107
signed int verse
Definition: versekey.h:98
#define SWDEPRECATED
Definition: defs.h:174
char intros
Definition: versekey.h:69
virtual void positionFrom(const SWKey &ikey)
Definition: swkey.h:180
SWDEPRECATED char AutoNormalize(char iautonorm)
Definition: versekey.h:375
virtual SWKey * clone() const
Definition: swkey.cpp:75
virtual void clearBounds() const
Definition: swkey.h:190
virtual const char * getText() const
Definition: swkey.cpp:184
ListKey internalListKey
Definition: versekey.h:59
static int instance
Definition: versekey.h:58
void init()
Definition: swkey.cpp:68
VerseComponents upperBoundComponents
Definition: versekey.h:89
SWDEPRECATED void Normalize(char autocheck=0)
Definition: versekey.h:362
virtual void setText(const char *ikey)
Definition: versekey.h:221
SWDEPRECATED char Testament() const
Definition: versekey.h:265
virtual int compare(const SWKey &ikey)
Definition: swkey.cpp:218
virtual void copyFrom(const SWKey &ikey)
Definition: swkey.cpp:173
SWDEPRECATED char Book(char ibook)
Definition: versekey.h:325
SWDEPRECATED char Headings(char iheadings=MAXPOS(char))
Definition: versekey.h:391
SWDEPRECATED int Verse() const
Definition: versekey.h:298
virtual const char * getOSISRefRangeText() const
Definition: swkey.cpp:203
SWDEPRECATED long TestamentIndex() const
Definition: versekey.h:423
virtual void setPosition(SW_POSITION)
Definition: swkey.cpp:228
SWDEPRECATED VerseKey & UpperBound() const
Definition: versekey.h:200
SWDEPRECATED int Chapter() const
Definition: versekey.h:287
virtual bool isTraversable() const
Definition: versekey.h:249
SWDEPRECATED int Verse(int iverse)
Definition: versekey.h:345
virtual int getTestamentMax() const
Definition: versekey.h:266
SWDEPRECATED char Testament(char itestament)
Definition: versekey.h:315
SWDEPRECATED VerseKey & LowerBound(const VerseKey &lb)
Definition: versekey.h:173
#define MAXPOS(x)
Definition: swmacs.h:30
signed char book
Definition: versekey.h:96
virtual void setText(const char *ikey, bool checkNormalize)
Definition: versekey.h:220
char autonorm
Definition: versekey.h:65
SWDEPRECATED int Chapter(int ichapter)
Definition: versekey.h:335
#define SWORD_NAMESPACE_END
Definition: defs.h:40
virtual int getBookMax() const
Definition: versekey.h:277
Definition: swkey.h:77
virtual long getIndex() const
Definition: swkey.h:229
VerseKey * tmpClone
Definition: versekey.h:85
long upperBound
Definition: versekey.h:84
SWDEPRECATED VerseKey & UpperBound(const VerseKey &ub)
Definition: versekey.h:182