The SWORD Project  1.9.0.svnversion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
treekey.h
Go to the documentation of this file.
1  /******************************************************************************
2  *
3  * treekey.h - class TreeKey: an SWKey for traversing a table of contents
4  *
5  * $Id: treekey.h 3808 2020-10-02 13:23:34Z scribe $
6  *
7  * Copyright 2002-2013 CrossWire Bible Society (http://www.crosswire.org)
8  * CrossWire Bible Society
9  * P. O. Box 2528
10  * Tempe, AZ 85280-2528
11  *
12  * This program is free software; you can redistribute it and/or modify it
13  * under the terms of the GNU General Public License as published by the
14  * Free Software Foundation version 2.
15  *
16  * This program is distributed in the hope that it will be useful, but
17  * WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * General Public License for more details.
20  *
21  */
22 
23 
24 #ifndef TREEKEY_H
25 #define TREEKEY_H
26 
27 #include <swkey.h>
28 #include <swbuf.h>
29 
30 #include <defs.h>
31 
33 
38 class SWDLLEXPORT TreeKey : public SWKey {
39 
40 private:
41  void init();
42 
43 protected:
44  // hold on to setText until we've done a snap action: getText or navigation
45  // if we set, and then write out userData, we want to assure the path exists.
46  // This better conforms to the SWORD write methodology: mod.setKey, mod.setEntry
48 
49  // called whenever position of this key is changed. Should we move this
50  // to a more base class?
51  void positionChanged() { if (posChangeListener) posChangeListener->positionChanged(); }
52 
53 public:
56  public:
59  virtual void positionChanged() = 0;
60  TreeKey *getTreeKey() { return treeKey; }
61  void setTreeKey(TreeKey *tk) { treeKey = tk; }
62  } *posChangeListener;
63 
64  void setPositionChangeListener(PositionChangeListener *pcl) { posChangeListener = pcl; posChangeListener->setTreeKey(this); }
65 
66 // TreeKey (const char *ikey = 0);
67 // TreeKey (const SWKey * ikey);
68 // TreeKey (TreeKey const &k);
69  TreeKey() { init(); };
70  ~TreeKey() {};
71 
72 
73  virtual const char *getLocalName() = 0;
74  virtual const char *setLocalName(const char *) = 0;
75 
76  virtual int getLevel() { long bm = getOffset(); int level = 0; do { level++; } while (parent()); setOffset(bm); return level; }
77 
78  virtual const char *getUserData(int *size = 0) const = 0;
79  virtual void setUserData(const char *userData, int size = 0) = 0;
80 
83  virtual void root() = 0;
84 
88  virtual bool parent() = 0;
89 
93  virtual bool firstChild() = 0;
94 
98  virtual bool nextSibling() = 0;
99 
103  virtual bool previousSibling() = 0;
104 
108  virtual bool hasChildren() = 0;
109 
110  virtual void append() = 0;
111  virtual void appendChild() = 0;
112  virtual void insertBefore() = 0;
113 
114  virtual void remove() = 0;
115 
116 
117  virtual void setOffset(unsigned long offset) = 0;
118  virtual unsigned long getOffset() const = 0;
119 
120  virtual void setText(const char *ikey) = 0;
121  virtual void setPosition(SW_POSITION p) = 0;
122  virtual const char *getText() const = 0;
123  virtual int compare(const SWKey &ikey) = 0;
124  virtual void decrement(int steps = 1) = 0;
125  virtual void increment(int steps = 1) = 0;
126  virtual bool isTraversable() const { return true; }
127  virtual long getIndex() const { return getOffset(); }
128  virtual void setIndex(long iindex) { setOffset(iindex); }
129 
134  virtual void assureKeyPath(const char *keyPath = 0);
135  virtual void save() {}
136 
138 
139  };
140 
142 #endif
virtual void setText(const char *ikey)
Definition: swkey.cpp:162
#define SWORD_NAMESPACE_START
Definition: defs.h:39
#define SWKEY_OPERATORS
Definition: swkey.h:37
Definition: swbuf.h:47
virtual void decrement(int steps=1)
Definition: swkey.cpp:261
#define SWDLLEXPORT
Definition: defs.h:171
~TreeKey()
Definition: treekey.h:70
void setLocalName(TreeKeyIdx *treeKey)
Definition: genbookutil.cpp:60
void setPositionChangeListener(PositionChangeListener *pcl)
Definition: treekey.h:64
virtual void increment(int steps=1)
Definition: swkey.cpp:248
SWBuf unsnappedKeyText
Definition: treekey.h:47
virtual int getLevel()
Definition: treekey.h:76
virtual const char * getText() const
Definition: swkey.cpp:184
void init()
Definition: swkey.cpp:68
virtual int compare(const SWKey &ikey)
Definition: swkey.cpp:218
virtual bool isTraversable() const
Definition: treekey.h:126
TreeKey()
Definition: treekey.h:69
virtual void setPosition(SW_POSITION)
Definition: swkey.cpp:228
int size
Definition: regex.c:5043
void appendChild(TreeKeyIdx *treeKey)
void positionChanged()
Definition: treekey.h:51
void setTreeKey(TreeKey *tk)
Definition: treekey.h:61
#define SWORD_NAMESPACE_END
Definition: defs.h:40
Definition: swkey.h:77
virtual void setIndex(long iindex)
Definition: treekey.h:128
virtual void save()
Definition: treekey.h:135
virtual long getIndex() const
Definition: treekey.h:127