TReK C++
5.3.3
Telemetry/Command API
|
This class maps ranges of unsigned integer values to strings for enumeration. More...
#include <range_enumerator.h>
Inherits BaseEnumerator.
Public Member Functions | |
Constructors, Destructor, and Other Basic Methods | |
RangeEnumerator () | |
Default constructor of the class. | |
virtual | ~RangeEnumerator () |
Class destructor. More... | |
void | operator= (RangeEnumerator &right_side) |
Provides the equal operator. | |
bool | operator== (RangeEnumerator &right_side) |
Provides the == operator. | |
virtual RangeEnumerator * | Clone () |
Returns an exact copy of the object;. | |
virtual void | Init () |
Initializes the object. More... | |
Setup Methods | |
These methods control setting up the API. | |
int32_t | Add (uint32_t start_value, const char *str_value_ptr, uint32_t end_value=0) |
Adds the string value as enumeration for the unsigned integer value range. More... | |
int32_t | Remove (const char *input) |
Removes the enumeration specifed by the string. More... | |
int32_t | Remove (uint32_t input) |
Removes the enumeration specifed by the integer (start value of range) More... | |
void | RemoveAll () |
Removes all enumerations. | |
Get Methods | |
int32_t | Get (const char *str_value, uint32_t *int_value) |
Finds the corresponding unsigned integer value for the specified string. More... | |
int32_t | Get (uint32_t int_value, char *output_str, uint32_t *size_of_output) |
Finds the corresponding string value for the specified unsigned integer. More... | |
uint32_t | GetNumberOfEnumerations () |
Returns the current number of enumerations. | |
void | GetEnumerations (StringArray &str_array) |
Gets a list of the string enumerations. More... | |
int32_t | GetEnumerations (uint32_t *uint_array, uint32_t *num_available) |
Gets a list of the integer values. Will always fail for RangeEnumerator since it has a start and end range. Another GetEnumerations() function is available for range enumerations. More... | |
int32_t | GetEnumerations (uint32_t *start_array, uint32_t *end_array, uint32_t *num_available) |
Gets a list of the start and end values for which enumerators exist. More... | |
Serialization Methods | |
These methods help read and write the class to disk or memory. Most users will not be interested in these. Those that are can continue reading. | |
int32_t | LoadFile (const char *filename) |
Loads the Enumerator definition from the specified file. More... | |
int32_t | SaveFile (const char *filename) |
Saves the Enumerator definition to the specified file. More... | |
This class maps ranges of unsigned integer values to strings for enumeration.
The unsigned integer values is limited to 32 bits.
|
virtual |
Class destructor.
Removes all resources created with this instance of the class.
int32_t trek::RangeEnumerator::Add | ( | uint32_t | start_value, |
const char * | str_value, | ||
uint32_t | end_value = 0 |
||
) |
Adds the string value as enumeration for the unsigned integer value range.
The range enumerator matches if the value is greater than or equal to the start value and less than or equal to the end value.
[in] | start_value | The start value for the enumerator. |
[in] | str_value | The string value. |
[in] | end_value | The end value for the enumerator. Must be >= start_value. |
Example:
int32_t trek::RangeEnumerator::Get | ( | const char * | str_value, |
uint32_t * | int_value | ||
) |
Finds the corresponding unsigned integer value for the specified string.
This function will return the 'start' value for the range.
[in] | str_value | String value to find. |
[out] | int_value | Corresponding integer value. |
Example:
int32_t trek::RangeEnumerator::Get | ( | uint32_t | int_value, |
char * | output_str, | ||
uint32_t * | size_of_output | ||
) |
Finds the corresponding string value for the specified unsigned integer.
If return code is SUCCESS, then the output_str contains a valid value.
[in] | int_value | Integer value to find. |
[out] | output_str | Corresponding string value. |
[in,out] | size_of_output | The size of the output buffer. If return code is TREK_DATA_NOT_ENOUGH_SPACE, then this value is reset to the number of bytes required for the given enumerated value. |
Example:
void trek::RangeEnumerator::GetEnumerations | ( | StringArray & | str_array | ) |
Gets a list of the string enumerations.
Deletes any items in the provided array prior to insertion. It is possible for duplicate strings to be returned. For example, if you used the following ranges 0-1 = RED, 2-3 = BLUE, and 4-7 = RED, then RED will be returned twice.
[out] | str_array | Contains all of the current string enumerations. |
Example:
int32_t trek::RangeEnumerator::GetEnumerations | ( | uint32_t * | start_array, |
uint32_t * | end_array, | ||
uint32_t * | num_available | ||
) |
Gets a list of the start and end values for which enumerators exist.
The number of items needed can be found by a call to GetNumberOfEnumerations().
[out] | start_array | Contains all of the start integer values. |
[out] | end_array | Contains all of the end integer values. |
[in,out] | num_available | The number of available slots in the array on input. Set to the number of valid items in the array on output. |
Example:
int32_t trek::RangeEnumerator::GetEnumerations | ( | uint32_t * | uint_array, |
uint32_t * | num_available | ||
) |
Gets a list of the integer values. Will always fail for RangeEnumerator since it has a start and end range. Another GetEnumerations() function is available for range enumerations.
The number of items needed can be found by a call to GetNumberOfEnumerations().
[out] | uint_array | Contains all of the current integer values. |
[in,out] | num_available | The number of available slots in the array on input. Set to the number of valid items in the array on output. |
Example:
|
virtual |
Initializes the object.
Removes all current enumerations.
int32_t trek::RangeEnumerator::LoadFile | ( | const char * | filename | ) |
Loads the Enumerator definition from the specified file.
Reads an XML format for the Enumerator. It can be written in with SaveFile.
[in] | filename | The file to load the Enumerator object from. |
Example:
int32_t trek::RangeEnumerator::Remove | ( | const char * | input | ) |
Removes the enumeration specifed by the string.
If more than one enumertor with this string exists, all are removed.
[in] | input | String value of enumeration to remove. |
Example:
int32_t trek::RangeEnumerator::Remove | ( | uint32_t | input | ) |
Removes the enumeration specifed by the integer (start value of range)
[in] | input | Start value of enumeration to remove. |
Example:
int32_t trek::RangeEnumerator::SaveFile | ( | const char * | filename | ) |
Saves the Enumerator definition to the specified file.
Writes an XML format for the Enumerator. It can be read in with LoadFile.
[in] | filename | The file to save the Enumerator object to. |
Example: