The SWORD Project  1.9.0.svnversion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
swcom.cpp
Go to the documentation of this file.
1 /******************************************************************************
2  *
3  * swcom.cpp - code for base class 'SWCom'- The basis for all commentary
4  * modules
5  *
6  * $Id: swcom.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 
25 #include <utilstr.h>
26 #include <swcom.h>
27 #include <localemgr.h>
28 #include <versekey.h>
29 
30 
32 
33 
34 /******************************************************************************
35  * SWCom Constructor - Initializes data for instance of SWCom
36  *
37  * ENT: imodname - Internal name for module
38  * imoddesc - Name to display to user for module
39  * idisp - Display object to use for displaying
40  */
41 
42 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) {
43  this->versification = 0;
44  stdstr(&(this->versification), versification);
45  delete key;
46  key = (VerseKey *)createKey();
47  tmpVK1 = (VerseKey *)createKey();
48  tmpVK2 = (VerseKey *)createKey();
49  tmpSecond = false;
50 }
51 
52 
53 /******************************************************************************
54  * SWCom Destructor - Cleans up instance of SWCom
55  */
56 
58  delete tmpVK1;
59  delete tmpVK2;
60  delete [] versification;
61 }
62 
63 
65  VerseKey *vk = new VerseKey();
66 
68 
69  return vk;
70 }
71 
72 
73 long SWCom::getIndex() const {
74  const VerseKey *key = &getVerseKey();
75  entryIndex = key->getIndex();
76  return entryIndex;
77 }
78 
79 void SWCom::setIndex(long iindex) {
80  VerseKey *key = &getVerseKey();
81  key->setTestament(1);
82  key->setIndex(iindex);
83 
84  if (key != this->key) {
85  this->key->copyFrom(*key);
86  }
87 }
88 
89 
90 const VerseKey &SWCom::getVerseKeyConst(const SWKey *keyToConvert) const {
91  const SWKey *thisKey = keyToConvert ? keyToConvert : this->key;
92 
93  const VerseKey *key = 0;
94  // see if we have a VerseKey * or decendant
95  SWTRY {
96  key = SWDYNAMIC_CAST(const VerseKey, thisKey);
97  }
98  SWCATCH ( ... ) { }
99  if (!key) {
100  const ListKey *lkTest = 0;
101  SWTRY {
102  lkTest = SWDYNAMIC_CAST(const ListKey, thisKey);
103  }
104  SWCATCH ( ... ) { }
105  if (lkTest) {
106  SWTRY {
107  key = SWDYNAMIC_CAST(const VerseKey, lkTest->getElement());
108  }
109  SWCATCH ( ... ) { }
110  }
111  }
112  if (!key) {
113  VerseKey *retKey = (tmpSecond) ? tmpVK1 : tmpVK2;
114  tmpSecond = !tmpSecond;
115  retKey->setLocale(LocaleMgr::getSystemLocaleMgr()->getDefaultLocaleName());
116  (*retKey) = *(thisKey);
117  return (*retKey);
118  }
119  else return *key;
120 }
121 
122 
124  SWKey *thisKey = keyToConvert ? keyToConvert : this->key;
125 
126  VerseKey *key = 0;
127  // see if we have a VerseKey * or decendant
128  SWTRY {
129  key = SWDYNAMIC_CAST(VerseKey, thisKey);
130  }
131  SWCATCH ( ... ) { }
132  if (!key) {
133  ListKey *lkTest = 0;
134  SWTRY {
135  lkTest = SWDYNAMIC_CAST(ListKey, thisKey);
136  }
137  SWCATCH ( ... ) { }
138  if (lkTest) {
139  SWTRY {
140  key = SWDYNAMIC_CAST(VerseKey, lkTest->getElement());
141  }
142  SWCATCH ( ... ) { }
143  }
144  }
145  if (!key) {
146  VerseKey *retKey = (tmpSecond) ? tmpVK1 : tmpVK2;
147  tmpSecond = !tmpSecond;
148  retKey->setLocale(LocaleMgr::getSystemLocaleMgr()->getDefaultLocaleName());
149  (*retKey) = *(thisKey);
150  return (*retKey);
151  }
152  else return *key;
153 }
154 
155 
virtual void setIndex(long iindex)
Definition: versekey.cpp:1718
virtual long getIndex() const
Definition: swcom.cpp:73
#define SWTextEncoding
Definition: swmodule.h:78
#define SWORD_NAMESPACE_START
Definition: defs.h:39
const VerseKey & getVerseKeyConst(const SWKey *key=0) const
Definition: swcom.cpp:90
virtual void copyFrom(const SWKey &ikey)
Definition: versekey.cpp:239
#define SWTRY
Definition: defs.h:57
VerseKey * tmpVK1
Definition: swcom.h:52
virtual void setTestament(char itestament)
Definition: versekey.cpp:1548
virtual SWKey * getElement(int pos=-1)
Definition: listkey.cpp:270
VerseKey * tmpVK2
Definition: swcom.h:53
SWORD_NAMESPACE_START char * stdstr(char **ipstr, const char *istr, unsigned int memPadFactor=1)
Definition: utilstr.h:44
char * versification
Definition: swcom.h:55
virtual void setIndex(long iindex)
Definition: swcom.cpp:79
#define SWCATCH(x)
Definition: defs.h:58
virtual void setVersificationSystem(const char *name)
Definition: versekey.cpp:298
static LocaleMgr * getSystemLocaleMgr()
Definition: localemgr.cpp:54
virtual SWKey * createKey() const
Definition: swcom.cpp:64
#define SWDYNAMIC_CAST(className, object)
Definition: defs.h:47
SWCom(const char *imodname=0, const char *imoddesc=0, SWDisplay *idisp=0, SWTextEncoding enc=ENC_UNKNOWN, SWTextDirection dir=DIRECTION_LTR, SWTextMarkup mark=FMT_UNKNOWN, const char *ilang=0, const char *versification="KJV")
Definition: swcom.cpp:42
bool tmpSecond
Definition: swcom.h:54
#define SWTextDirection
Definition: swmodule.h:77
SWKey * key
Definition: swmodule.h:124
#define SWORD_NAMESPACE_END
Definition: defs.h:40
virtual ~SWCom()
Definition: swcom.cpp:57
Definition: swkey.h:77
#define SWTextMarkup
Definition: swmodule.h:79
void setLocale(const char *name)
Definition: swkey.h:225
VerseKey & getVerseKey(SWKey *key=0)
Definition: swcom.cpp:123
long entryIndex
Definition: swmodule.h:158
virtual long getIndex() const
Definition: versekey.cpp:1681