diff options
Diffstat (limited to 'include/versekey.h')
-rw-r--r-- | include/versekey.h | 269 |
1 files changed, 132 insertions, 137 deletions
diff --git a/include/versekey.h b/include/versekey.h index 42127bf..4639c69 100644 --- a/include/versekey.h +++ b/include/versekey.h @@ -1,7 +1,7 @@ /****************************************************************************** * versekey.h - code for class 'versekey'- a standard Biblical verse key * - * $Id: versekey.h 2169 2008-05-18 02:50:53Z scribe $ + * $Id: versekey.h 2377 2009-05-04 08:04:55Z scribe $ * * Copyright 1998 CrossWire Bible Society (http://www.crosswire.org) * CrossWire Bible Society @@ -26,6 +26,7 @@ #include <swkey.h> #include <swmacs.h> #include <listkey.h> +#include <versemgr.h> #include <defs.h> @@ -40,32 +41,6 @@ SWORD_NAMESPACE_START #define MAXBOOK SW_POSITION(POS_MAXBOOK) -struct sbook -{ - /**Name of book - */ - const char *name; - - /**Preferred Abbreviation - */ - const char *prefAbbrev; - - /**Maximum chapters in book - */ - unsigned char chapmax; - /** Array[chapmax] of maximum verses in chapters - */ - int *versemax; -}; - -struct abbrev -{ - const char *ab; - int book; -}; - - -class SWLocale; /** * Class VerseKey @@ -73,56 +48,16 @@ class SWLocale; */ class SWDLLEXPORT VerseKey : public SWKey { - class LocaleCache { - public: - char *name; - unsigned int abbrevsCnt; - SWLocale *locale; - LocaleCache() { - name = 0; - abbrevsCnt = 0; - locale = 0; - } - virtual ~LocaleCache() { - if (name) - delete[]name; - } - }; - static SWClass classdef; - static long *offsets[2][2]; - static int offsize[2][2]; - /** number of instantiated VerseKey objects or derivitives + /** number of instantiated VerseKey objects or derivitives */ static int instance; - static struct sbook otbooks[]; - static struct sbook ntbooks[]; - static const char *osisotbooks[]; - static const char *osisntbooks[]; - static const char **osisbooks[]; -#if 1 - static long otbks[]; - static long otcps[]; - static long ntbks[]; - static long ntcps[]; -#endif - static int vm[]; - static LocaleCache localeCache; ListKey internalListKey; - const struct abbrev *abbrevs; - char *locale; - int abbrevsCnt; - - /** The Testament: 0 - Old; 1 - New - */ - signed char testament; - mutable signed char book; - mutable signed int chapter; - mutable signed int verse; + const VerseMgr::System *refSys; - /** flag for auto normalization + /** flag for auto normalization */ char autonorm; @@ -130,16 +65,19 @@ class SWDLLEXPORT VerseKey : public SWKey { */ char headings; - int getBookAbbrev(const char *abbr); - void initBounds() const; - /** initialize and allocate books array */ void initstatics(); /** initializes this VerseKey() */ - void init(); + void init(const char *v11n = "KJV"); + + // bounds caching is mutable, thus const + void initBounds() const; + + // private with no bounds check + void setFromOther(const VerseKey &vk); /** Binary search to find the index closest, but less * than the given value. @@ -151,17 +89,39 @@ class SWDLLEXPORT VerseKey : public SWKey { */ int findindex(long *array, int size, long value); - mutable VerseKey *lowerBound, *upperBound; + // internal upper/lower bounds optimizations + mutable long lowerBound, upperBound; // if autonorms is on + mutable VerseKey *tmpClone; + + typedef struct { int test; int book; int chap; int verse; } VerseComponents; + mutable VerseComponents lowerBoundComponents, upperBoundComponents; // if autonorms is off, we can't optimize with index protected: + /** The Testament: 0 - Module Heading; 1 - Old; 2 - New + */ + signed char testament; + signed char book; + signed int chapter; + signed int verse; + signed char suffix; + + /************************************************************************ + * VerseKey::getBookAbbrev - Attempts to find a book no from a name or + * abbreviation + * + * ENT: @param abbr - key for which to search; + * RET: @return book number or < 0 = not valid + */ + virtual int getBookAbbrev(const char *abbr) const; + /** Refresh keytext based on testament|book|chapter|verse * default auto normalization to true * default display headings option is false */ void freshtext() const; - /** Parse a character array into testament|book|chapter|verse + /** Parse a character array into testament|book|chapter|verse * */ virtual char parse(bool checkNormalize = true); @@ -172,11 +132,7 @@ public: static long ntbks[]; static long ntcps[]; #endif - static const char builtin_BMAX[2]; - static struct sbook *builtin_books[2]; - static const struct abbrev builtin_abbrevs[]; - const char *BMAX; - struct sbook **books; + int BMAX[2]; /** * VerseKey Constructor - initializes Instance of VerseKey @@ -185,23 +141,23 @@ public: * See parse() for more detailed information) */ VerseKey(const char *ikey = 0); - + /** * VerseKey Constructor - initializes instance of VerseKey * * @param ikey base key (will take various forms of 'BOOK CH:VS'. * See parse() for more detailed information) - */ + */ VerseKey(const SWKey *ikey); - + /** VerseKey Constructor - initializes instance of VerseKey * with boundariess - see also LowerBound() * and UpperBound() * @param min the lower boundary of the new VerseKey * @param max the upper boundary of the new VerseKey - */ - VerseKey(const char *min, const char *max); - + */ + VerseKey(const char *min, const char *max, const char *v11n = "KJV"); + /** VerseKey Copy Constructor - will create a new VerseKey * based on an existing SWKey * @@ -215,7 +171,7 @@ public: * @param k the VerseKey to copy from */ VerseKey(const VerseKey &k); - + /** VerseKey Destructor * Cleans up an instance of VerseKey */ @@ -224,37 +180,37 @@ public: /** sets the lower boundary for this VerseKey * and returns the new boundary * - * @param lb the new lower boundary for this VerseKey + * @param ub the new upper boundary for this VerseKey * @return the lower boundary the key was set to */ - VerseKey &LowerBound(const char *lb); - + VerseKey &LowerBound(const VerseKey &ub); + /** sets the upper boundary for this VerseKey * and returns the new boundary * @param ub the new upper boundary for this VerseKey * @return the upper boundary the key was set to */ - VerseKey &UpperBound(const char *ub); - + VerseKey &UpperBound(const VerseKey &ub); + /** gets the lower boundary of this VerseKey * @return the lower boundary of this VerseKey */ VerseKey &LowerBound() const; - + /** gets the upper boundary of this VerseKey * @return the upper boundary of this VerseKey */ VerseKey &UpperBound() const; - + /** clears the boundaries of this VerseKey */ void ClearBounds(); - + /** Creates a new SWKey based on the current VerseKey * see also the Copy Constructor */ virtual SWKey *clone() const; - + /** refreshes keytext before returning if cast to * a (char *) is requested */ @@ -263,59 +219,79 @@ public: virtual void setText(const char *ikey, bool checkNormalize) { SWKey::setText(ikey); parse(checkNormalize); } virtual void setText(const char *ikey) { SWKey::setText(ikey); parse(); } virtual void copyFrom(const SWKey &ikey); - + /** Equates this VerseKey to another VerseKey */ virtual void copyFrom(const VerseKey &ikey); - + + /** Only repositions this VerseKey to another VerseKey + */ + virtual void positionFrom(const SWKey &ikey); + /** Positions this key * * @param newpos Position to set to. * @return *this */ virtual void setPosition(SW_POSITION newpos); - + /** Decrements key a number of verses * * @param steps Number of verses to jump backward * @return *this */ - virtual void decrement(int steps); - + virtual void decrement(int steps = 1); + /** Increments key a number of verses * * @param steps Number of verses to jump forward * @return *this */ - virtual void increment(int steps); + virtual void increment(int steps = 1); virtual bool isTraversable() const { return true; } + /** Get/Set position of this key by Book Name + */ virtual const char *getBookName() const; + virtual void setBookName(const char *bname); + virtual const char *getBookAbbrev() const; /** Gets testament * * @return value of testament */ - virtual char Testament() const; - + virtual char Testament() const { return getTestament(); } // deprecated + virtual char getTestament() const; + /** Gets book * * @return value of book */ - virtual char Book() const; - + virtual char Book() const { return getBook(); } // deprecated + virtual char getBook() const; + /** Gets chapter * * @return value of chapter */ - virtual int Chapter() const; - + virtual int Chapter() const { return getChapter(); } // deprecated + virtual int getChapter() const; + virtual int getChapterMax() const; + /** Gets verse * * @return value of verse */ - virtual int Verse() const; - + virtual int Verse() const { return getVerse(); } // deprecated + virtual int getVerse() const; + virtual int getVerseMax() const; + + /** Gets verse suffix + * + * @return value of verse suffix + */ + virtual char getSuffix() const; + /** Sets/gets testament * * @param itestament value which to set testament @@ -323,8 +299,9 @@ public: * @return if unchanged -> value of testament, * if changed -> previous value of testament */ - virtual char Testament(char itestament); - + virtual char Testament(char itestament) { char retVal = getTestament(); setTestament(itestament); return retVal; } // deprecated + virtual void setTestament(char itestament); + /** Sets/gets book * * @param ibook value which to set book @@ -332,8 +309,9 @@ public: * @return if unchanged -> value of book, * if changed -> previous value of book */ - virtual char Book(char ibook); - + virtual char Book(char ibook) { char retVal = getBook(); setBook(ibook); return retVal; } // deprecated + virtual void setBook(char ibook); + /** Sets/gets chapter * * @param ichapter value which to set chapter @@ -341,8 +319,9 @@ public: * @return if unchanged -> value of chapter, * if changed -> previous value of chapter */ - virtual int Chapter(int ichapter); - + virtual int Chapter(int ichapter) { char retVal = getChapter(); setChapter(ichapter); return retVal; } // deprecated + virtual void setChapter(int ichapter); + /** Sets/gets verse * * @param iverse value which to set verse @@ -350,8 +329,15 @@ public: * @return if unchanged -> value of verse, * if changed -> previous value of verse */ - virtual int Verse(int iverse); - + virtual int Verse(int iverse) { char retVal = getVerse(); setVerse(iverse); return retVal; } // deprecated; + virtual void setVerse(int iverse); + + /** Sets/gets verse suffix + * + * @param isuffix value which to set verse suffix + */ + virtual void setSuffix(char isuffix); + /** checks limits and normalizes if necessary (e.g. * Matthew 29:47 = Mark 2:2). If last verse is * exceeded, key is set to last Book CH:VS @@ -359,7 +345,7 @@ public: * @return *this */ virtual void Normalize(char autocheck = 0); - + /** Sets/gets flag that tells VerseKey to * automatically normalize itself when modified * @@ -368,8 +354,12 @@ public: * @return if unchanged -> value of autonorm, * if changed -> previous value of autonorm */ - virtual char AutoNormalize(char iautonorm = MAXPOS(char)); - + virtual char AutoNormalize(char iautonorm) { char retVal = isAutoNormalize()?1:0; setAutoNormalize(iautonorm); return retVal; } // deprecated + virtual char AutoNormalize() const { return isAutoNormalize()?1:0; } // deprecated + + virtual bool isAutoNormalize() const; + virtual void setAutoNormalize(bool iautonorm); + /** Sets/gets flag that tells VerseKey to include * chapter/book/testament/module headings * @@ -379,15 +369,13 @@ public: * if changed -> previous value of headings */ virtual char Headings(char iheadings = MAXPOS(char)); - - virtual long NewIndex() const; - + /** Gets index based upon current verse * * @return offset */ virtual long Index() const; - + /** Sets index based upon current verse * * @param iindex value to set index to @@ -395,8 +383,14 @@ public: */ virtual long Index(long iindex); + /** Gets index into current testament based upon current verse + * + * @return offset + */ + virtual long TestamentIndex() const; + virtual const char *getOSISRef() const; - static const int getOSISBookNum(const char *bookab); + virtual const char *getOSISBookName() const; /** Tries to parse a string and convert it into an OSIS reference * @param inRef reference string to try to parse @@ -404,8 +398,9 @@ public: */ static const char *convertToOSIS(const char *inRef, const SWKey *defaultKey); - virtual ListKey ParseVerseList(const char *buf, const char *defaultKey = 0, bool expandRange = false); + virtual ListKey ParseVerseList(const char *buf, const char *defaultKey = 0, bool expandRange = false, bool useChapterAsVerse = false); virtual const char *getRangeText() const; + virtual const char *getOSISRefRangeText() const; /** Compares another SWKey object * * @param ikey key to compare with this one @@ -413,8 +408,8 @@ public: * <0 if this VerseKey is smaller than compare SWKey, * 0 if the keys are the same */ - virtual int compare(const SWKey & ikey); - + virtual int compare(const SWKey &ikey); + /** Compares another VerseKey object * * @param ikey key to compare with this one @@ -422,13 +417,13 @@ public: * <0 if this VerseKey is smaller than compare VerseKey, * 0 if the keys are the same */ - virtual int _compare(const VerseKey & ikey); - - virtual void setBookAbbrevs(const struct abbrev *bookAbbrevs, unsigned int size = 0 /* default determine size */ ); - virtual void setBooks(const char *iBMAX, struct sbook **ibooks); - virtual void setLocale(const char *name); - virtual const char *getLocale() const { return locale; } + virtual int _compare(const VerseKey &ikey); + + virtual void setVersificationSystem(const char *name); + virtual const char *getVersificationSystem() const; + // DEBUG + void validateCurrentLocale() const; // OPERATORS -------------------------------------------------------------------- @@ -436,7 +431,7 @@ public: SWKEY_OPERATORS - virtual SWKey & operator =(const VerseKey & ikey) { copyFrom(ikey); return *this; } + virtual SWKey &operator =(const VerseKey &ikey) { positionFrom(ikey); return *this; } }; SWORD_NAMESPACE_END |