Dangerous SNMP
|
A Variant defines an arbitrary value (within the scope of SNMP). More...
#include <variant.hpp>
Public Types | |
enum | Type { SIMPLE_INTEGER, SIMPLE_STRING, SIMPLE_OID, SIMPLE_NULL, APPLICATION_IPADDRESS, APPLICATION_COUNTER32, APPLICATION_GAUGE32, APPLICATION_TIMETICKS, APPLICATION_OPAQUE, APPLICATION_COUNTER64, CONTEXT_NOSUCHOBJECT, CONTEXT_NOSUCHINSTANCE, CONTEXT_ENDOFMIBVIEW } |
This enumeration defines the different types of data that can be represented by this Variant. More... | |
Public Member Functions | |
Variant () | |
Default constructor; the Variant is set to a null value. | |
Variant (const Variant &variant) | |
Copy constructor; the Variant is set to a copy of the given one. | |
Variant & | operator= (const Variant &variant) |
Assignment operator; the Variant is set to a copy of the given one. | |
~Variant () | |
Destructor; all memory is freed. More... | |
Type | type () const |
This returns the type of the Variant. More... | |
void | set_null (Type type) throw ( InvalidTypeException ) |
This restores the Variant to its default, null state. More... | |
void | set_int32_t (Type type, int32_t i32=0) throw ( InvalidTypeException ) |
This sets the value to a signed, 32-bit integer. More... | |
void | set_uint32_t (Type type, uint32_t u32=0) throw ( InvalidTypeException ) |
This sets the value to an unsigned, 32-bit integer. More... | |
void | set_uint64_t (Type type, uint64_t u64=0) throw ( InvalidTypeException ) |
This sets the value to an unsigned, 64-bit integer. More... | |
void | set_string (Type type, std::string string=std::string()) throw ( InvalidTypeException ) |
This sets the value to a string. More... | |
void | set_oid (Type type, NumericOid oid=NumericOid()) throw ( InvalidTypeException ) |
This sets the value to an OID. More... | |
bool | is_null () const |
This returns whether or not the Variant represents a null value. More... | |
bool | is_int32_t () const |
This returns whether or not the Variant represents a 32-bit signed integer. More... | |
int32_t | get_int32_t () const throw ( InvalidTypeException ) |
This returns the 32-bit signed integer value of the Variant. More... | |
bool | is_uint32_t () const |
This returns whether or not the Variant represents a 32-bit unsigned integer. More... | |
uint32_t | get_uint32_t () const throw ( InvalidTypeException ) |
This returns the 32-bit unsigned integer value of the Variant. More... | |
bool | is_uint64_t () const |
This returns whether or not the Variant represents a 64-bit unsigned integer. More... | |
uint64_t | get_uint64_t () const throw ( InvalidTypeException ) |
This returns the 64-bit unsigned integer value of the Variant. More... | |
bool | is_string () const |
This returns whether or not the Variant represents a string. More... | |
const std::string & | get_string () const throw ( InvalidTypeException ) |
This returns the string value of the Variant. More... | |
bool | is_oid () const |
This returns whether or not the Variant represents an OID. More... | |
const NumericOid & | get_oid () const throw ( InvalidTypeException ) |
This returns the OID value of the Variant. More... | |
A Variant defines an arbitrary value (within the scope of SNMP).
It can have any one of a number of different "types". Thus, a Variant can represent a null value, an integer, a string, a 64-bit counter, etc.
There are four "simple" types in SNMP (imported directly from ASN.1):
There are six "application" types in SNMP (built from simple types):
Finally, there are three "error" types in SNMP (added in SNMPv2). These allow for much better error reporting in "get"-style operations.
If you are interested in determining the exact type of a Variant, then you may use the type
method, which will return the Variant::Type of the instance.
If you are interested in extracting the value from a Variant, then you must first check the type by using one of the is_...
methods, each of which tests for a particular C++ return type (for example, is_string
will return true for SIMPLE_STRING, APPLICATION_IPADDRESS, and APPLICATION_OPAQUE). Once you have determined the appropriate C++ type, you may then use the matching get_...
function to retrieve the value (for example, if is_string
returns true, then you may call get_string
).
Implementation note: Variant is defined entirely in this header file.
enum Type |
This enumeration defines the different types of data that can be represented by this Variant.
For example, a Variant instance may represent a simple integer, or a simple string. However, it might also be an OID, or a null value. In addition, there are some SNMP-specific things (such as IP address, or timeticks) that it can be.
|
inline |
Destructor; all memory is freed.
Since the Variant internally uses a union with non-trivial components, their destructors will need to be called manually.
|
inline |
This returns the 32-bit signed integer value of the Variant.
You should first check that this is the correct type by calling is_int32_t
.
InvalidTypeException | if the Variant is not of this format. |
|
inline |
This returns the OID value of the Variant.
You should first check that this is the correct type by calling is_oid
.
InvalidTypeException | if the Variant is not of this format. |
|
inline |
This returns the string value of the Variant.
You should first check that this is the correct type by calling is_string
.
InvalidTypeException | if the Variant is not of this format. |
|
inline |
This returns the 32-bit unsigned integer value of the Variant.
You should first check that this is the correct type by calling is_uint32_t
.
InvalidTypeException | if the Variant is not of this format. |
|
inline |
This returns the 64-bit unsigned integer value of the Variant.
You should first check that this is the correct type by calling is_uint64_t
.
InvalidTypeException | if the Variant is not of this format. |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
This sets the value to a signed, 32-bit integer.
type | The new type for the Variant. This may be SIMPLE_INTEGER. |
i32 | The signed, 32-bit integer. |
InvalidTypeException | if type is not one of the allowed types. |
|
inline |
This restores the Variant to its default, null state.
Note: this will be called internally to clear out the string and OID data when the type of the Variant is reassigned.
type | The new type for the Variant. This may be SIMPLE_NULL, CONTEXT_NOSUCHOBJECT, CONTEXT_NOSUCHINSTANCE, or CONTEXT_ENDOFMIBVIEW. |
InvalidTypeException | if type is not one of the allowed types. |
|
inline |
This sets the value to an OID.
type | The new type for the Variant. This may be SIMPLE_OID. |
oid | The string. |
InvalidTypeException | if type is not one of the allowed types. |
|
inline |
This sets the value to a string.
type | The new type for the Variant. This may be SIMPLE_STRING. |
string | The signed integer. |
InvalidTypeException | if type is not one of the allowed types. |
|
inline |
This sets the value to an unsigned, 32-bit integer.
type | The new type for the Variant. This may be APPLICATION_COUNTER32, APPLICATION_GAUGE32, or APPLICATION_TIMETICKS. |
u32 | The unsigned, 32-bit integer. |
InvalidTypeException | if type is not one of the allowed types. |
|
inline |
This sets the value to an unsigned, 64-bit integer.
type | The new type for the Variant. This may be APPLICATION_COUNTER64. |
u64 | The unsigned, 64-bit integer. |
InvalidTypeException | if type is not one of the allowed types. |
|
inline |
This returns the type of the Variant.