The SWORD Project  1.9.0.svnversion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
treekeyidx.h
Go to the documentation of this file.
1 /******************************************************************************
2  *
3  * treekeyidx.h - class TreeKeyIdx: a TreeKey implementation which
4  * grabs its structure from an index data file
5  *
6  * $Id: treekeyidx.h 3808 2020-10-02 13:23:34Z scribe $
7  *
8  * Copyright 2002-2013 CrossWire Bible Society (http://www.crosswire.org)
9  * CrossWire Bible Society
10  * P. O. Box 2528
11  * Tempe, AZ 85280-2528
12  *
13  * This program is free software; you can redistribute it and/or modify it
14  * under the terms of the GNU General Public License as published by the
15  * Free Software Foundation version 2.
16  *
17  * This program is distributed in the hope that it will be useful, but
18  * WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20  * General Public License for more details.
21  *
22  */
23 
24 
25 #ifndef TREEKEYIDX_H
26 #define TREEKEYIDX_H
27 
28 #include <treekey.h>
29 #include <sysdata.h>
30 
32 
33 class FileDesc;
34 
39 class SWDLLEXPORT TreeKeyIdx : public TreeKey {
40 
41 private:
42  class TreeNode {
43  public:
44  TreeNode();
45  ~TreeNode();
46  void clear();
51  char *name;
53  char *userData;
54  } currentNode;
55 
56  char *path;
57 
60 
61  void init();
62 
63  void getTreeNodeFromDatOffset(long ioffset, TreeNode *buf) const;
64  char getTreeNodeFromIdxOffset(long ioffset, TreeNode *node) const;
65  void saveTreeNode(TreeNode *node);
66  void saveTreeNodeOffsets(TreeNode *node);
67 
68 public:
69  TreeKeyIdx(const TreeKeyIdx &ikey);
70  TreeKeyIdx(const char *idxPath, int fileMode = -1);
71  virtual ~TreeKeyIdx();
72 
73  virtual SWKey *clone() const;
74 
75  virtual const char *getLocalName();
76  virtual const char *setLocalName(const char *);
77 
78  virtual const char *getUserData(int *size = 0) const;
79  virtual void setUserData(const char *userData, int size = 0);
80 
81  virtual void root();
82  virtual bool parent();
83 
84  virtual bool firstChild();
85  virtual bool nextSibling();
86  virtual bool previousSibling();
87 
88  virtual bool hasChildren();
89 
90  virtual void append();
91  virtual void appendChild();
92  virtual void insertBefore();
93 
94  virtual void remove();
95  virtual void save();
96 
97  virtual void copyFrom(const TreeKeyIdx &ikey);
98  virtual void copyFrom(const SWKey &ikey);
99 
100  void setOffset(unsigned long offset);
101  unsigned long getOffset() const;
102 
103  virtual int getLevel();
104 
105 
106  // OPERATORS ------------------------------------------------------------
107 
108 
109  virtual SWKey &operator = (const TreeKeyIdx &ikey) { copyFrom(ikey); return *this; }
111 
112  virtual void setText(const char *ikey);
113  virtual void setPosition(SW_POSITION p);
114  virtual const char *getText() const;
115  virtual int _compare(const TreeKeyIdx & ikey);
116  virtual int compare(const SWKey &ikey);
117  virtual void decrement(int steps = 1);
118  virtual void increment(int steps = 1);
119  virtual bool isTraversable() const { return true; }
120 
121  static signed char create(const char *path);
122 };
123 
125 
126 #endif
virtual bool parent()=0
virtual void setPosition(SW_POSITION p)=0
#define SWORD_NAMESPACE_START
Definition: defs.h:39
#define SWKEY_OPERATORS
Definition: swkey.h:37
virtual unsigned long getOffset() const =0
#define SWDLLEXPORT
Definition: defs.h:171
virtual const char * setLocalName(const char *)=0
virtual void setOffset(unsigned long offset)=0
virtual void append()=0
virtual const char * getLocalName()=0
signed int SW_s32
Definition: sysdata.h:40
virtual void setUserData(const char *userData, int size=0)=0
FileDesc * idxfd
Definition: treekeyidx.h:58
virtual int getLevel()
Definition: treekey.h:76
virtual void increment(int steps=1)=0
virtual const char * getUserData(int *size=0) const =0
virtual SWKey * clone() const
Definition: swkey.cpp:75
char * path
Definition: treekeyidx.h:56
virtual const char * getText() const =0
virtual int compare(const SWKey &ikey)=0
virtual void root()=0
virtual void copyFrom(const SWKey &ikey)
Definition: swkey.cpp:173
unsigned short SW_u16
Definition: sysdata.h:38
FileDesc * datfd
Definition: treekeyidx.h:59
virtual bool hasChildren()=0
virtual void decrement(int steps=1)=0
virtual bool isTraversable() const
Definition: treekeyidx.h:119
virtual void setText(const char *ikey)=0
int size
Definition: regex.c:5043
virtual void insertBefore()=0
#define SWORD_NAMESPACE_END
Definition: defs.h:40
Definition: swkey.h:77
virtual bool previousSibling()=0
virtual bool nextSibling()=0
virtual void appendChild()=0
virtual void save()
Definition: treekey.h:135
void init()
Definition: treekey.cpp:34
virtual bool firstChild()=0