TReK C++  5.3.3
Telemetry/Command API
trek::SwitchSet Class Referenceabstract

This class is the abstraction for sets of information that can be switch by the value of a parameter. More...

#include <switch_set.h>

Inherits trek::NamedItem.

Inherited by trek::CalibratorSwitchSet, trek::EnumeratorSwitchSet, trek::ExpectedStateAlarmSwitchSet, and trek::LimitAlarmSwitchSet.

Public Member Functions

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...
 
Constructors, Destructor, and Other Basic Methods
 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 is the abstraction for sets of information that can be switch by the value of a parameter.

The switch parameter can be used to determine which set of information to use. Used for enumeration, calbiration, limits, and expected states. Two types of switching are supported: range switching and enumeration switching.

Constructor & Destructor Documentation

◆ ~SwitchSet()

trek::SwitchSet::~SwitchSet ( )
virtual

Class destructor.

Removes all resources created with this instance of the class.

Member Function Documentation

◆ AddEnumerationSwitch()

int32_t trek::SwitchSet::AddEnumerationSwitch ( const char *  enum_name,
const char *  name 
)

Adds an enumeration switch.

Adds the specified enumeration switch. Checks are performed to make sure the specified enumeration does not already exist.

Parameters
[in]enum_nameThe enumerated value to use for switching.
[in]nameThe name of the item to switch to when the switch parameter has the specified enumeration.
Returns
SUCCESS
TREK_DATA_NULL_PTR
TREK_DATA_INCORRECT_SWITCH_TYPE
TREK_DATA_ALREADY_EXISTS

Example:

int32_t ret_value;
ret_value = css.AddEnumerationSwitch( "On", "one" );
ret_value = css.AddEnumerationSwitch( "OFF", "two" );
This class switches calibrator sets.
Definition: calibrator_switch_set.h:20
int32_t AddEnumerationSwitch(const char *enum_name, const char *name)
Adds an enumeration switch.
Definition: switch_set.cpp:700

◆ AddRangeSwitch()

int32_t trek::SwitchSet::AddRangeSwitch ( double  low,
double  high,
const char *  name 
)

Adds a range switch.

Adds the specified range switch. Checks are performed to make sure the specified range does not overlap with a current range. Ranges are evaluated by low < value <= high.

Parameters
[in]lowThe low value for the range.
[in]highThe high value for the range.
[in]nameThe name of the item to switch to when the switch parameter falls within the range.
Returns
SUCCESS
TREK_DATA_NULL_PTR
TREK_DATA_INCORRECT_SWITCH_TYPE
TREK_DATA_LOW_TO_HIGH
TREK_DATA_NEED_UNIQUE_RANGE

Example:

int32_t ret_value;
ret_value = css.AddRangeSwitch( 0, 10, "one" );
ret_value = css.AddRangeSwitch( 10, 100, "two" );
int32_t AddRangeSwitch(double low, double high, const char *name)
Adds a range switch.
Definition: switch_set.cpp:641

◆ DeleteEnumerationSwitch()

int32_t trek::SwitchSet::DeleteEnumerationSwitch ( const char *  enum_name)

Deletes the specified enumeration switch.

Parameters
[in]enum_nameThe enumerated value to delete.
Returns
SUCCESS
TREK_DATA_NULL_PTR
TREK_DATA_DOES_NOT_EXIST

Example:

int32_t ret_value;
ret_value = css.AddRangeSwitch( "first", "one" );
ret_value = css.DeleteEnumerationSwitch( "first" );
int32_t DeleteEnumerationSwitch(const char *enum_name)
Deletes the specified enumeration switch.
Definition: switch_set.cpp:769

◆ DeleteRangeSwitch()

int32_t trek::SwitchSet::DeleteRangeSwitch ( double  low)

Deletes the specified range switch.

Only need to specify the low range as ranges are not allowed to overlap.

Parameters
[in]lowThe low range of the switch to delete.
Returns
SUCCESS
TREK_DATA_DOES_NOT_EXIST

Example:

int32_t ret_value;
ret_value = css.AddRangeSwitch( 0, 10, "one" );
ret_value = css.DeleteRangeSwitch( 0 );
int32_t DeleteRangeSwitch(double low)
Deletes the specified range switch.
Definition: switch_set.cpp:737

◆ GetDefaultSetName()

const char * trek::SwitchSet::GetDefaultSetName ( )

