---
name: "listkey"
section: "3"
platform: "linux"
package: "libsword-dev"
version: "1.5.3-3woody2"
release: "Debian 3.0 (Woody)"
platforms: ["linux"]
url: "https://new.carta.tech/listkey"
---

# listkey(3)

ListKey is the basis for all types of keys that have lists of specified indexes (e.g.

## NAME

ListKey - ListKey is the basis for all types of keys that have lists of specified indexes (e.g.

## SYNOPSIS

`#include <listkey.h>`

Inherits **SWKey**.

### Public Methods

**ListKey** (const char \*ikey=0)\
 *initializes instance of ListKey.* **ListKey** (ListKey const &k)\
 virtual **~ListKey** ()\
 *cleans up instance of ListKey.* virtual **SWKey**\* **clone** () const\
 *Returns a copy of this* **SWKey** object. virtual void **ClearList** ()\
 *Clears out elements of list.* virtual int **Count** ()\
 *Returns number of elements in list.* virtual void **Remove** ()\
 *Removes current element from list.* virtual char **SetToElement** (int ielement, SW\_POSITION=TOP)\
 *Sets key to element number.* virtual **SWKey**\* **GetElement** (int pos=-1)\
 *Gets a key element number.* ListKey& **operator\<\<** (const **SWKey** &ikey)\
 *Adds an element to the list.* virtual void **add** (const **SWKey** &ikey)\
 virtual void **copyFrom** (const ListKey &ikey)\
 *Equates this ListKey to another ListKey object.* virtual void **copyFrom** (const **SWKey** &ikey)\
 *Equates this* **SWKey** to another **SWKey** object. virtual void **setPosition** (SW\_POSITION)\
 *Positions this key.* virtual void **decrement** (int step)\
 *Decrements a number of elements.* virtual void **increment** (int step)\
 *Increments a number of elements.* virtual char **Traversable** ()\
 virtual long **Index** () const\
 *Use this function to get te current position withing a module.* virtual long **Index** (long index)\
 *Returns the index for the new one given as as parameter.* SWKEY\_OPERATORS ListKey& **operator=** (const ListKey &key)\

### Protected Attributes

int **arraypos**\
 int **arraymax**\
 int **arraycnt**\
 **SWKey**\*\* **array**\

### Private Methods

void **init** ()\

### Static Private Attributes

**SWClass** **classdef**\

## DETAILED DESCRIPTION

ListKey is the basis for all types of keys that have lists of specified indexes (e.g.

a list of verses, place, etc.)

Definition at line 36 of file listkey.h.

## CONSTRUCTOR & DESTRUCTOR DOCUMENTATION

### ListKey::ListKey (const char \* ikey = 0)

initializes instance of ListKey.

**Parameters:**

- *ikey*

  text key

## MEMBER FUNCTION DOCUMENTATION

### int ListKey::Count ()` [virtual]`

Returns number of elements in list.

**Returns:**  number of elements in list

### SWKey \* ListKey::GetElement (int pos = -1)` [virtual]`

Gets a key element number.

**Parameters:**

- *pos*

  element number to get (or default current)

**Returns:**  Key or null on error

### long ListKey::Index (long index)` [inline, virtual]`

Returns the index for the new one given as as parameter.

The first parameter is the new index.

Reimplemented from **SWKey**.

Definition at line 112 of file listkey.h.

### long ListKey::Index () const` [inline, virtual]`

Use this function to get te current position withing a module.

Here's a small example how to use this function and **Index**(long). This function uses the GerLut module and chooses a random verse from the Bible and returns it.

```
 const char* randomVerse() {
   VerseKey vk;
   SWMgr mgr;
   LocaleMgr::systemLocaleMgr.setDefaultLocaleName("de");
   SWModule* module = mgr->Modules("GerLut");
   srand( time(0) );
   const double newIndex = (double(rand())/RAND_MAX)*(24108+8224);
   vk.Index(newIndex);
   module->SetKey(vk);
   char* text;
   sprintf(text, "%s: %s",(const char*)vk ,module->StripText(&vk));
   return text;
```

Reimplemented from **SWKey**.

Definition at line 106 of file listkey.h.

### char ListKey::SetToElement (int ielement, SW\_POSITION = TOP)` [virtual]`

Sets key to element number.

**Parameters:**

- *ielement*

  element number to set to

**Returns:**  error status

Referenced by Index().

### virtual SWKey\* ListKey::clone () const` [virtual]`

Returns a copy of this **SWKey** object.

This is useful to get a 1:1 copy of an **SWKey** based object.

**Returns:**  **SWKey**

Reimplemented from **SWKey**.

### void ListKey::copyFrom (const SWKey & ikey)` [inline, virtual]`

Equates this **SWKey** to another **SWKey** object.

**Parameters:**

- *ikey*

  other swkey object

Reimplemented from **SWKey**.

Definition at line 90 of file listkey.h.

### void ListKey::copyFrom (const ListKey & ikey)` [virtual]`

Equates this ListKey to another ListKey object.

**Parameters:**

- *ikey*

  other ListKey object

### ListKey & ListKey::operator\<\< (const SWKey & ikey)` [inline]`

Adds an element to the list.

**Parameters:**

- *ikey*

  the element to add

Definition at line 82 of file listkey.h.

### void ListKey::setPosition (SW\_POSITION)` [virtual]`

Positions this key.

**Parameters:**

- *p*

  position

**Returns:**  \*this

Reimplemented from **SWKey**.

## AUTHOR

Generated automatically by Doxygen for The Sword Project from the source code.
