KrChoice: Difference between revisions
Created page with "==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 i..." |
mNo edit summary |
||
(2 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
==Description == | ==Description== | ||
'''#include "krwc.hpp"''' | '''#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. | 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== | ==Derivation== | ||
KrChoice inherits from IBase. | KrChoice inherits from IBase. | ||
==Constructors== | ==Constructors== | ||
You can construct and destruct objects of this class. | 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. | 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''' | '''Overload 1''' | ||
public: | |||
KrChoice (); | |||
You may also construct a KrChoice object from an existing KrChoiceData object. | |||
'''Overload 2''' | |||
public: | |||
KrChoice (const KrChoiceData & aData); | |||
'''Overload 2''' | |||
public: | |||
KrChoice (const KrChoiceData & aData); | |||
==Public Functions== | |||
===Active choice === | ===Active choice === | ||
====get==== | ====get==== | ||
This function returns the id of the currently active choice. | This function returns the id of the currently active choice. | ||
public: | |||
public: | int get(); | ||
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. | |||
public: | '''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==== | ====getFirstKey==== | ||
This function returns the id of the first choice in the set. | This function returns the id of the first choice in the set. | ||
public: | |||
public: | int getFirstKey (); | ||
int getFirstKey (); | '''Note:''' If you call this function when the set is empty, an IEmptyException is thrown. | ||
'''Note:''' | |||
====getNextKey==== | ====getNextKey==== | ||
This function returns the id of the next choice in the set which comes after the id passed as an argument. | |||
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); | |||
public: | '''Note:''' If you pass an invalid id to this function, an ICursorInvalidException is thrown. | ||
int getNextKey (int id); | |||
'''Note:''' | |||
If the id passed to the function already belongs to the last choice, this same id is returned. | |||
==== | ====getText==== | ||
This function returns the | 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. | |||
public: | ====numberOfEntries==== | ||
int numberOfEntries (); | This function returns the number of choices currently in the set. | ||
public: | |||
int numberOfEntries (); | |||
[[Category: | [[Category:Kronis Classes]] |
Latest revision as of 10:12, 13 February 2017
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 ();