The SWORD Project  1.9.0.svnversion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
swtext.cpp
Go to the documentation of this file.
1 /******************************************************************************
2  *
3  * swtext.cpp - code for base class 'SWText'- The basis for all text
4  * modules
5  *
6  * $Id: swtext.cpp 3821 2020-11-02 18:33:02Z scribe $
7  *
8  * Copyright 1997-2013 CrossWire Bible Society (http://www.crosswire.org)
9  * CrossWire Bible Society
10  * P. O. Box 2528
11  * Tempe, AZ 85280-2528
12  *
13  * This program is free software; you can redistribute it and/or modify it
14  * under the terms of the GNU General Public License as published by the
15  * Free Software Foundation version 2.
16  *
17  * This program is distributed in the hope that it will be useful, but
18  * WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20  * General Public License for more details.
21  *
22  */
23 
24 #include <utilstr.h>
25 #include <swtext.h>
26 #include <listkey.h>
27 #include <localemgr.h>
28 #include <versekey.h>
29 
31 
32 /******************************************************************************
33  * SWText Constructor - Initializes data for instance of SWText
34  *
35  * ENT: imodname - Internal name for module
36  * imoddesc - Name to display to user for module
37  * idisp - Display object to use for displaying
38  */
39 
40 SWText::SWText(const char *imodname, const char *imoddesc, SWDisplay *idisp, SWTextEncoding enc, SWTextDirection dir, SWTextMarkup mark, const char* ilang, const char *versification): SWModule(imodname, imoddesc, idisp, "Biblical Texts", enc, dir, mark, ilang) {
41  this->versification = 0;
42  stdstr(&(this->versification), versification);
43  delete key;
44  key = (VerseKey *)createKey();
45  tmpVK1 = (VerseKey *)createKey();
46  tmpVK2 = (VerseKey *)createKey();
47  tmpSecond = false;
48  skipConsecutiveLinks = false;
49 }
50 
51 
52 /******************************************************************************
53  * SWText Destructor - Cleans up instance of SWText
54  */
55 
57  delete tmpVK1;
58  delete tmpVK2;
59  delete [] versification;
60 }
61 
62 
63 /******************************************************************************
64  * SWText createKey - Create the correct key (VerseKey) for use with SWText
65  */
66 
68  VerseKey *vk = new VerseKey();
69 
71 
72  return vk;
73 }
74 
75 
76 long SWText::getIndex() const {
77  const VerseKey *key = &getVerseKey();
78  entryIndex = key->getIndex();
79 
80  return entryIndex;
81 }
82 
83 void SWText::setIndex(long iindex) {
84  VerseKey *key = &getVerseKey();
85 
86  key->setTestament(1);
87  key->setIndex(iindex);
88 
89  if (key != this->key) {
90  this->key->copyFrom(*key);
91  }
92 }
93 
94 
95 const VerseKey &SWText::getVerseKeyConst(const SWKey *keyToConvert) const {
96  const SWKey *thisKey = keyToConvert ? keyToConvert : this->key;
97 
98  const VerseKey *key = 0;
99  // see if we have a VerseKey * or decendant
100  SWTRY {
101  key = SWDYNAMIC_CAST(const VerseKey, thisKey);
102  }
103  SWCATCH ( ... ) { }
104  if (!key) {
105  const ListKey *lkTest = 0;
106  SWTRY {
107  lkTest = SWDYNAMIC_CAST(const ListKey, thisKey);
108  }
109  SWCATCH ( ... ) { }
110  if (lkTest) {
111  SWTRY {
112  key = SWDYNAMIC_CAST(const VerseKey, lkTest->getElement());
113  }
114  SWCATCH ( ... ) { }
115  }
116  }
117  if (!key) {
118  VerseKey *retKey = (tmpSecond) ? tmpVK1 : tmpVK2;
119  tmpSecond = !tmpSecond;
120  retKey->setLocale(LocaleMgr::getSystemLocaleMgr()->getDefaultLocaleName());
121  (*retKey) = *(thisKey);
122  return (*retKey);
123  }
124  else return *key;
125 }
126 
127 
129  SWKey *thisKey = keyToConvert ? keyToConvert : this->key;
130 
131  VerseKey *key = 0;
132  // see if we have a VerseKey * or decendant
133  SWTRY {
134  key = SWDYNAMIC_CAST(VerseKey, thisKey);
135  }
136  SWCATCH ( ... ) { }
137  if (!key) {
138  ListKey *lkTest = 0;
139  SWTRY {
140  lkTest = SWDYNAMIC_CAST(ListKey, thisKey);
141  }
142  SWCATCH ( ... ) { }
143  if (lkTest) {
144  SWTRY {
145  key = SWDYNAMIC_CAST(VerseKey, lkTest->getElement());
146  }
147  SWCATCH ( ... ) { }
148  }
149  }
150  if (!key) {
151  VerseKey *retKey = (tmpSecond) ? tmpVK1 : tmpVK2;
152  tmpSecond = !tmpSecond;
153  retKey->setLocale(LocaleMgr::getSystemLocaleMgr()->getDefaultLocaleName());
154  (*retKey) = *(thisKey);
155  return (*retKey);
156  }
157  else return *key;
158 }
159 
160 
virtual void setIndex(long iindex)
Definition: versekey.cpp:1718
#define SWTextEncoding
Definition: swmodule.h:78
#define SWORD_NAMESPACE_START
Definition: defs.h:39
virtual SWKey * createKey() const
Definition: swtext.cpp:67
virtual void setIndex(long iindex)
Definition: swtext.cpp:83
SWText(const char *imodname=0, const char *imoddesc=0, SWDisplay *idisp=0, SWTextEncoding encoding=ENC_UNKNOWN, SWTextDirection dir=DIRECTION_LTR, SWTextMarkup markup=FMT_UNKNOWN, const char *ilang=0, const char *versification="KJV")
Definition: swtext.cpp:40
virtual void copyFrom(const SWKey &ikey)
Definition: versekey.cpp:239
#define SWTRY
Definition: defs.h:57
virtual void setTestament(char itestament)
Definition: versekey.cpp:1548
virtual SWKey * getElement(int pos=-1)
Definition: listkey.cpp:270
SWORD_NAMESPACE_START char * stdstr(char **ipstr, const char *istr, unsigned int memPadFactor=1)
Definition: utilstr.h:44
virtual long getIndex() const
Definition: swtext.cpp:76
char * versification
Definition: swtext.h:43
#define SWCATCH(x)
Definition: defs.h:58
const VerseKey & getVerseKeyConst(const SWKey *key=0) const
Definition: swtext.cpp:95
virtual void setVersificationSystem(const char *name)
Definition: versekey.cpp:298
VerseKey * tmpVK1
Definition: swtext.h:40
VerseKey * tmpVK2
Definition: swtext.h:41
virtual ~SWText()
Definition: swtext.cpp:56
static LocaleMgr * getSystemLocaleMgr()
Definition: localemgr.cpp:54
bool skipConsecutiveLinks
Definition: swmodule.h:121
#define SWDYNAMIC_CAST(className, object)
Definition: defs.h:47
const VerseKey & getVerseKey(const SWKey *key=0) const
Definition: swtext.h:46
#define SWTextDirection
Definition: swmodule.h:77
SWKey * key
Definition: swmodule.h:124
#define SWORD_NAMESPACE_END
Definition: defs.h:40
Definition: swkey.h:77
#define SWTextMarkup
Definition: swmodule.h:79
bool tmpSecond
Definition: swtext.h:42
void setLocale(const char *name)
Definition: swkey.h:225
long entryIndex
Definition: swmodule.h:158
virtual long getIndex() const
Definition: versekey.cpp:1681