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

« back to all changes in this revision

Viewing changes to include/versekey.h

  • 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
 *      versekey.h - code for class 'versekey'- a standard Biblical verse key
 
3
 *
 
4
 * $Id: versekey.h,v 1.30 2003/08/13 05:27:02 scribe Exp $
 
5
 *
 
6
 * Copyright 1998 CrossWire Bible Society (http://www.crosswire.org)
 
7
 *      CrossWire Bible Society
 
8
 *      P. O. Box 2528
 
9
 *      Tempe, AZ       85280-2528
 
10
 *
 
11
 * This program is free software; you can redistribute it and/or modify it
 
12
 * under the terms of the GNU General Public License as published by the
 
13
 * Free Software Foundation version 2.
 
14
 *
 
15
 * This program is distributed in the hope that it will be useful, but
 
16
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 
18
 * General Public License for more details.
 
19
 *
 
20
 */
 
21
 
 
22
 
 
23
#ifndef VERSEKEY_H
 
24
#define VERSEKEY_H
 
25
 
 
26
#include <swkey.h>
 
27
#include <swmacs.h>
 
28
#include <listkey.h>
 
29
#include <ctype.h>
 
30
 
 
31
#include <defs.h>
 
32
 
 
33
SWORD_NAMESPACE_START
 
34
 
 
35
#define POS_MAXVERSE ((char)3)
 
36
#define POS_MAXCHAPTER ((char)4)
 
37
#define POS_MAXBOOK ((char)5)
 
38
 
 
39
#define MAXVERSE SW_POSITION(POS_MAXVERSE)
 
40
#define MAXCHAPTER SW_POSITION(POS_MAXCHAPTER)
 
41
#define MAXBOOK SW_POSITION(POS_MAXBOOK)
 
42
 
 
43
struct sbook
 
44
{
 
45
        /**Name of book
 
46
        */
 
47
        const char *name;
 
48
 
 
49
        /**Preferred Abbreviation
 
50
        */
 
51
        const char *prefAbbrev;
 
52
 
 
53
        /**Maximum chapters in book
 
54
        */
 
55
        unsigned char chapmax;
 
56
        /** Array[chapmax] of maximum verses in chapters
 
57
        */
 
58
        int *versemax;
 
59
};
 
60
 
 
61
struct abbrev
 
62
{
 
63
        const char *ab;
 
64
        int book;
 
65
};
 
66
 
 
67
 
 
68
class SWLocale;
 
69
 
 
70
/**
 
71
 * Class VerseKey
 
72
 * The SWKey implementation used for verse based modules like Bibles or commentaries.
 
73
 */
 
74
class SWDLLEXPORT VerseKey:public SWKey {
 
75
        class LocaleCache {
 
76
        public:
 
77
                char *name;
 
78
                unsigned int abbrevsCnt;
 
79
                SWLocale *locale;
 
80
                        LocaleCache() {
 
81
                        name = 0;
 
82
                        abbrevsCnt = 0;
 
83
                        locale = 0;
 
84
                }
 
85
                 virtual ~LocaleCache() {
 
86
                        if (name)
 
87
                        delete[]name;
 
88
                }
 
89
        };
 
90
 
 
91
        static SWClass classdef;
 
92
 
 
93
        static long *offsets[2][2];
 
94
        static int offsize[2][2];
 
95
        /** number of instantiated VerseKey objects or derivitives 
 
96
        */
 
97
        static int instance;
 
98
        static struct sbook otbooks[];
 
99
        static struct sbook ntbooks[];
 
100
        static long otbks[];
 
101
        static long otcps[];
 
102
        static long ntbks[];
 
103
        static long ntcps[];
 
104
        static int vm[];
 
105
        static LocaleCache localeCache;
 
106
        ListKey internalListKey;
 
107
 
 
108
        const struct abbrev *abbrevs;
 
109
        char *locale;
 
110
        int abbrevsCnt;
 
111
        /** The Testament: 0 - Old; 1 - New
 
112
        */
 
113
        signed char testament;
 
114
        mutable signed char book;
 
115
        mutable signed int chapter;
 
116
        mutable signed int verse;
 
117
        /** flag for auto normalization 
 
118
        */
 
119
        char autonorm;
 
120
        /** flag for headings on/off
 
121
        */
 
122
        char headings;
 
123
 
 
124
        int getBookAbbrev(const char *abbr);
 
125
        void initBounds() const;
 
126
        /** initialize and allocate books array
 
127
        */
 
128
        void initstatics();
 
129
        /** initializes this VerseKey()
 
130
        */
 
131
        void init();
 
132
        /** Refresh keytext based on testament|book|chapter|verse
 
133
        * default auto normalization to true
 
134
        * default display headings option is false
 
135
        */
 
136
        void freshtext() const;
 
137
        /**     Parse a character array into testament|book|chapter|verse 
 
138
        *
 
139
        */
 
140
        virtual char parse();
 
141
        /** Binary search to find the index closest, but less
 
142
        * than the given value.
 
143
        *
 
144
        * @param array long * to array to search
 
145
        * @param size number of elements in the array
 
146
        * @param value value to find
 
147
        * @return the index into the array that is less than but closest to value
 
148
        */
 
149
        int findindex(long *array, int size, long value);
 
150
        mutable VerseKey *lowerBound, *upperBound;
 
151
 
 
152
public:
 
153
        static const char builtin_BMAX[2];
 
154
        static struct sbook *builtin_books[2];
 
155
        static const struct abbrev builtin_abbrevs[];
 
156
        const char *BMAX;
 
157
        struct sbook **books;
 
158
 
 
159
        /**
 
160
        * VerseKey Constructor - initializes Instance of VerseKey
 
161
        *
 
162
        * @param ikey text key (will take various forms of 'BOOK CH:VS'.
 
163
        * See parse() for more detailed information)
 
164
        */
 
165
        VerseKey(const char *ikey = 0);
 
166
        
 
167
        /**
 
168
        * VerseKey Constructor - initializes instance of VerseKey
 
169
        *
 
170
        * @param ikey base key (will take various forms of 'BOOK CH:VS'.
 
171
        *       See parse() for more detailed information)
 
172
        */      
 
173
        VerseKey(const SWKey * ikey);
 
174
        
 
175
        /** VerseKey Constructor - initializes instance of VerseKey
 
176
        * with boundariess - see also LowerBound()
 
177
        * and UpperBound()
 
178
        * @param min the lower boundary of the new      VerseKey
 
179
        * @param max the upper boundary of the new      VerseKey
 
180
        */      
 
181
        VerseKey(const char *min, const char *max);
 
182
        
 
183
        /**     VerseKey Copy Constructor - will create a new   VerseKey
 
184
        * based on an existing one
 
185
        *
 
186
        * @param k the  VerseKey to copy from
 
187
        */
 
188
        VerseKey(const VerseKey &k);
 
189
        
 
190
        /**     VerseKey Destructor
 
191
        * Cleans up an instance of VerseKey
 
192
        */
 
193
        virtual ~ VerseKey();
 
194
 
 
195
        /** sets the lower boundary for this    VerseKey
 
196
        * and returns the new boundary
 
197
        *
 
198
        * @param lb the new lower boundary for this     VerseKey
 
199
        * @return the lower boundary the key was set to
 
200
        */
 
201
        VerseKey & LowerBound(const char *lb);
 
202
        
 
203
        /** sets the upper boundary for this    VerseKey
 
204
        * and returns the new boundary
 
205
        * @param ub the new upper boundary for this     VerseKey
 
206
        * @return the upper boundary the key was set to
 
207
        */
 
208
        VerseKey & UpperBound(const char *ub);
 
209
        
 
210
        /** gets the lower boundary of this     VerseKey
 
211
        * @return the lower boundary of this    VerseKey
 
212
        */
 
213
        VerseKey & LowerBound() const;
 
214
        
 
215
        /** gets the upper boundary of this     VerseKey
 
216
        * @return the upper boundary of this    VerseKey
 
217
        */
 
218
        VerseKey & UpperBound() const;
 
219
        
 
220
        /** clears the boundaries of this       VerseKey
 
221
        */
 
222
        void ClearBounds();
 
223
        
 
224
        /** Creates a new       SWKey based on the current      VerseKey
 
225
        * see also the Copy Constructor
 
226
        */
 
227
        virtual SWKey *clone() const;
 
228
        
 
229
        /** refreshes keytext before returning if cast to
 
230
        * a (char *) is requested
 
231
        */
 
232
        virtual const char *getText() const;
 
233
        virtual const char *getShortText() const;
 
234
        virtual void setText(const char *ikey) { SWKey::setText(ikey); parse (); }
 
235
        virtual void copyFrom(const SWKey & ikey);
 
236
        
 
237
        /** Equates this VerseKey to another VerseKey
 
238
        */
 
239
        virtual void copyFrom(const VerseKey & ikey);
 
240
        
 
241
        /** Positions this key
 
242
        *
 
243
        * @param newpos Position to set to.
 
244
        * @return *this
 
245
        */
 
246
        virtual void setPosition(SW_POSITION newpos);
 
247
        
 
248
        /** Decrements key a number of verses
 
249
        *
 
250
        * @param steps Number of verses to jump backward
 
251
        * @return *this
 
252
        */
 
253
        virtual void decrement(int steps);
 
254
        
 
255
        /** Increments key a number of verses
 
256
        *
 
257
        * @param steps Number of verses to jump forward
 
258
        * @return *this
 
259
        */
 
260
        virtual void increment(int steps);
 
261
        virtual char Traversable() { return 1; }
 
262
 
 
263
        virtual const char *getBookName() const;
 
264
        virtual const char *getBookAbbrev() const;
 
265
        /** Gets testament
 
266
        *
 
267
        * @return value of testament
 
268
        */
 
269
        virtual char Testament() const;
 
270
        
 
271
        /** Gets book
 
272
        *
 
273
        * @return value of book
 
274
        */
 
275
        virtual char Book() const;
 
276
        
 
277
        /** Gets chapter
 
278
        *
 
279
        * @return value of chapter
 
280
        */
 
281
        virtual int Chapter() const;
 
282
        
 
283
        /** Gets verse
 
284
        *
 
285
        * @return value of verse
 
286
        */
 
287
        virtual int Verse() const;
 
288
        
 
289
        /** Sets/gets testament
 
290
        *
 
291
        * @param itestament value which to set testament
 
292
        * [MAXPOS(char)] - only get
 
293
        * @return if unchanged -> value of testament,
 
294
        * if changed -> previous value of testament
 
295
        */
 
296
        virtual char Testament(char itestament);
 
297
        
 
298
        /** Sets/gets book
 
299
        *
 
300
        * @param ibook value which to set book
 
301
        * [MAXPOS(char)] - only get
 
302
        * @return if unchanged -> value of book,
 
303
        * if changed -> previous value of book
 
304
        */
 
305
        virtual char Book(char ibook);
 
306
        
 
307
        /** Sets/gets chapter
 
308
        *
 
309
        * @param ichapter value which to set chapter
 
310
        * [MAXPOS(int)] - only get
 
311
        * @return if unchanged -> value of chapter,
 
312
        * if changed -> previous value of chapter
 
313
        */
 
314
        virtual int Chapter(int ichapter);
 
315
        
 
316
        /** Sets/gets verse
 
317
        *
 
318
        * @param iverse value which to set verse
 
319
        * [MAXPOS(int)] - only get
 
320
        * @return if unchanged -> value of verse,
 
321
        * if changed -> previous value of verse
 
322
        */
 
323
        virtual int Verse(int iverse);
 
324
        
 
325
        /** checks limits and normalizes if necessary (e.g.
 
326
        * Matthew 29:47 = Mark 2:2).    If last verse is
 
327
        * exceeded, key is set to last Book CH:VS
 
328
        *
 
329
        * @return *this
 
330
        */
 
331
        virtual void Normalize(char autocheck = 0);
 
332
        
 
333
        /** Sets/gets flag that tells VerseKey to
 
334
        * automatically normalize itself when modified
 
335
        *
 
336
        * @param iautonorm value which to set autonorm
 
337
        * [MAXPOS(char)] - only get
 
338
        * @return if unchanged -> value of autonorm,
 
339
        * if changed -> previous value of autonorm
 
340
        */
 
341
        virtual char AutoNormalize(char iautonorm = MAXPOS (char));
 
342
        
 
343
        /** Sets/gets flag that tells VerseKey to include
 
344
        * chapter/book/testament/module headings
 
345
        *
 
346
        * @param iheadings value which to set headings
 
347
        * [MAXPOS(char)] - only get
 
348
        * @return if unchanged -> value of headings,
 
349
        * if changed -> previous value of headings
 
350
        */
 
351
        virtual char Headings(char iheadings = MAXPOS (char));
 
352
        
 
353
        virtual long NewIndex() const;
 
354
        
 
355
        /** Gets index based upon current verse
 
356
        *
 
357
        * @return offset
 
358
        */
 
359
        virtual long Index() const;
 
360
        
 
361
        /** Sets index based upon current verse
 
362
        *
 
363
        * @param iindex value to set index to
 
364
        * @return offset
 
365
        */
 
366
        virtual long Index(long iindex);
 
367
 
 
368
        virtual const char *getOSISRef() const;
 
369
 
 
370
        virtual ListKey ParseVerseList(const char *buf, const char *defaultKey = "Genesis 1:1", bool expandRange = false);
 
371
        virtual const char *getRangeText() const;
 
372
        /** Compares another    SWKey object
 
373
        *
 
374
        * @param ikey key to compare with this one
 
375
        * @return >0 if this    VerseKey is greater than compare        SWKey,
 
376
        * <0 if this    VerseKey is smaller than compare        SWKey,
 
377
        * 0 if the keys are the same
 
378
        */
 
379
        virtual int compare(const SWKey & ikey);
 
380
        
 
381
        /** Compares another    VerseKey object
 
382
        *
 
383
        * @param ikey key to compare with this one
 
384
        * @return >0 if this    VerseKey is greater than compare        VerseKey,
 
385
        * <0 if this    VerseKey is smaller than compare        VerseKey,
 
386
        * 0 if the keys are the same
 
387
        */
 
388
        virtual int _compare(const VerseKey & ikey);
 
389
        
 
390
        virtual void setBookAbbrevs(const struct abbrev *bookAbbrevs, unsigned int size = 0 /* default determine size */ );
 
391
        virtual void setBooks(const char *iBMAX, struct sbook **ibooks);
 
392
        virtual void setLocale(const char *name);
 
393
        virtual const char *getLocale() const { return locale; }
 
394
 
 
395
 
 
396
 
 
397
        // OPERATORS --------------------------------------------------------------------
 
398
 
 
399
 
 
400
        SWKEY_OPERATORS
 
401
 
 
402
        virtual SWKey & operator = (const VerseKey & ikey) { copyFrom(ikey); return *this; }
 
403
};
 
404
 
 
405
SWORD_NAMESPACE_END
 
406
#endif