aboutsummaryrefslogtreecommitdiffstats
path: root/src/modules
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules')
-rw-r--r--src/modules/comments/rawcom/rawcom.cpp98
-rw-r--r--src/modules/comments/zcom/zcom.cpp103
-rw-r--r--src/modules/common/rawstr.cpp2
-rw-r--r--src/modules/texts/rawtext/rawtext.cpp118
-rw-r--r--src/modules/texts/ztext/ztext.cpp119
5 files changed, 152 insertions, 288 deletions
diff --git a/src/modules/comments/rawcom/rawcom.cpp b/src/modules/comments/rawcom/rawcom.cpp
index de400d6..c9cfcd5 100644
--- a/src/modules/comments/rawcom/rawcom.cpp
+++ b/src/modules/comments/rawcom/rawcom.cpp
@@ -54,15 +54,7 @@ RawCom::~RawCom()
char *RawCom::getRawEntry() {
long start = 0;
unsigned short size = 0;
- VerseKey *key = 0;
-
- try {
- key = SWDYNAMIC_CAST(VerseKey, this->key);
- }
- catch ( ... ) {}
- if (!key)
- key = new VerseKey(this->key);
-
+ VerseKey *key = &getVerseKey();
findoffset(key->Testament(), key->Index(), &start, &size);
entrySize = size; // support getEntrySize call
@@ -85,9 +77,6 @@ char *RawCom::getRawEntry() {
if (!isUnicode())
preptext(entrybuf);
- if (key != this->key)
- delete key;
-
return entrybuf;
}
@@ -103,14 +92,7 @@ char *RawCom::getRawEntry() {
void RawCom::increment(int steps) {
long start;
unsigned short size;
- VerseKey *tmpkey = 0;
-
- try {
- tmpkey = SWDYNAMIC_CAST(VerseKey, key);
- }
- catch ( ... ) {}
- if (!tmpkey)
- tmpkey = new VerseKey(key);
+ VerseKey *tmpkey = &getVerseKey();
findoffset(tmpkey->Testament(), tmpkey->Index(), &start, &size);
@@ -120,15 +102,7 @@ void RawCom::increment(int steps) {
unsigned short lastsize = size;
SWKey lasttry = *tmpkey;
(steps > 0) ? (*key)++ : (*key)--;
- if (tmpkey != key)
- delete tmpkey;
- tmpkey = 0;
- try {
- tmpkey = SWDYNAMIC_CAST(VerseKey, key);
- }
- catch ( ... ) {}
- if (!tmpkey)
- tmpkey = new VerseKey(key);
+ tmpkey = &getVerseKey();
if ((error = key->Error())) {
*key = lastgood;
@@ -145,41 +119,18 @@ void RawCom::increment(int steps) {
}
}
error = (error) ? KEYERR_OUTOFBOUNDS : 0;
-
- if (tmpkey != key)
- delete tmpkey;
}
void RawCom::setEntry(const char *inbuf, long len) {
- VerseKey *key = 0;
- // see if we have a VerseKey * or decendant
- try {
- key = SWDYNAMIC_CAST(VerseKey, this->key);
- }
- catch ( ... ) {}
- // if we don't have a VerseKey * decendant, create our own
- if (!key)
- key = new VerseKey(this->key);
-
+ VerseKey *key = &getVerseKey();
settext(key->Testament(), key->Index(), inbuf, len);
-
- if (this->key != key) // free our key if we created a VerseKey
- delete key;
}
void RawCom::linkEntry(const SWKey *inkey) {
- VerseKey *destkey = 0;
+ VerseKey *destkey = &getVerseKey();
const VerseKey *srckey = 0;
- // see if we have a VerseKey * or decendant
- try {
- destkey = SWDYNAMIC_CAST(VerseKey, this->key);
- }
- catch ( ... ) {}
- // if we don't have a VerseKey * decendant, create our own
- if (!destkey)
- destkey = new VerseKey(this->key);
// see if we have a VerseKey * or decendant
try {
@@ -192,9 +143,6 @@ void RawCom::linkEntry(const SWKey *inkey) {
linkentry(destkey->Testament(), destkey->Index(), srckey->Index());
- if (this->key != destkey) // free our key if we created a VerseKey
- delete destkey;
-
if (inkey != srckey) // free our key if we created a VerseKey
delete srckey;
}
@@ -208,19 +156,37 @@ void RawCom::linkEntry(const SWKey *inkey) {
void RawCom::deleteEntry() {
- VerseKey *key = 0;
+ VerseKey *key = &getVerseKey();
+ settext(key->Testament(), key->Index(), "");
+}
+
+VerseKey &RawCom::getVerseKey() {
+ static VerseKey tmpVK;
+ VerseKey *key;
+ // see if we have a VerseKey * or decendant
try {
key = SWDYNAMIC_CAST(VerseKey, this->key);
}
- catch ( ... ) {}
- if (!key)
- key = new VerseKey(this->key);
-
- settext(key->Testament(), key->Index(), "");
-
- if (key != this->key)
- delete key;
+ catch ( ... ) { }
+ if (!key) {
+ ListKey *lkTest = 0;
+ try {
+ lkTest = SWDYNAMIC_CAST(ListKey, this->key);
+ }
+ catch ( ... ) { }
+ if (lkTest) {
+ try {
+ key = SWDYNAMIC_CAST(VerseKey, lkTest->GetElement());
+ }
+ catch ( ... ) { }
+ }
+ }
+ if (!key) {
+ tmpVK = *(this->key);
+ return tmpVK;
+ }
+ else return *key;
}
diff --git a/src/modules/comments/zcom/zcom.cpp b/src/modules/comments/zcom/zcom.cpp
index 7d5d3c2..b3a10de 100644
--- a/src/modules/comments/zcom/zcom.cpp
+++ b/src/modules/comments/zcom/zcom.cpp
@@ -58,15 +58,7 @@ zCom::~zCom() {
char *zCom::getRawEntry() {
long start = 0;
unsigned short size = 0;
- VerseKey *key = 0;
-
- try {
- key = SWDYNAMIC_CAST(VerseKey, this->key);
- }
- catch ( ... ) {}
- // if we don't have a VerseKey * decendant, create our own
- if (!key)
- key = new VerseKey(this->key);
+ VerseKey *key = &getVerseKey();
findoffset(key->Testament(), key->Index(), &start, &size);
entrySize = size; // support getEntrySize call
@@ -87,9 +79,6 @@ char *zCom::getRawEntry() {
if (!isUnicode())
preptext(entrybuf);
- if (this->key != key) // free our key if we created a VerseKey
- delete key;
-
return entrybuf;
}
@@ -113,16 +102,7 @@ bool zCom::sameBlock(VerseKey *k1, VerseKey *k2) {
}
void zCom::setEntry(const char *inbuf, long len) {
- VerseKey *key = 0;
- // see if we have a VerseKey * or decendant
- try {
- key = SWDYNAMIC_CAST(VerseKey, this->key);
- }
- catch ( ... ) {}
- // if we don't have a VerseKey * decendant, create our own
- if (!key)
- key = new VerseKey(this->key);
-
+ VerseKey *key = &getVerseKey();
// see if we've jumped across blocks since last write
if (lastWriteKey) {
@@ -135,23 +115,12 @@ void zCom::setEntry(const char *inbuf, long len) {
settext(key->Testament(), key->Index(), inbuf, len);
lastWriteKey = (VerseKey *)key->clone(); // must delete
-
- if (this->key != key) // free our key if we created a VerseKey
- delete key;
}
void zCom::linkEntry(const SWKey *inkey) {
- VerseKey *destkey = 0;
+ VerseKey *destkey = &getVerseKey();
const VerseKey *srckey = 0;
- // see if we have a VerseKey * or decendant
- try {
- destkey = SWDYNAMIC_CAST(VerseKey, this->key);
- }
- catch ( ... ) {}
- // if we don't have a VerseKey * decendant, create our own
- if (!destkey)
- destkey = new VerseKey(this->key);
// see if we have a VerseKey * or decendant
try {
@@ -165,9 +134,6 @@ void zCom::linkEntry(const SWKey *inkey) {
linkentry(destkey->Testament(), destkey->Index(), srckey->Index());
- if (this->key != destkey) // free our key if we created a VerseKey
- delete destkey;
-
if (inkey != srckey) // free our key if we created a VerseKey
delete srckey;
}
@@ -180,19 +146,8 @@ void zCom::linkEntry(const SWKey *inkey) {
void zCom::deleteEntry() {
- VerseKey *key = 0;
-
- try {
- key = SWDYNAMIC_CAST(VerseKey, this->key);
- }
- catch ( ... ) {}
- if (!key)
- key = new VerseKey(this->key);
-
+ VerseKey *key = &getVerseKey();
settext(key->Testament(), key->Index(), "");
-
- if (key != this->key)
- delete key;
}
@@ -207,14 +162,7 @@ void zCom::deleteEntry() {
void zCom::increment(int steps) {
long start;
unsigned short size;
- VerseKey *tmpkey = 0;
-
- try {
- tmpkey = SWDYNAMIC_CAST(VerseKey, key);
- }
- catch ( ... ) {}
- if (!tmpkey)
- tmpkey = new VerseKey(key);
+ VerseKey *tmpkey = &getVerseKey();
findoffset(tmpkey->Testament(), tmpkey->Index(), &start, &size);
@@ -224,15 +172,7 @@ void zCom::increment(int steps) {
unsigned short lastsize = size;
SWKey lasttry = *tmpkey;
(steps > 0) ? (*key)++ : (*key)--;
- if (tmpkey != key)
- delete tmpkey;
- tmpkey = 0;
- try {
- tmpkey = SWDYNAMIC_CAST(VerseKey, key);
- }
- catch ( ... ) {}
- if (!tmpkey)
- tmpkey = new VerseKey(key);
+ tmpkey = &getVerseKey();
if ((error = key->Error())) {
*key = lastgood;
@@ -249,9 +189,36 @@ void zCom::increment(int steps) {
}
}
error = (error) ? KEYERR_OUTOFBOUNDS : 0;
+}
+
- if (tmpkey != key)
- delete tmpkey;
+VerseKey &zCom::getVerseKey() {
+ static VerseKey tmpVK;
+ VerseKey *key;
+ // see if we have a VerseKey * or decendant
+ try {
+ key = SWDYNAMIC_CAST(VerseKey, this->key);
+ }
+ catch ( ... ) { }
+ if (!key) {
+ ListKey *lkTest = 0;
+ try {
+ lkTest = SWDYNAMIC_CAST(ListKey, this->key);
+ }
+ catch ( ... ) { }
+ if (lkTest) {
+ try {
+ key = SWDYNAMIC_CAST(VerseKey, lkTest->GetElement());
+ }
+ catch ( ... ) { }
+ }
+ }
+ if (!key) {
+ tmpVK = *(this->key);
+ return tmpVK;
+ }
+ else return *key;
}
+
SWORD_NAMESPACE_END
diff --git a/src/modules/common/rawstr.cpp b/src/modules/common/rawstr.cpp
index a9f9c1d..eeb3bf8 100644
--- a/src/modules/common/rawstr.cpp
+++ b/src/modules/common/rawstr.cpp
@@ -171,7 +171,7 @@ signed char RawStr::findoffset(const char *ikey, long *start, unsigned short *si
if (*ikey) {
headoff = 0;
- key = new char [ strlen(ikey) + 10 ]; // just in case toupper needs a few extra
+ key = new char [ (strlen(ikey)*2) + 10 ]; // just in case toupper needs a few extra
strcpy(key, ikey);
toupperstr_utf8(key);
diff --git a/src/modules/texts/rawtext/rawtext.cpp b/src/modules/texts/rawtext/rawtext.cpp
index fe14e9b..ef7742a 100644
--- a/src/modules/texts/rawtext/rawtext.cpp
+++ b/src/modules/texts/rawtext/rawtext.cpp
@@ -77,6 +77,35 @@ RawText::~RawText()
}
+VerseKey &RawText::getVerseKey() {
+ static VerseKey tmpVK;
+ VerseKey *key;
+ // see if we have a VerseKey * or decendant
+ try {
+ key = SWDYNAMIC_CAST(VerseKey, this->key);
+ }
+ catch ( ... ) { }
+ if (!key) {
+ ListKey *lkTest = 0;
+ try {
+ lkTest = SWDYNAMIC_CAST(ListKey, this->key);
+ }
+ catch ( ... ) { }
+ if (lkTest) {
+ try {
+ key = SWDYNAMIC_CAST(VerseKey, lkTest->GetElement());
+ }
+ catch ( ... ) { }
+ }
+ }
+ if (!key) {
+ tmpVK = *(this->key);
+ return tmpVK;
+ }
+ else return *key;
+}
+
+
/******************************************************************************
* RawText::getRawEntry - Returns the correct verse when char * cast
* is requested
@@ -87,18 +116,9 @@ RawText::~RawText()
char *RawText::getRawEntry() {
long start = 0;
unsigned short size = 0;
- VerseKey *key = 0;
+ VerseKey &key = getVerseKey();
- // see if we have a VerseKey * or decendant
- try {
- key = SWDYNAMIC_CAST(VerseKey, this->key);
- }
- catch ( ... ) { }
- // if we don't have a VerseKey * decendant, create our own
- if (!key)
- key = new VerseKey(this->key);
-
- findoffset(key->Testament(), key->Index(), &start, &size);
+ findoffset(key.Testament(), key.Index(), &start, &size);
entrySize = size; // support getEntrySize call
unsigned long newsize = (size + 2) * FILTERPAD;
@@ -110,18 +130,15 @@ char *RawText::getRawEntry() {
}
*entrybuf = 0;
- readtext(key->Testament(), start, (size + 2), entrybuf);
+ readtext(key.Testament(), start, (size + 2), entrybuf);
entrybuf[size] = 0;
rawFilter(entrybuf, size, 0); // hack, decipher
- rawFilter(entrybuf, size*FILTERPAD, key);
+ rawFilter(entrybuf, size*FILTERPAD, &key);
if (!isUnicode())
preptext(entrybuf);
- if (this->key != key) // free our key if we created a VerseKey
- delete key;
-
return entrybuf;
}
@@ -458,34 +475,14 @@ ListKey &RawText::Search(const char *istr, int searchType, int flags, SWKey *sco
void RawText::setEntry(const char *inbuf, long len) {
- VerseKey *key = 0;
- // see if we have a VerseKey * or decendant
- try {
- key = SWDYNAMIC_CAST(VerseKey, this->key);
- }
- catch ( ... ) {}
- // if we don't have a VerseKey * decendant, create our own
- if (!key)
- key = new VerseKey(this->key);
-
- settext(key->Testament(), key->Index(), inbuf, len);
-
- if (this->key != key) // free our key if we created a VerseKey
- delete key;
+ VerseKey &key = getVerseKey();
+ settext(key.Testament(), key.Index(), inbuf, len);
}
void RawText::linkEntry(const SWKey *inkey) {
- VerseKey *destkey = 0;
+ VerseKey &destkey = getVerseKey();
const VerseKey *srckey = 0;
- // see if we have a VerseKey * or decendant
- try {
- destkey = SWDYNAMIC_CAST(VerseKey, this->key);
- }
- catch ( ... ) {}
- // if we don't have a VerseKey * decendant, create our own
- if (!destkey)
- destkey = new VerseKey(this->key);
// see if we have a VerseKey * or decendant
try {
@@ -496,10 +493,7 @@ void RawText::linkEntry(const SWKey *inkey) {
if (!srckey)
srckey = new VerseKey(inkey);
- linkentry(destkey->Testament(), destkey->Index(), srckey->Index());
-
- if (this->key != destkey) // free our key if we created a VerseKey
- delete destkey;
+ linkentry(destkey.Testament(), destkey.Index(), srckey->Index());
if (inkey != srckey) // free our key if we created a VerseKey
delete srckey;
@@ -513,20 +507,8 @@ void RawText::linkEntry(const SWKey *inkey) {
*/
void RawText::deleteEntry() {
-
- VerseKey *key = 0;
-
- try {
- key = SWDYNAMIC_CAST(VerseKey, this->key);
- }
- catch ( ... ) {}
- if (!key)
- key = new VerseKey(this->key);
-
- settext(key->Testament(), key->Index(), "");
-
- if (key != this->key)
- delete key;
+ VerseKey &key = getVerseKey();
+ settext(key.Testament(), key.Index(), "");
}
/******************************************************************************
@@ -540,14 +522,7 @@ void RawText::deleteEntry() {
void RawText::increment(int steps) {
long start;
unsigned short size;
- VerseKey *tmpkey = 0;
-
- try {
- tmpkey = SWDYNAMIC_CAST(VerseKey, key);
- }
- catch ( ... ) {}
- if (!tmpkey)
- tmpkey = new VerseKey(key);
+ VerseKey *tmpkey = &getVerseKey();
findoffset(tmpkey->Testament(), tmpkey->Index(), &start, &size);
@@ -557,15 +532,7 @@ void RawText::increment(int steps) {
unsigned short lastsize = size;
SWKey lasttry = *tmpkey;
(steps > 0) ? (*key)++ : (*key)--;
- if (tmpkey != key)
- delete tmpkey;
- tmpkey = 0;
- try {
- tmpkey = SWDYNAMIC_CAST(VerseKey, key);
- }
- catch ( ... ) {}
- if (!tmpkey)
- tmpkey = new VerseKey(key);
+ tmpkey = &getVerseKey();
if ((error = key->Error())) {
*key = lastgood;
@@ -582,9 +549,6 @@ void RawText::increment(int steps) {
}
}
error = (error) ? KEYERR_OUTOFBOUNDS : 0;
-
- if (tmpkey != key)
- delete tmpkey;
}
SWORD_NAMESPACE_END
diff --git a/src/modules/texts/ztext/ztext.cpp b/src/modules/texts/ztext/ztext.cpp
index fe90216..00793c2 100644
--- a/src/modules/texts/ztext/ztext.cpp
+++ b/src/modules/texts/ztext/ztext.cpp
@@ -63,18 +63,9 @@ char *zText::getRawEntry()
{
long start = 0;
unsigned short size = 0;
- VerseKey *key = 0;
+ VerseKey &key = getVerseKey();
- // see if we have a VerseKey * or decendant
- try {
- key = SWDYNAMIC_CAST(VerseKey, this->key);
- }
- catch ( ... ) {}
- // if we don't have a VerseKey * decendant, create our own
- if (!key)
- key = new VerseKey(this->key);
-
- findoffset(key->Testament(), key->Index(), &start, &size);
+ findoffset(key.Testament(), key.Index(), &start, &size);
entrySize = size; // support getEntrySize call
unsigned long newsize = (size + 2) * FILTERPAD;
@@ -86,16 +77,13 @@ char *zText::getRawEntry()
}
*entrybuf = 0;
- zreadtext(key->Testament(), start, (size + 2), entrybuf);
+ zreadtext(key.Testament(), start, (size + 2), entrybuf);
- rawFilter(entrybuf, size*FILTERPAD, key);
+ rawFilter(entrybuf, size*FILTERPAD, &key);
if (!isUnicode())
preptext(entrybuf);
- if (this->key != key) // free our key if we created a VerseKey
- delete key;
-
return entrybuf;
}
@@ -120,45 +108,25 @@ bool zText::sameBlock(VerseKey *k1, VerseKey *k2) {
void zText::setEntry(const char *inbuf, long len) {
- VerseKey *key = 0;
- // see if we have a VerseKey * or decendant
- try {
- key = SWDYNAMIC_CAST(VerseKey, this->key);
- }
- catch ( ... ) {}
- // if we don't have a VerseKey * decendant, create our own
- if (!key)
- key = new VerseKey(this->key);
-
+ VerseKey &key = getVerseKey();
// see if we've jumped across blocks since last write
if (lastWriteKey) {
- if (!sameBlock(lastWriteKey, key)) {
+ if (!sameBlock(lastWriteKey, &key)) {
flushCache();
}
delete lastWriteKey;
}
- settext(key->Testament(), key->Index(), inbuf, len);
-
- lastWriteKey = (VerseKey *)key->clone(); // must delete
+ settext(key.Testament(), key.Index(), inbuf, len);
- if (this->key != key) // free our key if we created a VerseKey
- delete key;
+ lastWriteKey = (VerseKey *)key.clone(); // must delete
}
void zText::linkEntry(const SWKey *inkey) {
- VerseKey *destkey = 0;
+ VerseKey &destkey = getVerseKey();
const VerseKey *srckey = 0;
- // see if we have a VerseKey * or decendant
- try {
- destkey = SWDYNAMIC_CAST(VerseKey, this->key);
- }
- catch ( ... ) {}
- // if we don't have a VerseKey * decendant, create our own
- if (!destkey)
- destkey = new VerseKey(this->key);
// see if we have a VerseKey * or decendant
try {
@@ -170,10 +138,7 @@ void zText::linkEntry(const SWKey *inkey) {
if (!srckey)
srckey = new VerseKey(inkey);
- linkentry(destkey->Testament(), destkey->Index(), srckey->Index());
-
- if (this->key != destkey) // free our key if we created a VerseKey
- delete destkey;
+ linkentry(destkey.Testament(), destkey.Index(), srckey->Index());
if (inkey != srckey) // free our key if we created a VerseKey
delete srckey;
@@ -187,19 +152,9 @@ void zText::linkEntry(const SWKey *inkey) {
void zText::deleteEntry() {
- VerseKey *key = 0;
+ VerseKey &key = getVerseKey();
- try {
- key = SWDYNAMIC_CAST(VerseKey, this->key);
- }
- catch ( ... ) {}
- if (!key)
- key = new VerseKey(this->key);
-
- settext(key->Testament(), key->Index(), "");
-
- if (key != this->key)
- delete key;
+ settext(key.Testament(), key.Index(), "");
}
@@ -213,14 +168,7 @@ void zText::deleteEntry() {
void zText::increment(int steps) {
long start;
unsigned short size;
- VerseKey *tmpkey = 0;
-
- try {
- tmpkey = SWDYNAMIC_CAST(VerseKey, key);
- }
- catch ( ... ) {}
- if (!tmpkey)
- tmpkey = new VerseKey(key);
+ VerseKey *tmpkey = &getVerseKey();
findoffset(tmpkey->Testament(), tmpkey->Index(), &start, &size);
@@ -230,15 +178,7 @@ void zText::increment(int steps) {
unsigned short lastsize = size;
SWKey lasttry = *tmpkey;
(steps > 0) ? (*key)++ : (*key)--;
- if (tmpkey != key)
- delete tmpkey;
- tmpkey = 0;
- try {
- tmpkey = SWDYNAMIC_CAST(VerseKey, key);
- }
- catch ( ... ) {}
- if (!tmpkey)
- tmpkey = new VerseKey(key);
+ tmpkey = &getVerseKey();
if ((error = key->Error())) {
*key = lastgood;
@@ -256,9 +196,36 @@ void zText::increment(int steps) {
}
}
error = (error) ? KEYERR_OUTOFBOUNDS : 0;
+}
+
- if (tmpkey != key)
- delete tmpkey;
+VerseKey &zText::getVerseKey() {
+ static VerseKey tmpVK;
+ VerseKey *key;
+ // see if we have a VerseKey * or decendant
+ try {
+ key = SWDYNAMIC_CAST(VerseKey, this->key);
+ }
+ catch ( ... ) { }
+ if (!key) {
+ ListKey *lkTest = 0;
+ try {
+ lkTest = SWDYNAMIC_CAST(ListKey, this->key);
+ }
+ catch ( ... ) { }
+ if (lkTest) {
+ try {
+ key = SWDYNAMIC_CAST(VerseKey, lkTest->GetElement());
+ }
+ catch ( ... ) { }
+ }
+ }
+ if (!key) {
+ tmpVK = *(this->key);
+ return tmpVK;
+ }
+ else return *key;
}
+
SWORD_NAMESPACE_END