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
|
/******************************************************************************
* listkey.h - code for base class 'listkey'. listkey is the basis for all
* types of keys for indexing into modules
* (e.g. verse, word,
* place, etc.)
*
* $Id: listkey.h,v 1.19 2003/08/31 01:58:13 scribe Exp $
*
* Copyright 1998 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 SWLSTKEY_H
#define SWLSTKEY_H
#include <swkey.h>
#include <defs.h>
SWORD_NAMESPACE_START
/** ListKey is the basis for all
* types of keys that have lists of specified indexes
* (e.g. a list of verses, place, etc.)
*/
class SWDLLEXPORT ListKey : public SWKey {
static SWClass classdef;
void init ();
protected:
int arraypos;
int arraymax;
int arraycnt;
SWKey **array;
public:
/** initializes instance of ListKey
*
* @param ikey text key
*/
ListKey(const char *ikey = 0);
ListKey(ListKey const &k);
/** cleans up instance of ListKey
*/
virtual ~ ListKey();
virtual SWKey *clone() const;
/** Clears out elements of list
*/
virtual void ClearList();
/** Returns number of elements in list
* @return number of elements in list
*/
virtual int Count();
/** Removes current element from list
*/
virtual void Remove();
/** Sets key to element number
*
* @param ielement element number to set to
* @return error status
*/
virtual char SetToElement(int ielement, SW_POSITION = TOP);
/** Gets a key element number
*
* @param pos element number to get (or default current)
* @return Key or null on error
*/
virtual SWKey *getElement(int pos = -1);
// deprecated, use above function
virtual SWKey *GetElement(int pos = -1) { return getElement(pos); }
/** Adds an element to the list
* @param ikey the element to add
*/
ListKey & operator <<(const SWKey &ikey) { add(ikey); return *this; }
virtual void add(const SWKey &ikey);
/** Equates this ListKey to another ListKey object
*
* @param ikey other ListKey object
*/
virtual void copyFrom(const ListKey & ikey);
virtual void copyFrom(const SWKey & ikey) { SWKey::copyFrom(ikey); }
/** Positions this key
*
* @param pos position
* @return *this
*/
virtual void setPosition(SW_POSITION pos);
/** Decrements a number of elements
*/
virtual void decrement(int step);
/** Increments a number of elements
*/
virtual void increment(int step);
virtual char Traversable() { return 1; }
virtual long Index() const { return arraypos; }
virtual const char *getRangeText() const;
/**
* Returns the index for the new one given as as parameter.
* The first parameter is the new index.
*/
virtual long Index(long index) { SetToElement (index); return Index (); }
virtual const char *getText() const;
virtual void setText(const char *ikey);
SWKEY_OPERATORS
ListKey & operator =(const ListKey &key) { copyFrom(key); return *this; }
};
SWORD_NAMESPACE_END
#endif
|