summaryrefslogtreecommitdiff
path: root/include/versetreekey.h
blob: 60e2d69fe8b3e1e3a8bf078c0774528d29dc70d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/******************************************************************************
 *
 *  versetreekey.h -	code for class 'VerseTreeKey'- a standard Biblical
 *			verse key
 *
 * $Id: versetreekey.h 2833 2013-06-29 06:40:28Z chrislit $
 *
 * Copyright 2006-2013 CrossWire Bible Society (http://www.crosswire.org)
 *	CrossWire Bible Society
 *	P. O. Box 2528
 *	Tempe, AZ  85280-2528
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation version 2.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	See the GNU
 * General Public License for more details.
 *
 */


#ifndef VERSETREEKEY_H
#define VERSETREEKEY_H

#include <versekey.h>
#include <treekey.h>
#include <swmacs.h>
#include <listkey.h>

#include <defs.h>

SWORD_NAMESPACE_START

/**
 * Class VerseKey
 * The SWKey implementation used for verse based modules like Bibles or commentaries.
 */
class SWDLLEXPORT VerseTreeKey : public VerseKey, public TreeKey::PositionChangeListener {

	static SWClass classdef;
	TreeKey *treeKey;
//	vector<struct sbook> books;

	void init(TreeKey *treeKey);
	void syncVerseToTree();
	long lastGoodOffset;

protected:
	virtual int getBookFromAbbrev(const char *abbr) const;

public:

	/**
	* VerseKey Constructor - initializes Instance of VerseKey
	*
	* @param treeKey a TreeKey which will form the basis of this VerseTreeKey
	* @param ikey text key (will take various forms of 'BOOK CH:VS'.
	* See parse() for more detailed information)
	*/
	VerseTreeKey(TreeKey *treeKey, const char *ikey = 0);
	
	/**
	* VerseKey Constructor - initializes instance of VerseKey
	*
	* @param treeKey a TreeKey which will form the basis of this VerseTreeKey
	* @param ikey base key (will take various forms of 'BOOK CH:VS'.
	*	See parse() for more detailed information)
	*/	
	VerseTreeKey(TreeKey *treeKey, const SWKey *ikey);
	
	/** VerseKey Constructor - initializes instance of VerseKey
	* with boundariess - see also LowerBound()
	* and UpperBound()
	* @param treeKey a TreeKey which will form the basis of this VerseTreeKey
	* @param min the lower boundary of the new	VerseKey
	* @param max the upper boundary of the new	VerseKey
	*/	
	VerseTreeKey(TreeKey *treeKey, const char *min, const char *max);
	
	/**	VerseKey Copy Constructor - will create a new	VerseKey
	* based on an existing one
	*
	* @param k the	VerseKey to copy from
	*/
	VerseTreeKey(const VerseTreeKey &k);
	

	/**	VerseKey Destructor
	* Cleans up an instance of VerseKey
	*/
	virtual ~VerseTreeKey();

	/** Creates a new	SWKey based on the current	VerseKey
	* see also the Copy Constructor
	*/
	virtual SWKey *clone() const;
	
	virtual bool isTraversable() const { return true; }

	virtual TreeKey *getTreeKey();

	// TreeKey::PositionChangeListener interface
	virtual void positionChanged();
	bool internalPosChange;

	virtual void decrement(int steps = 1);
	virtual void increment(int steps = 1);
	
	virtual void Normalize(char autocheck = 0);

	virtual void setPosition(SW_POSITION newpos);
	virtual long NewIndex() const;
	// OPERATORS --------------------------------------------------------------------


	SWKEY_OPERATORS

	virtual SWKey & operator = (const VerseKey & ikey) { copyFrom(ikey); return *this; }
//	virtual void copyFrom(const VerseTreeKey &ikey);
};

SWORD_NAMESPACE_END

#endif //VERSETREEKEY_H