summaryrefslogtreecommitdiff
path: root/include/swkey.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/swkey.h')
-rw-r--r--include/swkey.h64
1 files changed, 40 insertions, 24 deletions
diff --git a/include/swkey.h b/include/swkey.h
index ed62e67..eea2135 100644
--- a/include/swkey.h
+++ b/include/swkey.h
@@ -3,7 +3,7 @@
* types of keys for indexing into modules (e.g. verse, word,
* place, etc.)
*
- * $Id: swkey.h 2121 2007-11-24 16:42:32Z scribe $
+ * $Id: swkey.h 2324 2009-04-20 18:40:15Z scribe $
*
* Copyright 1998 CrossWire Bible Society (http://www.crosswire.org)
* CrossWire Bible Society
@@ -27,6 +27,7 @@
#include <swobject.h>
#include <defs.h>
+#include <utilstr.h>
SWORD_NAMESPACE_START
@@ -34,7 +35,7 @@ SWORD_NAMESPACE_START
#define SWKEY_OPERATORS \
SWKey &operator =(const char *ikey) { setText(ikey); return *this; } \
- SWKey &operator =(const SWKey &ikey) { copyFrom(ikey); return *this; } \
+ SWKey &operator =(const SWKey &ikey) { positionFrom(ikey); return *this; } \
SWKey &operator =(SW_POSITION pos) { setPosition(pos); return *this; } \
operator const char *() const { return getText(); } \
bool operator ==(const SWKey &ikey) { return equals(ikey); } \
@@ -45,8 +46,10 @@ SWORD_NAMESPACE_START
virtual bool operator <=(const SWKey &ikey) { return (compare(ikey) < 1); } \
SWKey &operator -=(int steps) { decrement(steps); return *this; } \
SWKey &operator +=(int steps) { increment(steps); return *this; } \
- SWKey &operator++(int) { return *this += 1; } \
- SWKey &operator--(int) { return *this -= 1; }
+ SWKey &operator ++() { increment(1); return *this; } \
+ SWKey operator ++(int) { SWKey temp = *this; increment(1); return temp; } \
+ SWKey &operator --() { decrement(1); return *this; } \
+ SWKey operator --(int) { SWKey temp = *this; decrement(1); return temp; }
/** For use with = operator to position key.
@@ -64,15 +67,37 @@ public:
#define TOP SW_POSITION(POS_TOP)
#define BOTTOM SW_POSITION(POS_BOTTOM)
+class SWLocale;
+
/** SWKey is used for positioning an SWModule to a specific entry.
* It always represents a possible location into a module and can additionally represent
* a domain of entries (e.g. "John 3:16" in the domain "John 1:1 - Mark 5:25")
*/
class SWDLLEXPORT SWKey : public SWObject {
+
+ class LocaleCache {
+ public:
+ char *name;
+ SWLocale *locale;
+ LocaleCache() {
+ name = 0;
+ locale = 0;
+ }
+ virtual ~LocaleCache() {
+ if (name)
+ delete[]name;
+ }
+ };
+ static LocaleCache localeCache;
+ // for caching; don't use directly, call getPrivateLocale()
+ mutable SWLocale *locale;
+
+
long index;
static SWClass classdef;
void init();
+
protected:
char *keytext;
mutable char *rangeText;
@@ -80,6 +105,10 @@ protected:
char persist;
char error;
+ char *localeName;
+ SWLocale *getPrivateLocale() const;
+
+
public:
// misc pointer for whatever
@@ -124,6 +153,7 @@ public:
* @return error status
*/
virtual char Error();
+ virtual void setError(char err) { error = err; }
/** Sets this SWKey with a character string
* @param ikey string used to set this key
@@ -134,12 +164,14 @@ public:
* @param ikey other SWKey object from which to copy
*/
virtual void copyFrom(const SWKey &ikey);
+ virtual void positionFrom(const SWKey &ikey) { copyFrom(ikey); }
- /** returns string representation of this key
+ /** returns string representation of this key
*/
virtual const char *getText() const;
virtual const char *getShortText() const { return getText(); }
virtual const char *getRangeText() const;
+ virtual const char *getOSISRefRangeText() const;
virtual bool isBoundSet() const { return boundSet; }
virtual void clearBound() const { boundSet = false; }
@@ -179,26 +211,10 @@ public:
*/
virtual bool isTraversable() const { return false; }
+ char *getLocale() const { return localeName; }
+ void setLocale(const char *name) { stdstr(&localeName, name); locale = 0; } // this will force an on demand lookup of our locale
+
/** Use this function to get an index position within a module.
- * Here's a small example how to use this function and @ref Index(long).
- * This function uses the GerLut module and chooses a random verse from the
- * Bible and returns it.
- * @code
- * const char* randomVerse() {
- * VerseKey vk;
- * SWMgr mgr;
- * LocaleMgr::getSystemLocaleMgr()->setDefaultLocaleName("de");
- *
- * SWModule* module = mgr->Modules("GerLut");
- * srand( time(0) );
- * const double newIndex = (double(rand())/RAND_MAX)*(24108+8224);
- * vk.Index(newIndex);
- * module->setKey(vk);
- *
- * char* text;
- * sprintf(text, "%s: %s",(const char*)vk ,module->StripText(&vk));
- * return text;
- * @endcode
*/
virtual long Index() const { return index; }