TReK C++  5.3.3
Telemetry/Command API
trek::EnumeratorSwitchSet Class Reference

This class switches calibrator sets. More...

#include <enumerator_switch_set.h>

Inherits trek::SwitchSet.

Public Member Functions

int32_t AddEnumerator (BaseEnumerator *input)
 Adds an Enumerator. More...
 
int32_t AddEnumerator (BaseEnumerator &input)
 Adds an enumerator. More...
 
int32_t DeleteEnumerator (const char *name)
 Deletes the specified enumerator. More...
 
void DeleteAllEnumerators ()
 Deletes all of the enumerators. More...
 
BaseEnumerator * GetEnumerator (const char *name)
 Returns the enumerator with the specified name. More...
 
int32_t Get (const char *str_value, uint32_t *int_value)
 Gets the integer value from the enumerated string. More...
 
int32_t Get (uint32_t int_value, char *output_str, uint32_t *size_of_output)
 Gets the enumerated value for the input value. More...
 
Constructors, Destructor, and Other Basic Methods
 EnumeratorSwitchSet ()
 Default constructor of the class.
 
 EnumeratorSwitchSet (EnumeratorSwitchSet &input)
 Copy constructor of the class.
 
virtual ~EnumeratorSwitchSet ()
 Class destructor. More...
 
virtual SwitchSetClone ()
 Creates and returns an extact copy of the object.
 
void operator= (EnumeratorSwitchSet &right_side)
 Provides the equal operator.
 
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 Packet definition from the specified file. More...
 
int32_t SaveFile (const char *filename)
 Saves the Packet definition to the specified file. More...
 
virtual int32_t ToXml (XmlElement &element)
 
virtual int32_t FromXml (XmlElement &element)
 
- Public Member Functions inherited from trek::SwitchSet
int32_t SetDefaultSetName (const char *name)
 Sets the default set name. More...
 
const char * GetDefaultSetName ()
 Gets the default set name. More...
 
int32_t SetSwitchParameterName (const char *name)
 Sets the name of the parameter to use as a switch. More...
 
const char * GetSwitchParameterName ()
 Gets the parameter name for the switch. More...
 
void SetSwitchType (switch_type input)
 Sets the type of switch to use. More...
 
switch_type GetSwitchType ()
 Returns the current switch type. More...
 
int32_t SetSwitchParameter (Parameter *input_ptr)
 Sets the parameter to use for switching. More...
 
int32_t AddRangeSwitch (double low, double high, const char *name)
 Adds a range switch. More...
 
int32_t AddEnumerationSwitch (const char *enum_name, const char *name)
 Adds an enumeration switch. More...
 
int32_t DeleteRangeSwitch (double low)
 Deletes the specified range switch. More...
 
int32_t DeleteEnumerationSwitch (const char *enum_name)
 Deletes the specified enumeration switch. More...
 
int32_t GetRangeSwitches (double **input, uint32_t &array_size)
 Gets the low value for each range switch. More...
 
void GetEnumerationSwitches (StringArray &input)
 Gets the enumeration values for the switch. More...
 
int32_t GetRangeSwitchInfo (double low, double &high, char **name)
 Gets the high value and name for a range switch based on its low value. More...
 
int32_t GetEnumerationInfo (const char *enum_name, char **name)
 Gets the name for a switch based on its enumerated value. More...
 
int32_t Validate ()
 Determines if it is safe to use the switch set. More...
 
const char * GetValidationErrors ()
 Gets a string of the last validation errors. More...
 
uint32_t GetEnumerationInfoLength (const char *enum_name)
 Gets the length for returned info of input parameter. Does not include space for the NULL termination character. More...
 
int32_t GetEnumerationInfo (const char *enum_name, char *name, uint16_t &name_size)
 Gets the name for a switch based on its enumerated value. More...
 
uint32_t GetRangeSwitchInfoLength (double low)
 Gets the length for returned info of input parameter. Does not include space for the NULL termination character. More...
 
int32_t GetRangeSwitchInfo (double low, double &high, char *name, uint16_t &name_size)
 Gets the high value and name for a range switch based on its low value. More...
 
uint32_t GetNumberOfRangeSwitches ()
 Returns the number of range switches available. More...
 
int32_t GetRangeSwitches (double *low_values, uint32_t low_value_size)
 Gets the low value for each range switch. More...
 
