listkey.h

00001 /******************************************************************************
00002  * listkey.h    - code for base class 'listkey'.  listkey is the basis for all
00003  *                              types of keys for indexing into modules
00004  *                              (e.g. verse, word,
00005  *                              place, etc.)
00006  *
00007  * $Id: listkey.h 1958 2006-08-22 00:15:10Z scribe $
00008  *
00009  * Copyright 1998 CrossWire Bible Society (http://www.crosswire.org)
00010  *      CrossWire Bible Society
00011  *      P. O. Box 2528
00012  *      Tempe, AZ  85280-2528
00013  *
00014  * This program is free software; you can redistribute it and/or modify it
00015  * under the terms of the GNU General Public License as published by the
00016  * Free Software Foundation version 2.
00017  *
00018  * This program is distributed in the hope that it will be useful, but
00019  * WITHOUT ANY WARRANTY; without even the implied warranty of
00020  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00021  * General Public License for more details.
00022  *
00023  */
00024 
00025 #ifndef SWLSTKEY_H
00026 #define SWLSTKEY_H
00027 
00028 #include <swkey.h>
00029 
00030 #include <defs.h>
00031 
00032 SWORD_NAMESPACE_START
00033 
00038 class SWDLLEXPORT ListKey : public SWKey {
00039 
00040         static SWClass classdef;
00041         void init();
00042 
00043 protected:
00044         int arraypos;
00045         int arraymax;
00046         int arraycnt;
00047         SWKey **array;
00048 
00049 public:
00050 
00055         ListKey(const char *ikey = 0);
00056         ListKey(ListKey const &k);
00057 
00060         virtual ~ListKey();
00061 
00062         virtual SWKey *clone() const;
00063         
00066         virtual void clear();
00067 
00070         virtual void ClearList() { clear(); }
00071 
00075         virtual int Count();
00076         
00079         virtual void Remove();
00080         
00086         virtual char SetToElement(int ielement, SW_POSITION = TOP);
00087         
00093         virtual SWKey *getElement(int pos = -1);
00094         
00095         // deprecated, use above function
00096         virtual SWKey *GetElement(int pos = -1) { return getElement(pos); }
00097 
00101         ListKey & operator <<(const SWKey &ikey) { add(ikey); return *this; }
00102         virtual void add(const SWKey &ikey);
00103 
00108         virtual void copyFrom(const ListKey & ikey);
00109         virtual void copyFrom(const SWKey & ikey) { SWKey::copyFrom(ikey); }
00110 
00116         virtual void setPosition(SW_POSITION pos);
00117         
00120         virtual void decrement(int step);
00121         
00124         virtual void increment(int step);
00125 
00126         virtual bool isTraversable() const { return true; }
00127         virtual long Index() const { return arraypos; }
00128         virtual const char *getRangeText() const;
00129 
00134         virtual long Index(long index) { SetToElement(index); return Index (); }
00135         virtual const char *getText() const;
00136         virtual void setText(const char *ikey);
00137         virtual void sort();
00138 
00139         SWKEY_OPERATORS
00140         ListKey & operator =(const ListKey &key) { copyFrom(key); return *this; }
00141 };
00142 
00143 SWORD_NAMESPACE_END
00144 #endif