#include <versekey.h>
Inheritance diagram for VerseKey:
Public Methods | |
VerseKey (const char *ikey=0) | |
VerseKey Constructor - initializes Instance of VerseKey. More... | |
VerseKey (const SWKey *ikey) | |
VerseKey Constructor - initializes instance of VerseKey. More... | |
VerseKey (const char *min, const char *max) | |
VerseKey Constructor - initializes instance of VerseKey with boundariess - see also LowerBound and UpperBound. More... | |
VerseKey (const VerseKey &k) | |
VerseKey Copy Constructor - will create a new VerseKey based on an existing one. More... | |
virtual | ~VerseKey () |
VerseKey Destructor Cleans up an instance of VerseKey. | |
VerseKey & | LowerBound (const char *lb) |
sets the lower boundary for this VerseKey and returns the new boundary. More... | |
VerseKey & | UpperBound (const char *ub) |
sets the upper boundary for this VerseKey and returns the new boundary. More... | |
VerseKey & | LowerBound () const |
gets the lower boundary of this VerseKey. More... | |
VerseKey & | UpperBound () const |
gets the upper boundary of this VerseKey. More... | |
void | ClearBounds () |
clears the boundaries of this VerseKey. | |
virtual SWKey * | clone () const |
Creates a new SWKey based on the current VerseKey see also the Copy Constructor. | |
virtual const char * | getText () const |
refreshes keytext before returning if cast to a (char *) is requested. | |
virtual const char * | getShortText () const |
virtual void | setText (const char *ikey) |
Equates this SWKey to a character string. More... | |
virtual void | copyFrom (const SWKey &ikey) |
Equates this SWKey to another SWKey object. More... | |
virtual void | copyFrom (const VerseKey &ikey) |
Equates this VerseKey to another VerseKey. | |
virtual void | setPosition (SW_POSITION) |
Positions this key. More... | |
virtual void | decrement (int step) |
Decrements key a number of verses. More... | |
virtual void | increment (int step) |
Increments key a number of verses. More... | |
virtual char | Traversable () |
virtual const char * | getBookName () const |
virtual const char * | getBookAbbrev () const |
virtual char | Testament () const |
Gets testament. More... | |
virtual char | Book () const |
Gets book. More... | |
virtual int | Chapter () const |
Gets chapter. More... | |
virtual int | Verse () const |
Gets verse. More... | |
virtual char | Testament (char itestament) |
Sets/gets testament. More... | |
virtual char | Book (char ibook) |
Sets/gets book. More... | |
virtual int | Chapter (int ichapter) |
Sets/gets chapter. More... | |
virtual int | Verse (int iverse) |
Sets/gets verse. More... | |
virtual void | Normalize (char autocheck=0) |
checks limits and normalizes if necessary (e.g. More... | |
virtual char | AutoNormalize (char iautonorm=MAXPOS(char)) |
Sets/gets flag that tells VerseKey to automatically normalize itself when modified. More... | |
virtual char | Headings (char iheadings=MAXPOS(char)) |
Sets/gets flag that tells VerseKey to include chapter/book/testament/module headings. More... | |
virtual long | NewIndex () const |
virtual long | Index () const |
Gets index based upon current verse. More... | |
virtual long | Index (long iindex) |
Sets index based upon current verse. More... | |
virtual ListKey | ParseVerseList (const char *buf, const char *defaultKey="Genesis 1:1", bool expandRange=false) |
virtual int | compare (const SWKey &ikey) |
Compares another SWKey object. More... | |
virtual int | _compare (const VerseKey &ikey) |
Compares another VerseKey object. More... | |
virtual void | setBookAbbrevs (const struct abbrev *bookAbbrevs, unsigned int size=0) |
virtual void | setBooks (const char *iBMAX, struct sbook **ibooks) |
virtual void | setLocale (const char *name) |
virtual const char * | getLocale () const |
virtual SWKEY_OPERATORS SWKey & | operator= (const VerseKey &ikey) |
Public Attributes | |
const char * | BMAX |
sbook ** | books |
Static Public Attributes | |
const char | builtin_BMAX [2] = {39, 27} |
sbook * | builtin_books [2] = {0,0} |
const struct abbrev | builtin_abbrevs [] |
Private Methods | |
int | getBookAbbrev (const char *abbr) |
void | initBounds () const |
void | initstatics () |
initialize and allocate books array. | |
void | init () |
initializes this VerseKey(). | |
void | freshtext () const |
Refresh keytext based on testament|book|chapter|verse default auto normalization to true default display headings option is false. | |
virtual char | parse () |
Parse a character array into testament|book|chapter|verse. | |
int | findindex (long *array, int size, long value) |
Binary search to find the index closest, but less than the given value. More... | |
Private Attributes | |
ListKey | internalListKey |
const struct abbrev * | abbrevs |
char * | locale |
int | abbrevsCnt |
signed char | testament |
The Testament: 0 - Old; 1 - New. | |
signed char | book |
signed int | chapter |
signed int | verse |
char | autonorm |
flag for auto normalization. | |
char | headings |
flag for headings on/off. | |
VerseKey * | lowerBound |
VerseKey * | upperBound |
Static Private Attributes | |
SWClass | classdef |
long * | offsets [2][2] = {{VerseKey::otbks, VerseKey::otcps}, {VerseKey::ntbks, VerseKey::ntcps}} |
int | offsize [2][2] |
int | instance = 0 |
number of instantiated VerseKey objects or derivitives. | |
sbook | otbooks [] |
sbook | ntbooks [] |
long | otbks [] |
long | otcps [] |
long | ntbks [] |
long | ntcps [] |
int | vm [] |
LocaleCache | localeCache |
Definition at line 72 of file versekey.h.
|
VerseKey Constructor - initializes Instance of VerseKey.
Definition at line 89 of file versekey.cpp. Referenced by clone.
|
|
VerseKey Constructor - initializes instance of VerseKey.
Definition at line 74 of file versekey.cpp.
|
|
VerseKey Constructor - initializes instance of VerseKey with boundariess - see also LowerBound and UpperBound.
Definition at line 111 of file versekey.cpp. References init, LowerBound, setPosition, and UpperBound.
00111 : SWKey() 00112 { 00113 init(); 00114 LowerBound(min); 00115 UpperBound(max); 00116 setPosition(TOP); 00117 } |
|
VerseKey Copy Constructor - will create a new VerseKey based on an existing one.
|
|
Compares another VerseKey object.
Definition at line 1389 of file versekey.cpp. References Book, Chapter, Testament, and Verse. Referenced by compare, Index, and Normalize.
01390 { 01391 long keyval1 = 0; 01392 long keyval2 = 0; 01393 01394 keyval1 += Testament() * 1000000000; 01395 keyval2 += ivkey.Testament() * 1000000000; 01396 keyval1 += Book() * 1000000; 01397 keyval2 += ivkey.Book() * 1000000; 01398 keyval1 += Chapter() * 1000; 01399 keyval2 += ivkey.Chapter() * 1000; 01400 keyval1 += Verse(); 01401 keyval2 += ivkey.Verse(); 01402 keyval1 -= keyval2; 01403 keyval1 = (keyval1) ? ((keyval1 > 0) ? 1 : -1) /*keyval1/labs(keyval1)*/:0; // -1 | 0 | 1 01404 return keyval1; 01405 } |
|
Sets/gets flag that tells VerseKey to automatically normalize itself when modified.
Definition at line 1190 of file versekey.cpp. References autonorm, and Normalize.
|
|
Sets/gets book.
Definition at line 1124 of file versekey.cpp. References Chapter, and Normalize.
|
|
Gets book.
Definition at line 1062 of file versekey.cpp. Referenced by _compare, and setPosition.
01063 { 01064 return book; 01065 } |
|
Sets/gets chapter.
Definition at line 1146 of file versekey.cpp. References Normalize, and Verse.
|
|
Gets chapter.
Definition at line 1074 of file versekey.cpp. Referenced by _compare, Book, and setPosition.
01075 { 01076 return chapter; 01077 } |
|
Compares another SWKey object.
Reimplemented from SWKey. Definition at line 1372 of file versekey.cpp. References _compare.
|
|
Equates this SWKey to another SWKey object.
Reimplemented from SWKey. Definition at line 820 of file versekey.cpp. References SWKey::copyFrom, and parse.
00820 { 00821 SWKey::copyFrom(ikey); 00822 00823 parse(); 00824 } |
|
Decrements key a number of verses.
Reimplemented from SWKey. Definition at line 928 of file versekey.cpp. References SWKey::Error, headings, and Index.
|
|
Binary search to find the index closest, but less than the given value.
Definition at line 1236 of file versekey.cpp. Referenced by Index.
01237 { 01238 int lbound, ubound, tval; 01239 01240 lbound = 0; 01241 ubound = size - 1; 01242 while ((ubound - lbound) > 1) { 01243 tval = lbound + (ubound-lbound)/2; 01244 if (array[tval] <= value) 01245 lbound = tval; 01246 else ubound = tval; 01247 } 01248 return (array[ubound] <= value) ? ubound : lbound; 01249 } |
|
Sets/gets flag that tells VerseKey to include chapter/book/testament/module headings.
Definition at line 1213 of file versekey.cpp. References headings, and Normalize.
|
|
Increments key a number of verses.
Reimplemented from SWKey. Definition at line 908 of file versekey.cpp. References SWKey::Error, headings, and Index.
|
|
Sets index based upon current verse.
Reimplemented from SWKey. Definition at line 1303 of file versekey.cpp. References _compare, findindex, Index, LowerBound, testament, and UpperBound.
01304 { 01305 long offset; 01306 01307 // This is the dirty stuff -------------------------------------------- 01308 01309 if (!testament) 01310 testament = 1; 01311 01312 if (iindex < 1) { // if (-) or module heading 01313 if (testament < 2) { 01314 if (iindex < 0) { 01315 testament = 0; // previously we changed 0 -> 1 01316 error = KEYERR_OUTOFBOUNDS; 01317 } 01318 else testament = 0; // we want module heading 01319 } 01320 else { 01321 testament--; 01322 iindex = (offsets[testament-1][1][offsize[testament-1][1]-1] + books[testament-1][BMAX[testament-1]-1].versemax[books[testament-1][BMAX[testament-1]-1].chapmax-1]) + iindex; // What a doozy! ((offset of last chapter + number of verses in the last chapter) + iindex) 01323 } 01324 } 01325 01326 // -------------------------------------------------------------------- 01327 01328 01329 if (testament) { 01330 if ((!error) && (iindex)) { 01331 offset = findindex(offsets[testament-1][1], offsize[testament-1][1], iindex); 01332 verse = iindex - offsets[testament-1][1][offset]; 01333 book = findindex(offsets[testament-1][0], offsize[testament-1][0], offset); 01334 chapter = offset - offsets[testament-1][0][VerseKey::book]; 01335 verse = (chapter) ? verse : 0; // funny check. if we are index=1 (testmt header) all gets set to 0 exept verse. Don't know why. Fix if you figure out. Think its in the offsets table. 01336 if (verse) { // only check if -1 won't give negative 01337 if (verse > books[testament-1][book-1].versemax[chapter-1]) { 01338 if (testament > 1) { 01339 verse = books[testament-1][book-1].versemax[chapter-1]; 01340 error = KEYERR_OUTOFBOUNDS; 01341 } 01342 else { 01343 testament++; 01344 Index(verse - books[testament-2][book-1].versemax[chapter-1]); 01345 } 01346 } 01347 } 01348 } 01349 } 01350 if (_compare(UpperBound()) > 0) { 01351 *this = UpperBound(); 01352 error = KEYERR_OUTOFBOUNDS; 01353 } 01354 if (_compare(LowerBound()) < 0) { 01355 *this = LowerBound(); 01356 error = KEYERR_OUTOFBOUNDS; 01357 } 01358 return Index(); 01359 } |
|
Gets index based upon current verse.
Reimplemented from SWKey. Definition at line 1258 of file versekey.cpp. References testament. Referenced by decrement, increment, and Index.
01259 { 01260 long offset; 01261 01262 if (!testament) { // if we want module heading 01263 offset = 0; 01264 verse = 0; 01265 } 01266 else { 01267 if (!book) 01268 chapter = 0; 01269 if (!chapter) 01270 verse = 0; 01271 01272 offset = offsets[testament-1][0][book]; 01273 offset = offsets[testament-1][1][(int)offset + chapter]; 01274 if (!(offset|verse)) // if we have a testament but nothing else. 01275 offset = 1; 01276 } 01277 return (offset + verse); 01278 } |
|
gets the lower boundary of this VerseKey.
Definition at line 748 of file versekey.cpp. Referenced by Index, Normalize, setPosition, and VerseKey.
00749 { 00750 if (!lowerBound) 00751 initBounds(); 00752 00753 return (*lowerBound); 00754 } |
|
sets the lower boundary for this VerseKey and returns the new boundary.
Definition at line 692 of file versekey.cpp. References Normalize.
00693 { 00694 if (!lowerBound) 00695 initBounds(); 00696 00697 (*lowerBound) = lb; 00698 lowerBound->Normalize(); 00699 00700 return (*lowerBound); 00701 } |
|
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
Definition at line 950 of file versekey.cpp. References _compare, autonorm, headings, LowerBound, testament, and UpperBound. Referenced by AutoNormalize, Book, Chapter, Headings, LowerBound, parse, setPosition, Testament, UpperBound, and Verse.
00951 { 00952 error = 0; 00953 00954 if ((autocheck) && (!autonorm)) // only normalize if we were explicitely called or if autonorm is turned on 00955 return; 00956 00957 if ((headings) && (!verse)) // this is cheeze and temporary until deciding what actions should be taken. 00958 return; // so headings should only be turned on when positioning with Index() or incrementors 00959 00960 while ((testament < 3) && (testament > 0)) { 00961 00962 if (book > BMAX[testament-1]) { 00963 book -= BMAX[testament-1]; 00964 testament++; 00965 continue; 00966 } 00967 00968 if (book < 1) { 00969 if (--testament > 0) { 00970 book += BMAX[testament-1]; 00971 } 00972 continue; 00973 } 00974 00975 if (chapter > books[testament-1][book-1].chapmax) { 00976 chapter -= books[testament-1][book-1].chapmax; 00977 book++; 00978 continue; 00979 } 00980 00981 if (chapter < 1) { 00982 if (--book > 0) { 00983 chapter += books[testament-1][book-1].chapmax; 00984 } 00985 else { 00986 if (testament > 1) { 00987 chapter += books[0][BMAX[0]-1].chapmax; 00988 } 00989 } 00990 continue; 00991 } 00992 00993 if (verse > books[testament-1][book-1].versemax[chapter-1]) { // -1 because e.g chapter 1 of Matthew is books[1][0].versemax[0] 00994 verse -= books[testament-1][book-1].versemax[chapter++ - 1]; 00995 continue; 00996 } 00997 00998 if (verse < 1) { 00999 if (--chapter > 0) { 01000 verse += books[testament-1][book-1].versemax[chapter-1]; 01001 } 01002 else { 01003 if (book > 1) { 01004 verse += books[testament-1][book-2].versemax[books[testament-1][book-2].chapmax-1]; 01005 } 01006 else { 01007 if (testament > 1) { 01008 verse += books[0][BMAX[0]-1].versemax[books[0][BMAX[0]-1].chapmax-1]; 01009 } 01010 } 01011 } 01012 continue; 01013 } 01014 01015 break; // If we've made it this far (all failure checks continue) we're ok 01016 } 01017 01018 if (testament > 2) { 01019 testament = 2; 01020 book = BMAX[testament-1]; 01021 chapter = books[testament-1][book-1].chapmax; 01022 verse = books[testament-1][book-1].versemax[chapter-1]; 01023 error = KEYERR_OUTOFBOUNDS; 01024 } 01025 01026 if (testament < 1) { 01027 error = ((!headings) || (testament < 0) || (book < 0)) ? KEYERR_OUTOFBOUNDS : 0; 01028 testament = ((headings) ? 0 : 1); 01029 book = ((headings) ? 0 : 1); 01030 chapter = ((headings) ? 0 : 1); 01031 verse = ((headings) ? 0 : 1); 01032 } 01033 if (_compare(UpperBound()) > 0) { 01034 *this = UpperBound(); 01035 error = KEYERR_OUTOFBOUNDS; 01036 } 01037 if (_compare(LowerBound()) < 0) { 01038 *this = LowerBound(); 01039 error = KEYERR_OUTOFBOUNDS; 01040 } 01041 } |
|
Positions this key.
Reimplemented from SWKey. Definition at line 871 of file versekey.cpp. References Book, Chapter, SWKey::Error, LowerBound, Normalize, Testament, testament, UpperBound, and Verse. Referenced by VerseKey.
00871 { 00872 switch (p) { 00873 case POS_TOP: 00874 testament = LowerBound().Testament(); 00875 book = LowerBound().Book(); 00876 chapter = LowerBound().Chapter(); 00877 verse = LowerBound().Verse(); 00878 break; 00879 case POS_BOTTOM: 00880 testament = UpperBound().Testament(); 00881 book = UpperBound().Book(); 00882 chapter = UpperBound().Chapter(); 00883 verse = UpperBound().Verse(); 00884 break; 00885 case POS_MAXVERSE: 00886 Normalize(); 00887 verse = books[testament-1][book-1].versemax[chapter-1]; 00888 break; 00889 case POS_MAXCHAPTER: 00890 verse = 1; 00891 Normalize(); 00892 chapter = books[testament-1][book-1].chapmax; 00893 break; 00894 } 00895 Normalize(1); 00896 Error(); // clear error from normalize 00897 } |
|
Equates this SWKey to a character string.
Reimplemented from SWKey. Definition at line 236 of file versekey.h. References SWKey::setText.
00236 { SWKey::setText(ikey); parse (); } |
|
Sets/gets testament.
Definition at line 1102 of file versekey.cpp. References Normalize, and testament.
|
|
Gets testament.
Definition at line 1050 of file versekey.cpp. References testament. Referenced by _compare, and setPosition.
01051 { 01052 return testament; 01053 } |
|
gets the upper boundary of this VerseKey.
Definition at line 761 of file versekey.cpp. Referenced by Index, Normalize, setPosition, and VerseKey.
00762 { 00763 if (!upperBound) 00764 initBounds(); 00765 00766 return (*upperBound); 00767 } |
|
sets the upper boundary for this VerseKey and returns the new boundary.
Definition at line 708 of file versekey.cpp. References Normalize.
00709 { 00710 if (!upperBound) 00711 initBounds(); 00712 00713 // need to set upperbound parsing to resolve to max verse/chap if not specified 00714 (*upperBound) = ub; 00715 if (*upperBound < *lowerBound) 00716 *upperBound = *lowerBound; 00717 upperBound->Normalize(); 00718 00719 // until we have a proper method to resolve max verse/chap use this kludge 00720 int len = strlen(ub); 00721 bool alpha = false; 00722 bool versespec = false; 00723 bool chapspec = false; 00724 for (int i = 0; i < len; i++) { 00725 if (isalpha(ub[i])) 00726 alpha = true; 00727 if (ub[i] == ':') // if we have a : we assume verse spec 00728 versespec = true; 00729 if ((isdigit(ub[i])) && (alpha)) // if digit after alpha assume chap spec 00730 chapspec = true; 00731 } 00732 if (!chapspec) 00733 *upperBound = MAXCHAPTER; 00734 if (!versespec) 00735 *upperBound = MAXVERSE; 00736 00737 00738 // -- end kludge 00739 00740 return (*upperBound); 00741 } |
|
Sets/gets verse.
Definition at line 1168 of file versekey.cpp. References Normalize.
01169 { 01170 int retval = verse; 01171 01172 verse = iverse; 01173 Normalize(1); 01174 01175 return retval; 01176 } |
|
Gets verse.
Definition at line 1086 of file versekey.cpp. Referenced by _compare, Chapter, and setPosition.
01087 { 01088 return verse; 01089 } |