KrBitfield

From EDM2
Jump to: navigation, search

Description

#include "krwc.hpp"

This class represents a set of options, each of which has a name, and each of which can independently be selected or deselected. Its main purpose is to be used as an input data structure for KrWinComm.

Derivation

KrBitfield inherits from IBase.

Constructors

You can construct and destruct objects of this class.

The default constructor creates an empty set of options. Before an object created that way is actually used, add should have been called at least once.

Overload 1

public:
KrBitfield ();

You may also construct a KrBitfield object from an existing KrBitfieldData object.

Overload 2

public:
KrBitfield (const KrBitfieldData & aData);

Public Functions

Adding new options

add

There are to ways to add a new option to the set.

Overload 1

public:
int add (const IString & newEntry, Boolean checked = false);

Use this overload to add an option and assign the next free id to it. This id is returned by the function. The parameter checked lets you control whether the option should initially be set.

Overload 2

public:
int add (int id, const IString & newEntry, Boolean checked = false);

Use this overload to add an option 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

KrBitfield

You can construct and destruct objects of this class.

The default constructor creates an empty set of options. Before an object created that way is actually used, add should have been called at least once.

Overload 1

public:
KrBitfield ();

You may also construct a KrBitfield object from an existing KrBitfieldData object.

Overload 2

public:
KrBitfield (const KrBitfieldData & aData);

Control options

isChecked

Use this function to query the status of the option identified by the parameter id.

public:
Boolean isChecked (int id);

toggle

Use this function to change the status of an option. There are two overloads. Both return the new status of the option identified by the parameter id.

Overload 1

public:
Boolean toggle (int id, Boolean check);

Use this overload to set the option to the value check.

Overload 2

public:
Boolean toggle (int id);

This overload inverts the current status of the option.

Queries

getFirstKey

This function returns the id of the first option 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 option 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 option, this same id is returned.

getText

This function returns the name of the option 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 options currently in the set.

public:
int numberOfEntries ();