The SWORD Project  1.9.0.svnversion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
listkey.h
Go to the documentation of this file.
1 /******************************************************************************
2  *
3  * listkey.h - class ListKey: a container Key which facilitates a list of
4  * SWKey objects. This is useful for search results or returning
5  * the result of parsing freetext verse ranges. The usefulness
6  * of having this container of keys itself be an SWKey is that it
7  * can be used natively by an SWModule to iterate the results.
8  *
9  * $Id: listkey.h 3822 2020-11-03 18:54:47Z scribe $
10  *
11  * Copyright 1997-2013 CrossWire Bible Society (http://www.crosswire.org)
12  * CrossWire Bible Society
13  * P. O. Box 2528
14  * Tempe, AZ 85280-2528
15  *
16  * This program is free software; you can redistribute it and/or modify it
17  * under the terms of the GNU General Public License as published by the
18  * Free Software Foundation version 2.
19  *
20  * This program is distributed in the hope that it will be useful, but
21  * WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23  * General Public License for more details.
24  *
25  */
26 
27 #ifndef SWLSTKEY_H
28 #define SWLSTKEY_H
29 
30 #include <swkey.h>
31 
32 #include <defs.h>
33 
35 
38 class SWDLLEXPORT ListKey : public SWKey {
39 
40  void init();
41 
42 protected:
43  int arraypos;
44  int arraymax;
45  int arraycnt;
47 
48 public:
49 
54  ListKey(const char *ikey = 0);
55  ListKey(ListKey const &k);
56 
59  virtual ~ListKey();
60 
61  virtual SWKey *clone() const;
62 
65  virtual void clear();
66 
70  SWDEPRECATED virtual void ClearList() { clear(); }
71 
72 
76  virtual int getCount() const;
80  SWDEPRECATED virtual int Count() { return getCount(); }
81 
84  virtual void remove();
88  SWDEPRECATED virtual void Remove() { remove(); }
89 
90 
98  virtual char setToElement(int ielement, SW_POSITION pos = TOP);
102  SWDEPRECATED virtual char SetToElement(int ielement, SW_POSITION pos = TOP) { return setToElement(ielement, pos); }
103 
104 
105 
111  virtual SWKey *getElement(int pos = -1);
112  virtual const SWKey *getElement(int pos = -1) const;
113 
117  SWDEPRECATED virtual SWKey *GetElement(int pos = -1) { return getElement(pos); }
118 
122  ListKey & operator <<(const SWKey &ikey) { add(ikey); return *this; }
123  virtual void add(const SWKey &ikey);
124 
129  virtual void copyFrom(const ListKey & ikey);
130  virtual void copyFrom(const SWKey & ikey) { SWKey::copyFrom(ikey); }
131 
136  virtual void setPosition(SW_POSITION pos);
137 
140  virtual void decrement(int step = 1);
141 
144  virtual void increment(int step = 1);
145 
146  virtual void nextElement() { setToElement(arraypos + 1); }
147 
148  virtual bool isTraversable() const { return true; }
149  virtual long getIndex() const { return arraypos; }
150  virtual const char *getRangeText() const;
151  virtual const char *getOSISRefRangeText() const;
152  virtual const char *getShortRangeText() const;
153  virtual const char *getShortText() const;
154 
159  virtual void setIndex(long index) { setToElement((int)index); }
160  virtual const char *getText() const;
161  virtual void setText(const char *ikey);
162  virtual void sort();
163 
165  ListKey & operator =(const ListKey &key) { copyFrom(key); return *this; }
166 };
167 
169 #endif
virtual void setText(const char *ikey)
Definition: swkey.cpp:162
#define TOP
Definition: swkey.h:68
#define SWORD_NAMESPACE_START
Definition: defs.h:39
virtual const char * getShortRangeText() const
Definition: swkey.h:187
#define SWKEY_OPERATORS
Definition: swkey.h:37
virtual const char * getShortText() const
Definition: swkey.h:185
virtual void decrement(int steps=1)
Definition: swkey.cpp:261
int arraycnt
Definition: listkey.h:45
int pos
Definition: regex.c:5534
#define SWDLLEXPORT
Definition: defs.h:171
virtual void nextElement()
Definition: listkey.h:146
virtual const char * getRangeText() const
Definition: swkey.cpp:193
virtual SWDEPRECATED void Remove()
Definition: listkey.h:88
virtual void increment(int steps=1)
Definition: swkey.cpp:248
#define SWDEPRECATED
Definition: defs.h:174
virtual SWKey * clone() const
Definition: swkey.cpp:75
virtual const char * getText() const
Definition: swkey.cpp:184
int arraymax
Definition: listkey.h:44
void init()
Definition: swkey.cpp:68
int arraypos
Definition: listkey.h:43
virtual void copyFrom(const SWKey &ikey)
Definition: swkey.cpp:173
virtual bool isTraversable() const
Definition: listkey.h:148
virtual SWDEPRECATED SWKey * GetElement(int pos=-1)
Definition: listkey.h:117
virtual const char * getOSISRefRangeText() const
Definition: swkey.cpp:203
virtual void setPosition(SW_POSITION)
Definition: swkey.cpp:228
SWKey ** array
Definition: listkey.h:46
virtual void copyFrom(const SWKey &ikey)
Definition: listkey.h:130
virtual SWDEPRECATED int Count()
Definition: listkey.h:80
virtual long getIndex() const
Definition: listkey.h:149
#define SWORD_NAMESPACE_END
Definition: defs.h:40
virtual SWDEPRECATED void ClearList()
Definition: listkey.h:70
virtual void setIndex(long index)
Definition: listkey.h:159
Definition: swkey.h:77
virtual SWDEPRECATED char SetToElement(int ielement, SW_POSITION pos=TOP)
Definition: listkey.h:102