1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
/******************************************************************************
* swcom.cpp - code for base class 'SWCom'- The basis for all commentary
* modules
*
*
* Copyright 2009 CrossWire Bible Society (http://www.crosswire.org)
* CrossWire Bible Society
* P. O. Box 2528
* Tempe, AZ 85280-2528
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation version 2.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
*/
#include <utilstr.h>
#include <swcom.h>
#include <localemgr.h>
#include <versekey.h>
SWORD_NAMESPACE_START
/******************************************************************************
* SWCom Constructor - Initializes data for instance of SWCom
*
* ENT: imodname - Internal name for module
* imoddesc - Name to display to user for module
* idisp - Display object to use for displaying
*/
SWCom::SWCom(const char *imodname, const char *imoddesc, SWDisplay *idisp, SWTextEncoding enc, SWTextDirection dir, SWTextMarkup mark, const char *ilang, const char *versification): SWModule(imodname, imoddesc, idisp, "Commentaries", enc, dir, mark, ilang) {
this->versification = 0;
stdstr(&(this->versification), versification);
delete key;
key = (VerseKey *)CreateKey();
tmpVK1 = (VerseKey *)CreateKey();
tmpVK2 = (VerseKey *)CreateKey();
tmpSecond = false;
}
/******************************************************************************
* SWCom Destructor - Cleans up instance of SWCom
*/
SWCom::~SWCom() {
delete tmpVK1;
delete tmpVK2;
delete [] versification;
}
SWKey *SWCom::CreateKey() const {
VerseKey *vk = new VerseKey();
vk->setVersificationSystem(versification);
return vk;
}
long SWCom::Index() const {
VerseKey *key = &getVerseKey();
entryIndex = key->Index();
return entryIndex;
}
long SWCom::Index(long iindex) {
VerseKey *key = &getVerseKey();
key->Testament(1);
key->Index(iindex);
if (key != this->key) {
this->key->copyFrom(*key);
}
return Index();
}
VerseKey &SWCom::getVerseKey(const SWKey *keyToConvert) const {
const SWKey *thisKey = keyToConvert ? keyToConvert : this->key;
VerseKey *key = 0;
// see if we have a VerseKey * or decendant
SWTRY {
key = SWDYNAMIC_CAST(VerseKey, thisKey);
}
SWCATCH ( ... ) { }
if (!key) {
ListKey *lkTest = 0;
SWTRY {
lkTest = SWDYNAMIC_CAST(ListKey, thisKey);
}
SWCATCH ( ... ) { }
if (lkTest) {
SWTRY {
key = SWDYNAMIC_CAST(VerseKey, lkTest->GetElement());
}
SWCATCH ( ... ) { }
}
}
if (!key) {
VerseKey *retKey = (tmpSecond) ? tmpVK1 : tmpVK2;
tmpSecond = !tmpSecond;
retKey->setLocale(LocaleMgr::getSystemLocaleMgr()->getDefaultLocaleName());
(*retKey) = *(thisKey);
return (*retKey);
}
else return *key;
}
SWORD_NAMESPACE_END
|