void GetItemNames (StringArray &input)
 Retrieves an array of the (e.g., calibrator) names from the set. More...
 
 SwitchSet ()
 Default constructor of the class.
 
 SwitchSet (SwitchSet &input)
 Copy constructor of the class.
 
virtual ~SwitchSet ()
 Class destructor. More...
 
void operator= (SwitchSet &right_side)
 Provides the equal operator.
 
virtual void Init ()
 Initializes the object.
 
- Public Member Functions inherited from trek::NamedItem
void SetName (const char *input_ptr)
 Sets the name of the item. More...
 
void SetAlias (const char *input)
 Sets the alias of the item. More...
 
void SetShortDescription (const char *input_ptr)
 Sets the short description of the item. More...
 
void SetLongDescription (const char *input_ptr)
 Sets the long description of the item. More...
 
void SetUserDescription (const char *input_ptr)
 Sets the user description of the item. More...
 
void SetOwner (const char *input_ptr)
 Sets the owner of the item. More...
 
const char * GetName ()
 Returns the name of the item.
 
const char * GetAlias ()
 Returns the alias of the item.
 
const char * GetShortDescription ()
 Returns the short description of the item.
 
const char * GetLongDescription ()
 Returns the long description of the item.
 
const char * GetUserDescription ()
 Returns the user description of the item.
 
const char * GetOwner ()
 Returns the owner of the item.
 
 NamedItem ()
 Default constructor of the class.
 
 NamedItem (NamedItem &input)
 Copy constructor of the class.
 
virtual ~NamedItem ()
 Class destructor. More...
 
void operator= (NamedItem &right_side)
 Provides the equal operator.
 
bool operator== (NamedItem &right_side)
 Provides the == operator.
 

Detailed Description

This class switches calibrator sets.

The details of switching are defined in SwitchSet. This class limits the type of information that is in the set and provides the serialization of the data.

Constructor & Destructor Documentation

◆ ~EnumeratorSwitchSet()

trek::EnumeratorSwitchSet::~EnumeratorSwitchSet ( )
virtual

Class destructor.

Removes all resources created with this instance of the class.

Member Function Documentation

◆ AddEnumerator() [1/2]

int32_t trek::EnumeratorSwitchSet::AddEnumerator ( BaseEnumerator &  input)

Adds an enumerator.

Adds the enumerator that can be referenced by a switch. The name of the enumerator is used for the reference.

Parameters
[in]inputA copy is made for this class.
Returns
SUCCESS
TREK_DATA_NULL_PTR
TREK_DATA_ALREADY_EXISTS

Example:

re.Add( 0, "OFF", 0 );
re.Add( 1, "ON", 255 );
ret_value = ess.AddEnumerator( re );
This class switches calibrator sets.
Definition: enumerator_switch_set.h:20
This class maps ranges of unsigned integer values to strings for enumeration.
Definition: range_enumerator.h:21
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.
Definition: range_enumerator.cpp:152

◆ AddEnumerator() [2/2]

int32_t trek::EnumeratorSwitchSet::AddEnumerator ( BaseEnumerator *  input)

Adds an Enumerator.

Adds the enumerator that can be referenced by a switch. The name of the enumerator is used for the reference.

Parameters
[in]inputA pointer to a valid enumerator. A copy is made for this class.
Returns
SUCCESS
TREK_DATA_NULL_PTR
TREK_DATA_ALREADY_EXISTS

Example:

re.Add( 0, "OFF", 0 );
re.Add( 1, "ON", 255 );
ret_value = ess.AddEnumerator( &re );
int32_t AddEnumerator(BaseEnumerator *input)
Adds an Enumerator.
Definition: enumerator_switch_set.cpp:92

◆ DeleteAllEnumerators()

void trek::EnumeratorSwitchSet::DeleteAllEnumerators ( )

Deletes all of the enumerators.

Example:

e.SetName( "whatever" );
e.Add( 0, "Off" );
e.Add( 1, "On" );
ret_value = ess.AddEnumerator( e );
This class maps unsigned integer values to strings for enumeration.
Definition: enumerator.h:21
int32_t Add(uint32_t int_value, const char *str_value_ptr, uint32_t end_value=0)
Adds the string values as enumeration for the unsigned integer value.
Definition: enumerator.cpp:159
void DeleteAllEnumerators()
Deletes all of the enumerators.
Definition: enumerator_switch_set.cpp:167

