KrChoice
Description
#include "krwc.hpp"
This class represents a set of choices, each of which has a name, and of which exactly one is chosen at a time. Its main purpose is to be used as an input data structure for KrWinComm.
Derivation
KrChoice inherits from IBase.
Constructors
You can construct and destruct objects of this class.
The default constructor creates an empty set of choices. Before an object created that way is actually used, add should have been called at least once.
Overload 1
public: KrChoice ();
You may also construct a KrChoice object from an existing KrChoiceData object.
Overload 2
public: KrChoice (const KrChoiceData & aData);
Public Functions
Active choice
get
This function returns the id of the currently active choice.
public: int get();
set
Pass a choice's id as an argument to this function to make the choice the active one.
public: void set (int id);
Adding new choices
add
There are to ways to add a new choice to the set.
Overload 1
public: int add (const IString & newChoice);
Use this overload to add a choice and assign the next free id to it. This id is returned by the function.
Overload 2
public: int add (int id, const IString & newChoice);
Use this overload to add a choice and assign a predefined id to it. If this id is not free anymore, the call fails, and zero is returned. Otherwise, the predefined id itself is returned.
Constructors
KrChoice
You can construct and destruct objects of this class.
The default constructor creates an empty set of choices. Before an object created that way is actually used, add should have been called at least once.
Overload 1
public: KrChoice ();
You may also construct a KrChoice object from an existing KrChoiceData object.
Overload 2
public: KrChoice (const KrChoiceData & aData);
Queries
getFirstKey
This function returns the id of the first choice in the set.
public: int getFirstKey ();
Note: If you call this function when the set is empty, an IEmptyException is thrown.
getNextKey
This function returns the id of the next choice in the set which comes after the id passed as an argument.
public: int getNextKey (int id);
Note: If you pass an invalid id to this function, an ICursorInvalidException is thrown.
If the id passed to the function already belongs to the last choice, this same id is returned.
getText
This function returns the name of the choice whose id is passed as an argument.
public: IString & getText (int id);
Note: If you pass an invalid id to this function, an INotContainsKeyException is thrown.
numberOfEntries
This function returns the number of choices currently in the set.
public: int numberOfEntries ();