treekey.h

00001 /******************************************************************************
00002  *  versekey.h - code for class 'versekey'- a standard Biblical verse key
00003  *
00004  * $Id: treekey.h 1958 2006-08-22 00:15:10Z scribe $
00005  *
00006  * Copyright 1998 CrossWire Bible Society (http://www.crosswire.org)
00007  *      CrossWire Bible Society
00008  *      P. O. Box 2528
00009  *      Tempe, AZ  85280-2528
00010  *
00011  * This program is free software; you can redistribute it and/or modify it
00012  * under the terms of the GNU General Public License as published by the
00013  * Free Software Foundation version 2.
00014  *
00015  * This program is distributed in the hope that it will be useful, but
00016  * WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  * General Public License for more details.
00019  *
00020  */
00021 
00022 
00023 #ifndef TREEKEY_H
00024 #define TREEKEY_H
00025 
00026 #include <swkey.h>
00027 #include <swbuf.h>
00028 
00029 #include <defs.h>
00030 
00031 SWORD_NAMESPACE_START
00032 
00037 class SWDLLEXPORT TreeKey : public SWKey {
00038         static SWClass classdef;
00039         void init();
00040 
00041 protected:
00042         // hold on to setText until we've done a snap action: getText or navigation
00043         // if we set, and then write out userData, we want to assure the path exists.
00044         // This better conforms to the SWORD write methodology: mod.setKey, mod.setEntry
00045         mutable SWBuf unsnappedKeyText;
00046 
00047 public:
00048 //      TreeKey (const char *ikey = 0);
00049 //      TreeKey (const SWKey * ikey);
00050 //      TreeKey (TreeKey const &k);
00051         TreeKey () { init(); };
00052         ~TreeKey () {};
00053 
00054 
00055         virtual const char *getLocalName() = 0;
00056         virtual const char *setLocalName(const char *) = 0;
00057 
00058         virtual const char *getUserData(int *size = 0) = 0;
00059         virtual void setUserData(const char *userData, int size = 0) = 0;
00060 
00063         virtual void root() = 0;
00064 
00068         virtual bool parent() = 0;
00069 
00073         virtual bool firstChild() = 0;
00074 
00078         virtual bool nextSibling() = 0;
00079 
00083         virtual bool previousSibling() = 0;
00084 
00088         virtual bool hasChildren() = 0;
00089 
00090         virtual void append() = 0;
00091         virtual void appendChild() = 0;
00092         virtual void insertBefore() = 0;
00093 
00094         virtual void remove() = 0;
00095 
00096 
00097         virtual void setOffset(unsigned long offset) = 0;
00098         virtual unsigned long getOffset() const = 0;
00099 
00100         virtual void setText(const char *ikey) = 0;
00101         virtual void setPosition(SW_POSITION p) = 0;
00102         virtual const char *getText() const = 0;
00103         virtual int compare(const SWKey &ikey) = 0;
00104         virtual void decrement(int steps = 1) = 0;
00105         virtual void increment(int steps = 1) = 0;
00106         virtual bool isTraversable() const { return true; }
00107         virtual long Index() const { return getOffset(); }
00108         virtual long Index(long iindex) { setOffset(iindex); return getOffset(); }
00109 
00114         virtual void assureKeyPath(const char *keyPath = 0);
00115         virtual void save() {}
00116 
00117         SWKEY_OPERATORS
00118 
00119         };
00120 
00121 SWORD_NAMESPACE_END
00122 #endif