◆ DeleteEnumerator()

int32_t trek::EnumeratorSwitchSet::DeleteEnumerator ( const char *  name)

Deletes the specified enumerator.

Parameters
[in]nameThe name of the enumerator to delete.
Returns
SUCCESS
TREK_DATA_NULL_PTR
TREK_DATA_DOES_NOT_EXIST

Example:

e.SetName( "whatever" );
e.Add( 0, "Off" );
e.Add( 1, "On" );
ret_value = ess.AddEnumerator( e );
ret_value = ess.DeleteEnumerator( "whatever" );
int32_t DeleteEnumerator(const char *name)
Deletes the specified enumerator.
Definition: enumerator_switch_set.cpp:147

◆ Get() [1/2]

int32_t trek::EnumeratorSwitchSet::Get ( const char *  str_value,
uint32_t *  int_value 
)

Gets the integer value from the enumerated string.

Determines the correct enumerator to use based on the switching and gets the integer value for the enumeration.

Parameters
[in]str_valueThe enumerated string.
[out]int_valueThe corresponding integer value if return is SUCCESS.
Returns
SUCCESS
TREK_DATA_SWITCH_ERROR
other errors
Note
This method is typically only called by internal TReK code. Example:
uint32_t uint_value;
int ret_value;
ret_value = ess.Get( "OFF", &uint_value );
if( ret_value == SUCCESS )
{
printf( "Integer value is %u\n", uint_value );
}
int32_t Get(const char *str_value, uint32_t *int_value)
Gets the integer value from the enumerated string.
Definition: enumerator_switch_set.cpp:222
#define SUCCESS
The function completed successfully.
Definition: trek_error.h:8

◆ Get() [2/2]

int32_t trek::EnumeratorSwitchSet::Get ( uint32_t  int_value,
char *  output_str,
uint32_t *  size_of_output 
)

Gets the enumerated value for the input value.

Determines the correct enumerator to use based on the switching.

Parameters
[in]int_valueThe value to enumerate.
[out]output_strThe enumerated value if return is SUCCESS.
[in,out]size_of_outputThe amount of space that can be written to on input. If not enough space is returned, the value is populated with the required space.
Returns
SUCCESS
TREK_DATA_SWITCH_ERROR
other errors
Note
This method is typically only called by internal TReK code. Example:
char enum_str[20];
uint32_t size_of_output;
int ret_value;
size_of_output = 20;
ret_value = ess.Get( 1, enum_str, &size_of_output );
if( ret_value == SUCCESS )
{
printf( "Enumerated value is %s\n", enum_str );
}

◆ GetEnumerator()

BaseEnumerator * trek::EnumeratorSwitchSet::GetEnumerator ( const char *  name)

Returns the enumerator with the specified name.

The returned copy is owned by the class. Don't go deleting it.

Parameters
[in]nameThe name of the calibrator to find.
Returns
A pointer to the calibrator if found and NULL otherwise.

Example:

Enumerator *enum_ptr;
enum_ptr = ess.GetEnumerator( "whatever" );
if( enum_ptr )
{
// safe to use
}
BaseEnumerator * GetEnumerator(const char *name)
Returns the enumerator with the specified name.
Definition: enumerator_switch_set.cpp:192

◆ LoadFile()

int32_t trek::EnumeratorSwitchSet::LoadFile ( const char *  filename)

Loads the Packet definition from the specified file.

Reads an XML format for the Packet. It can be written in with SaveFile.

Parameters
[in]filenameThe file to load the parameter object from.
Returns
SUCCESS
TREK_DATA_NULL_PTR
Other return codes

Example:

ret_value = ess.LoadFile( "my_file.xml" );
int32_t LoadFile(const char *filename)
Loads the Packet definition from the specified file.
Definition: enumerator_switch_set.cpp:293

◆ SaveFile()

int32_t trek::EnumeratorSwitchSet::SaveFile ( const char *  filename)

Saves the Packet definition to the specified file.

Writes an XML format for the Packet. It can be read in with LoadFile.

Parameters
[in]filenameThe file to save the parameter object to.
Returns
SUCCESS
TREK_DATA_NULL_PTR
Other return codes

Example:

ret_value = ess.SaveFile( "my_file.xml" );
int32_t SaveFile(const char *filename)
Saves the Packet definition to the specified file.
Definition: enumerator_switch_set.cpp:327