#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 const char * | getOSISRef () const |
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. References init(), and parse(). Referenced by clone().
|
|
VerseKey Constructor - initializes instance of VerseKey.
Definition at line 74 of file versekey.cpp. References init(), and parse().
|
|
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 1402 of file versekey.cpp. References Book(), Chapter(), Testament(), and Verse(). Referenced by compare(), Index(), and Normalize().
01403 { 01404 long keyval1 = 0; 01405 long keyval2 = 0; 01406 01407 keyval1 += Testament() * 1000000000; 01408 keyval2 += ivkey.Testament() * 1000000000; 01409 keyval1 += Book() * 1000000; 01410 keyval2 += ivkey.Book() * 1000000; 01411 keyval1 += Chapter() * 1000; 01412 keyval2 += ivkey.Chapter() * 1000; 01413 keyval1 += Verse(); 01414 keyval2 += ivkey.Verse(); 01415 keyval1 -= keyval2; 01416 keyval1 = (keyval1) ? ((keyval1 > 0) ? 1 : -1) /*keyval1/labs(keyval1)*/:0; // -1 | 0 | 1 01417 return keyval1; 01418 } |
|
Sets/gets flag that tells VerseKey to automatically normalize itself when modified.
Definition at line 1203 of file versekey.cpp. References autonorm, and Normalize().
|
|
Sets/gets book.
Definition at line 1137 of file versekey.cpp. References Chapter(), and Normalize().
|
|
Gets book.
Definition at line 1075 of file versekey.cpp. Referenced by _compare(), and setPosition().
01076 { 01077 return book; 01078 } |
|
Sets/gets chapter.
Definition at line 1159 of file versekey.cpp. References Normalize(), and Verse().
|
|
Gets chapter.
Definition at line 1087 of file versekey.cpp. Referenced by _compare(), Book(), and setPosition().
01088 { 01089 return chapter; 01090 } |
|
Compares another SWKey object.
Reimplemented from SWKey. Definition at line 1385 of file versekey.cpp. References _compare().
|
|
Equates this SWKey to another SWKey object.
Reimplemented from SWKey. Definition at line 833 of file versekey.cpp. References SWKey::copyFrom(), and parse().
00833 { 00834 SWKey::copyFrom(ikey); 00835 00836 parse(); 00837 } |
|
Decrements key a number of verses.
Reimplemented from SWKey. Definition at line 941 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 1249 of file versekey.cpp. Referenced by Index().
01250 { 01251 int lbound, ubound, tval; 01252 01253 lbound = 0; 01254 ubound = size - 1; 01255 while ((ubound - lbound) > 1) { 01256 tval = lbound + (ubound-lbound)/2; 01257 if (array[tval] <= value) 01258 lbound = tval; 01259 else ubound = tval; 01260 } 01261 return (array[ubound] <= value) ? ubound : lbound; 01262 } |
|
Sets/gets flag that tells VerseKey to include chapter/book/testament/module headings.
Definition at line 1226 of file versekey.cpp. References headings, and Normalize().
|
|
Increments key a number of verses.
Reimplemented from SWKey. Definition at line 921 of file versekey.cpp. References SWKey::Error(), headings, and Index().
|
|
Sets index based upon current verse.
Reimplemented from SWKey. Definition at line 1316 of file versekey.cpp. References _compare(), findindex(), Index(), LowerBound(), testament, and UpperBound().
01317 { 01318 long offset; 01319 01320 // This is the dirty stuff -------------------------------------------- 01321 01322 if (!testament) 01323 testament = 1; 01324 01325 if (iindex < 1) { // if (-) or module heading 01326 if (testament < 2) { 01327 if (iindex < 0) { 01328 testament = 0; // previously we changed 0 -> 1 01329 error = KEYERR_OUTOFBOUNDS; 01330 } 01331 else testament = 0; // we want module heading 01332 } 01333 else { 01334 testament--; 01335 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) 01336 } 01337 } 01338 01339 // -------------------------------------------------------------------- 01340 01341 01342 if (testament) { 01343 if ((!error) && (iindex)) { 01344 offset = findindex(offsets[testament-1][1], offsize[testament-1][1], iindex); 01345 verse = iindex - offsets[testament-1][1][offset]; 01346 book = findindex(offsets[testament-1][0], offsize[testament-1][0], offset); 01347 chapter = offset - offsets[testament-1][0][VerseKey::book]; 01348 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. 01349 if (verse) { // only check if -1 won't give negative 01350 if (verse > books[testament-1][book-1].versemax[chapter-1]) { 01351 if (testament > 1) { 01352 verse = books[testament-1][book-1].versemax[chapter-1]; 01353 error = KEYERR_OUTOFBOUNDS; 01354 } 01355 else { 01356 testament++; 01357 Index(verse - books[testament-2][book-1].versemax[chapter-1]); 01358 } 01359 } 01360 } 01361 } 01362 } 01363 if (_compare(UpperBound()) > 0) { 01364 *this = UpperBound(); 01365 error = KEYERR_OUTOFBOUNDS; 01366 } 01367 if (_compare(LowerBound()) < 0) { 01368 *this = LowerBound(); 01369 error = KEYERR_OUTOFBOUNDS; 01370 } 01371 return Index(); 01372 } |
|
Gets index based upon current verse.
Reimplemented from SWKey. Definition at line 1271 of file versekey.cpp. References testament. Referenced by decrement(), increment(), and Index().
01272 { 01273 long offset; 01274 01275 if (!testament) { // if we want module heading 01276 offset = 0; 01277 verse = 0; 01278 } 01279 else { 01280 if (!book) 01281 chapter = 0; 01282 if (!chapter) 01283 verse = 0; 01284 01285 offset = offsets[testament-1][0][book]; 01286 offset = offsets[testament-1][1][(int)offset + chapter]; 01287 if (!(offset|verse)) // if we have a testament but nothing else. 01288 offset = 1; 01289 } 01290 return (offset + verse); 01291 } |
|
gets the lower boundary of this VerseKey.
Definition at line 761 of file versekey.cpp. Referenced by Index(), Normalize(), setPosition(), and VerseKey().
00762 { 00763 if (!lowerBound) 00764 initBounds(); 00765 00766 return (*lowerBound); 00767 } |
|
sets the lower boundary for this VerseKey and returns the new boundary.
Definition at line 705 of file versekey.cpp. References Normalize().
00706 { 00707 if (!lowerBound) 00708 initBounds(); 00709 00710 (*lowerBound) = lb; 00711 lowerBound->Normalize(); 00712 00713 return (*lowerBound); 00714 } |
|
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 963 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().
00964 { 00965 error = 0; 00966 00967 if ((autocheck) && (!autonorm)) // only normalize if we were explicitely called or if autonorm is turned on 00968 return; 00969 00970 if ((headings) && (!verse)) // this is cheeze and temporary until deciding what actions should be taken. 00971 return; // so headings should only be turned on when positioning with Index() or incrementors 00972 00973 while ((testament < 3) && (testament > 0)) { 00974 00975 if (book > BMAX[testament-1]) { 00976 book -= BMAX[testament-1]; 00977 testament++; 00978 continue; 00979 } 00980 00981 if (book < 1) { 00982 if (--testament > 0) { 00983 book += BMAX[testament-1]; 00984 } 00985 continue; 00986 } 00987 00988 if (chapter > books[testament-1][book-1].chapmax) { 00989 chapter -= books[testament-1][book-1].chapmax; 00990 book++; 00991 continue; 00992 } 00993 00994 if (chapter < 1) { 00995 if (--book > 0) { 00996 chapter += books[testament-1][book-1].chapmax; 00997 } 00998 else { 00999 if (testament > 1) { 01000 chapter += books[0][BMAX[0]-1].chapmax; 01001 } 01002 } 01003 continue; 01004 } 01005 01006 if (verse > books[testament-1][book-1].versemax[chapter-1]) { // -1 because e.g chapter 1 of Matthew is books[1][0].versemax[0] 01007 verse -= books[testament-1][book-1].versemax[chapter++ - 1]; 01008 continue; 01009 } 01010 01011 if (verse < 1) { 01012 if (--chapter > 0) { 01013 verse += books[testament-1][book-1].versemax[chapter-1]; 01014 } 01015 else { 01016 if (book > 1) { 01017 verse += books[testament-1][book-2].versemax[books[testament-1][book-2].chapmax-1]; 01018 } 01019 else { 01020 if (testament > 1) { 01021 verse += books[0][BMAX[0]-1].versemax[books[0][BMAX[0]-1].chapmax-1]; 01022 } 01023 } 01024 } 01025 continue; 01026 } 01027 01028 break; // If we've made it this far (all failure checks continue) we're ok 01029 } 01030 01031 if (testament > 2) { 01032 testament = 2; 01033 book = BMAX[testament-1]; 01034 chapter = books[testament-1][book-1].chapmax; 01035 verse = books[testament-1][book-1].versemax[chapter-1]; 01036 error = KEYERR_OUTOFBOUNDS; 01037 } 01038 01039 if (testament < 1) { 01040 error = ((!headings) || (testament < 0) || (book < 0)) ? KEYERR_OUTOFBOUNDS : 0; 01041 testament = ((headings) ? 0 : 1); 01042 book = ((headings) ? 0 : 1); 01043 chapter = ((headings) ? 0 : 1); 01044 verse = ((headings) ? 0 : 1); 01045 } 01046 if (_compare(UpperBound()) > 0) { 01047 *this = UpperBound(); 01048 error = KEYERR_OUTOFBOUNDS; 01049 } 01050 if (_compare(LowerBound()) < 0) { 01051 *this = LowerBound(); 01052 error = KEYERR_OUTOFBOUNDS; 01053 } 01054 } |
|
Positions this key.
Reimplemented from SWKey. Definition at line 884 of file versekey.cpp. References Book(), Chapter(), SWKey::Error(), LowerBound(), Normalize(), Testament(), testament, UpperBound(), and Verse(). Referenced by VerseKey().
00884 { 00885 switch (p) { 00886 case POS_TOP: 00887 testament = LowerBound().Testament(); 00888 book = LowerBound().Book(); 00889 chapter = LowerBound().Chapter(); 00890 verse = LowerBound().Verse(); 00891 break; 00892 case POS_BOTTOM: 00893 testament = UpperBound().Testament(); 00894 book = UpperBound().Book(); 00895 chapter = UpperBound().Chapter(); 00896 verse = UpperBound().Verse(); 00897 break; 00898 case POS_MAXVERSE: 00899 Normalize(); 00900 verse = books[testament-1][book-1].versemax[chapter-1]; 00901 break; 00902 case POS_MAXCHAPTER: 00903 verse = 1; 00904 Normalize(); 00905 chapter = books[testament-1][book-1].chapmax; 00906 break; 00907 } 00908 Normalize(1); 00909 Error(); // clear error from normalize 00910 } |
|
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 1115 of file versekey.cpp. References Normalize(), and testament.
|
|
Gets testament.
Definition at line 1063 of file versekey.cpp. References testament. Referenced by _compare(), and setPosition().
01064 { 01065 return testament; 01066 } |
|
gets the upper boundary of this VerseKey.
Definition at line 774 of file versekey.cpp. Referenced by Index(), Normalize(), setPosition(), and VerseKey().
00775 { 00776 if (!upperBound) 00777 initBounds(); 00778 00779 return (*upperBound); 00780 } |
|
sets the upper boundary for this VerseKey and returns the new boundary.
Definition at line 721 of file versekey.cpp. References Normalize().
00722 { 00723 if (!upperBound) 00724 initBounds(); 00725 00726 // need to set upperbound parsing to resolve to max verse/chap if not specified 00727 (*upperBound) = ub; 00728 if (*upperBound < *lowerBound) 00729 *upperBound = *lowerBound; 00730 upperBound->Normalize(); 00731 00732 // until we have a proper method to resolve max verse/chap use this kludge 00733 int len = strlen(ub); 00734 bool alpha = false; 00735 bool versespec = false; 00736 bool chapspec = false; 00737 for (int i = 0; i < len; i++) { 00738 if (isalpha(ub[i])) 00739 alpha = true; 00740 if (ub[i] == ':') // if we have a : we assume verse spec 00741 versespec = true; 00742 if ((isdigit(ub[i])) && (alpha)) // if digit after alpha assume chap spec 00743 chapspec = true; 00744 } 00745 if (!chapspec) 00746 *upperBound = MAXCHAPTER; 00747 if (!versespec) 00748 *upperBound = MAXVERSE; 00749 00750 00751 // -- end kludge 00752 00753 return (*upperBound); 00754 } |
|
Sets/gets verse.
Definition at line 1181 of file versekey.cpp. References Normalize().
01182 { 01183 int retval = verse; 01184 01185 verse = iverse; 01186 Normalize(1); 01187 01188 return retval; 01189 } |
|
Gets verse.
Definition at line 1099 of file versekey.cpp. Referenced by _compare(), Chapter(), and setPosition().
01100 { 01101 return verse; 01102 } |