~ubuntu-branches/debian/squeeze/sword/squeeze

« back to all changes in this revision

Viewing changes to src/keys/swkey.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Glassey
  • Date: 2004-01-15 15:50:07 UTC
  • Revision ID: james.westby@ubuntu.com-20040115155007-n9mz4x0zxrs1isd3
Tags: upstream-1.5.7
ImportĀ upstreamĀ versionĀ 1.5.7

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/******************************************************************************
 
2
 *  swkey.cpp - code for base class 'SWKey'.  SWKey is the basis for all
 
3
 *              types of keys for indexing into modules (e.g. verse, word,
 
4
 *              place, etc.)
 
5
 */
 
6
 
 
7
#include <swkey.h>
 
8
#include <utilfuns.h>
 
9
 
 
10
SWORD_NAMESPACE_START
 
11
 
 
12
static const char *classes[] = {"SWKey", "SWObject", 0};
 
13
SWClass SWKey::classdef(classes);
 
14
 
 
15
/******************************************************************************
 
16
 * SWKey Constructor - initializes instance of SWKey
 
17
 *
 
18
 * ENT: ikey - text key
 
19
 */
 
20
 
 
21
SWKey::SWKey(const char *ikey)
 
22
{
 
23
        index     = 0;
 
24
        persist   = 0;
 
25
        keytext   = 0;
 
26
        rangeText = 0;
 
27
        error     = 0;
 
28
        userData  = 0;
 
29
        stdstr(&keytext, ikey);
 
30
        init();
 
31
}
 
32
 
 
33
SWKey::SWKey(SWKey const &k)
 
34
{
 
35
        index     = k.index;
 
36
        persist   = k.persist;
 
37
        userData  = k.userData;
 
38
        keytext   = 0;
 
39
        rangeText = 0;
 
40
        error     = k.error;
 
41
        setText(k.getText());
 
42
        init();
 
43
}
 
44
 
 
45
void SWKey::init() {
 
46
        myclass = &classdef;
 
47
        boundSet = false;
 
48
}
 
49
 
 
50
SWKey *SWKey::clone() const
 
51
{
 
52
        return new SWKey(*this);
 
53
}
 
54
 
 
55
/******************************************************************************
 
56
 * SWKey Destructor - cleans up instance of SWKey
 
57
 */
 
58
 
 
59
SWKey::~SWKey() {
 
60
        if (keytext)
 
61
                delete [] keytext;
 
62
        if (rangeText)
 
63
                delete [] rangeText;
 
64
}
 
65
 
 
66
 
 
67
/******************************************************************************
 
68
 * SWKey::Persist - Gets whether this object itself persists within a
 
69
 *                      module that it was used to setKey or just a copy.
 
70
 *                      (1 - persists in module; 0 - a copy is attempted
 
71
 *
 
72
 * RET: value of persist
 
73
 */
 
74
 
 
75
char SWKey::Persist() const
 
76
{
 
77
        return persist;
 
78
}
 
79
 
 
80
 
 
81
/******************************************************************************
 
82
 * SWKey::Persist - Set/gets whether this object itself persists within a
 
83
 *                      module that it was used to setKey or just a copy.
 
84
 *                      (1 - persists in module; 0 - a copy is attempted
 
85
 *
 
86
 * ENT: ipersist - value which to set persist
 
87
 *              [-1] - only get
 
88
 *
 
89
 * RET: value of persist
 
90
 */
 
91
 
 
92
char SWKey::Persist(signed char ipersist)
 
93
{
 
94
        if (ipersist != -1)
 
95
                persist = ipersist;
 
96
 
 
97
        return persist;
 
98
}
 
99
 
 
100
 
 
101
/******************************************************************************
 
102
 * SWKey::Error - Gets and clears error status
 
103
 *
 
104
 * RET: error status
 
105
 */
 
106
 
 
107
char SWKey::Error()
 
108
{
 
109
        char retval = error;
 
110
 
 
111
        error = 0;
 
112
        return retval;
 
113
}
 
114
 
 
115
 
 
116
/******************************************************************************
 
117
 * SWKey::setText Equates this SWKey to a character string
 
118
 *
 
119
 * ENT: ikey - other swkey object
 
120
 */
 
121
 
 
122
void SWKey::setText(const char *ikey) {
 
123
        stdstr(&keytext, ikey);
 
124
}
 
125
 
 
126
 
 
127
/******************************************************************************
 
128
 * SWKey::copyFrom Equates this SWKey to another SWKey object
 
129
 *
 
130
 * ENT: ikey - other swkey object
 
131
 */
 
132
 
 
133
void SWKey::copyFrom(const SWKey &ikey) {
 
134
// not desirable        Persist(ikey.Persist());
 
135
        setText((const char *)ikey);
 
136
}
 
137
 
 
138
 
 
139
/******************************************************************************
 
140
 * SWKey::getText - returns text key if (const char *) cast is requested
 
141
 */
 
142
 
 
143
const char *SWKey::getText() const {
 
144
        return keytext;
 
145
}
 
146
 
 
147
 
 
148
/******************************************************************************
 
149
 * SWKey::getRangeText - returns parsable range text for this key
 
150
 */
 
151
 
 
152
const char *SWKey::getRangeText() const {
 
153
        stdstr(&rangeText, keytext);
 
154
        return rangeText;
 
155
}
 
156
 
 
157
 
 
158
/******************************************************************************
 
159
 * SWKey::compare       - Compares another VerseKey object
 
160
 *
 
161
 * ENT: ikey - key to compare with this one
 
162
 *
 
163
 * RET: > 0 if this key is greater than compare key
 
164
 *      < 0
 
165
 *        0
 
166
 */
 
167
 
 
168
int SWKey::compare(const SWKey &ikey)
 
169
{
 
170
        return strcmp((const char *)*this, (const char *)ikey);
 
171
}
 
172
 
 
173
 
 
174
/******************************************************************************
 
175
 * SWKey::setPosition(SW_POSITION)      - Positions this key if applicable
 
176
 */
 
177
 
 
178
void SWKey::setPosition(SW_POSITION p) {
 
179
        switch (p) {
 
180
        case POS_TOP:
 
181
//              *this = "";
 
182
                break;
 
183
        case POS_BOTTOM:
 
184
//              *this = "zzzzzzzzz";
 
185
                break;
 
186
        } 
 
187
}
 
188
 
 
189
 
 
190
/******************************************************************************
 
191
 * SWKey::increment     - Increments key a number of entries
 
192
 *
 
193
 * ENT: increment       - Number of entries to jump forward
 
194
 *
 
195
 * RET: *this
 
196
 */
 
197
 
 
198
void SWKey::increment(int) {
 
199
        error = KEYERR_OUTOFBOUNDS;
 
200
}
 
201
 
 
202
 
 
203
/******************************************************************************
 
204
 * SWKey::decrement     - Decrements key a number of entries
 
205
 *
 
206
 * ENT: decrement       - Number of entries to jump backward
 
207
 *
 
208
 * RET: *this
 
209
 */
 
210
 
 
211
void SWKey::decrement(int) {
 
212
        error = KEYERR_OUTOFBOUNDS;
 
213
}
 
214
 
 
215
SWORD_NAMESPACE_END