Gets the default set name.

Returns
The default set name (returns empty string if not set)

Example:

printf( "Default set name is '%s'\n", css.GetDefaultSetName();
const char * GetDefaultSetName()
Gets the default set name.
Definition: switch_set.cpp:508

◆ GetEnumerationInfo() [1/2]

int32_t trek::SwitchSet::GetEnumerationInfo ( const char *  enum_name,
char **  name 
)

Gets the name for a switch based on its enumerated value.

All of the enumerations can be found by calling GetEnumerationSwitches. The caller of the function is responsible for deleting the memory that is created.

Parameters
[in]enum_nameThe enumerated value to search for
[out]nameThe name of the item when switch is valid.
Returns
SUCCESS
TREK_DATA_NULL_PTR
TREK_DATA_DOES_NOT_EXIST

Example:

int32_t ret_value;
char *name;
ret_value = css.GetEnumerationInfo( "ON", &name );
if( ret_value == SUCCESS )
{
printf( "When ON use %s\n", name );
delete name;
}
int32_t GetEnumerationInfo(const char *enum_name, char **name)
Gets the name for a switch based on its enumerated value.
Definition: switch_set.cpp:1080
#define SUCCESS
The function completed successfully.
Definition: trek_error.h:8

◆ GetEnumerationInfo() [2/2]

int32_t trek::SwitchSet::GetEnumerationInfo ( const char *  enum_name,
char *  name,
uint16_t &  name_size 
)

Gets the name for a switch based on its enumerated value.

All of the enumerations can be found by calling GetEnumerationSwitches. The caller of the function is responsible for allocating the memory needed for the returned data by calling GetEnumerationInfoLength.

Parameters
[in]enum_nameThe enumerated value to search for
[out]nameThe name of the item when switch is valid.
[in]name_sizeThe size of the data allocated for name.
Returns
SUCCESS
TREK_DATA_NULL_PTR
TREK_DATA_DOES_NOT_EXIST
TREK_DATA_NOT_ENOUGH_SPACE

Example:

int32_t ret_value;
char *name;
name = new char[css.GetEnumerationInfoLength("ON")];
ret_value = css.GetEnumerationInfo( "ON", name, name_size );
if( ret_value == SUCCESS )
{
printf( "When ON use %s\n", name );
delete name;
}
uint32_t GetEnumerationInfoLength(const char *enum_name)
Gets the length for returned info of input parameter. Does not include space for the NULL termination...
Definition: switch_set.cpp:1115

◆ GetEnumerationInfoLength()

uint32_t trek::SwitchSet::GetEnumerationInfoLength ( const char *  enum_name)

Gets the length for returned info of input parameter. Does not include space for the NULL termination character.

If the input does not exist, zero is returned.

Parameters
[in]enum_nameThe enumerated value to search for
Returns
Number of bytes needed for info string

Example:

uint32_t info_size = css.GetEnumerationInfoLength("ON");
printf( "The info returned for 'ON' will be %u bytes in length.\n", info_size );

◆ GetEnumerationSwitches()

void trek::SwitchSet::GetEnumerationSwitches ( StringArray input)

Gets the enumeration values for the switch.

The input array will be cleared prior to values being added.

Parameters
[out]inputWill contain all of the enumerated values for the switch.

Example:

StringArray enum_array;
css.GetEnumerationSwitches( enum_array );
for( uint32_t ii = 0; ii < enum_array.Size(); ii++ )
printf( "Enum value is %s\n", enum_array.GetAt(ii) );
This class provides a wrapper for std::vector and std::string so different versions of the standard t...
Definition: string_array.h:19
uint32_t Size()
Returns the number of items in the string array.
Definition: string_array.cpp:67
const char * GetAt(uint32_t index)
Returns the string at the given location.
Definition: string_array.cpp:89
void GetEnumerationSwitches(StringArray &input)
Gets the enumeration values for the switch.
Definition: switch_set.cpp:915

◆ GetItemNames()

void trek::SwitchSet::GetItemNames ( StringArray input)

Retrieves an array of the (e.g., calibrator) names from the set.

Parameters
[in]inputThe array to set. Previous items will be cleared.

Example:

StringArray my_array;
//...
css.GetItemNames( my_array );
void GetItemNames(StringArray &input)
Retrieves an array of the (e.g., calibrator) names from the set.
Definition: switch_set.cpp:453

◆ GetNumberOfRangeSwitches()

uint32_t trek::SwitchSet::GetNumberOfRangeSwitches ( )

Returns the number of range switches available.

Returns
The number of range switches.

◆ GetRangeSwitches() [1/2]

int32_t trek::SwitchSet::GetRangeSwitches ( double **  input,
uint32_t &  array_size 
)

Gets the low value for each range switch.

The low range returned can be used to access details about each range by calling GetRangeSwitchInfo. The caller of the function is responsible for deleting the memory that is created.

Parameters
[out]inputThis value will contain an array of doubles that are the low value.
[out]array_sizeThe number of values returned.
Returns
SUCCESS
TREK_DATA_NULL_PTR

Example:

int32_t ret_value;
double *low_values;
uint32_t array_size;
ret_value = css.GetRangeSwitches( &low_values, array_size );
if( ret_value == SUCCESS )
{
for( uint32_t ii = 0; ii < array_size; ii++ )
printf( "Low value was %lf\n", low_values[ii] );
delete low_values;
}
int32_t GetRangeSwitches(double **input, uint32_t &array_size)
Gets the low value for each range switch.
Definition: switch_set.cpp:814

◆ GetRangeSwitches() [2/2]

int32_t trek::SwitchSet::GetRangeSwitches ( double *  low_values,
uint32_t  low_value_size 
)

Gets the low value for each range switch.

The low range returned can be used to access details about each range by calling GetRangeSwitchInfo. The caller of the function is responsible for allocating the memory that is needed. The size of memory needed can be found by calling GetNumberOfRangeSwitches.

Parameters
[out]inputThis value will contain an array of doubles that are the low value.
[in]array_sizeThe size of the array.
Returns
SUCCESS
TREK_DATA_NULL_PTR
TREK_DATA_NOT_ENOUGH_SPACE

Example:

int32_t ret_value;
double *low_values;
uint32_t array_size;
array_size = GetNumberOfRangeSwitches();
low_values = new double[array_size];
ret_value = css.GetRangeSwitches( low_values, array_size );
if( ret_value == SUCCESS )
{
for( uint32_t ii = 0; ii < array_size; ii++ )
printf( "Low value was %lf\n", low_values[ii] );
}
delete low_values;
uint32_t GetNumberOfRangeSwitches()
Returns the number of range switches available.
Definition: switch_set.cpp:839

◆ GetRangeSwitchInfo() [1/2]

int32_t trek::SwitchSet::GetRangeSwitchInfo ( double  low,
double &  high,
char **  name 
)

Gets the high value and name for a range switch based on its low value.

All of the low ranges can be found by calling GetRangeSwitches. The caller of the function is responsible for deleting the memory that is created.

Parameters
[in]lowThe low value to search for
[out]highThe corresponding low value.
[out]nameThe name of the item when switch is valid.
Returns
SUCCESS
TREK_DATA_NULL_PTR
TREK_DATA_DOES_NOT_EXIST

Example:

int32_t ret_value;
double high_value;
char *name;
ret_value = css.GetRangeSwitchInfo( 5, high_value, &name );
if( ret_value == SUCCESS )
{
printf( "5 < value <= %lf will use %s\n", high_value, name );
delete name;
}
int32_t GetRangeSwitchInfo(double low, double &high, char **name)
Gets the high value and name for a range switch based on its low value.
Definition: switch_set.cpp:953

◆ GetRangeSwitchInfo() [2/2]

int32_t trek::SwitchSet::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.

All of the low ranges can be found by calling GetRangeSwitches. The caller of the function is responsible for allocating the memory that is needed. The size of data that will be returned can be found by calling GetRangeSwitchInfoLength.

Parameters
[in]lowThe low value to search for
[out]highThe corresponding low value.
[out]nameThe name of the item when switch is valid.
[in]name_sizeThe size of data allocated for name.
Returns
SUCCESS
TREK_DATA_NULL_PTR
TREK_DATA_DOES_NOT_EXIST

Example:

int32_t ret_value;
double high_value;
char *name;
ret_value = css.GetRangeSwitchInfo( 5, high_value, &name );
if( ret_value == SUCCESS )
{
printf( "5 < value <= %lf will use %s\n", high_value, name );
delete name;
}

◆ GetRangeSwitchInfoLength()

uint32_t trek::SwitchSet::GetRangeSwitchInfoLength ( double  low)

Gets the length for returned info of input parameter. Does not include space for the NULL termination character.

If the input does not exist, zero is returned.

Parameters
[in]lowThe value to search for
Returns
Number of bytes needed for info string

Example:

uint32_t info_size = css.GetRangeSwitchInfoLength(15);
printf( "The info returned for value 15 will be %u bytes in length.\n", info_size );
uint32_t GetRangeSwitchInfoLength(double low)
Gets the length for returned info of input parameter. Does not include space for the NULL termination...
Definition: switch_set.cpp:989

◆ GetSwitchParameterName()

const char * trek::SwitchSet::GetSwitchParameterName ( )

Gets the parameter name for the switch.

Returns
The switch parameter name (returns empty string if not set)

Example:

printf( "Switch parameter name is '%s'\n", css.GetSwitchParameterName();
const char * GetSwitchParameterName()
Gets the parameter name for the switch.
Definition: switch_set.cpp:560

◆ GetSwitchType()

switch_type trek::SwitchSet::GetSwitchType ( )

Returns the current switch type.

Returns
RANGE_SWITCH or ENUMERATION_SWITCH

Example:

printf( "It's a range switch.\n" );
else
printf( "It's an enumeration switch.\n" );
switch_type GetSwitchType()
Returns the current switch type.
Definition: switch_set.cpp:614
@ RANGE_SWITCH
Range switch (low < value <= high)
Definition: switch_set.h:23

◆ GetValidationErrors()

const char * trek::SwitchSet::GetValidationErrors ( )

Gets a string of the last validation errors.

Returns
A constant string of validation errors. Example:
int32_t num_err;
// assuming that set has some data added already.
num_err = limit_set.Validate();
if( num_err )
{
printf( "%d validation errors found.\n", num_err );
printf( "%s\n", limit_set.GetValidationErrors() );
}
else
printf( "ok to use\n" );
This class switches limit sets.
Definition: limit_alarm_switch_set.h:35
const char * GetValidationErrors()
Gets a string of the last validation errors.
Definition: switch_set.cpp:1327
int32_t Validate()
Determines if it is safe to use the switch set.
Definition: switch_set.cpp:1209

◆ SetDefaultSetName()

int32_t trek::SwitchSet::SetDefaultSetName ( const char *  name)

Sets the default set name.

The name of the item (e.g., calibrator) to use if no other set can be identified by switching.

Parameters
[in]nameThe name of the set.
Returns
SUCCESS
TREK_DATA_NULL_PTR

Example:

ret_value = css.SetDefaultSetName( "CalSet1" );
int32_t SetDefaultSetName(const char *name)
Sets the default set name.
Definition: switch_set.cpp:477

◆ SetSwitchParameter()

int32_t trek::SwitchSet::SetSwitchParameter ( Parameter input_ptr)

Sets the parameter to use for switching.

Parameters
[in]input_ptrA valid reference to a parameter in a packet.
Returns
SUCCESS
TREK_DATA_NULL_PTR
Note
This function is only intended for use by internal TReK code.

◆ SetSwitchParameterName()

int32_t trek::SwitchSet::SetSwitchParameterName ( const char *  name)

Sets the name of the parameter to use as a switch.

Parameters
[in]nameThe name of the switch parameter.
Returns
SUCCESS
TREK_DATA_NULL_PTR

Example:

ret_value = css.SetSwitchParameterName( "SwitchParameter" );
int32_t SetSwitchParameterName(const char *name)
Sets the name of the parameter to use as a switch.
Definition: switch_set.cpp:529

◆ SetSwitchType()

void trek::SwitchSet::SetSwitchType ( switch_type  input)

Sets the type of switch to use.

Parameters
inputThe new switch type

Example:

void SetSwitchType(switch_type input)
Sets the type of switch to use.
Definition: switch_set.cpp:596
@ ENUMERATION_SWITCH
Enumerator switch (value == "string")
Definition: switch_set.h:24

◆ Validate()

int32_t trek::SwitchSet::Validate ( )

Determines if it is safe to use the switch set.

Insures that class is properly configured. Safe to use if 0 is returned.

Returns
The number of errors found.

Example:

int32_t num_err;
// assuming that set has some data added already.
num_err = limit_set.Validate();
if( num_err )
{
printf( "%d validation errors found.\n", num_err );
printf( "%s\n", limit_set.GetValidationErrors() );
}
else
printf( "ok to use\n" );