SNMP++  3.3.4
OctetStr Class Reference

#include <octet.h>

Inheritance diagram for OctetStr:
Collaboration diagram for OctetStr:

Public Types

enum  OutputType { OutputHexAndClear, OutputHex, OutputClear }
 Enum for setting the hex output format. More...
 

Public Member Functions

 OctetStr ()
 Constructs a valid OctetStr with zero length. More...
 
 OctetStr (const char *str)
 Constructs a OctetStr with the given value. More...
 
 OctetStr (const unsigned char *str, unsigned long len)
 Constructs a OctetStr with the given value. More...
 
 OctetStr (const OctetStr &octet)
 Construct a OctetStr from another OctetStr. More...
 
 ~OctetStr ()
 Destructor, frees allocated space. More...
 
OctetStroperator= (const char *str)
 Assign a char string to a OctetStr. More...
 
OctetStroperator= (const OctetStr &octet)
 Assign a OctetStr to a OctetStr. More...
 
OctetStroperator+= (const char *a)
 Append a char string to this OctetStr. More...
 
OctetStroperator+= (const unsigned char c)
 Append a single char to this OctetStr. More...
 
OctetStroperator+= (const OctetStr &octet)
 Append another OctetStr to this OctetStr. More...
 
unsigned char & operator[] (int i)
 Allow access as if it was an array. More...
 
unsigned char operator[] (int i) const
 Allow access as if it was an array for const OctetStr objects. More...
 
SmiUINT32 get_syntax () const
 Return the syntax. More...
 
int get_asn1_length () const
 Return the space needed for serialization. More...
 
bool valid () const
 Return validity of the object. More...
 
SnmpSyntaxclone () const
 Clone this object. More...
 
SnmpSyntaxoperator= (const SnmpSyntax &val)
 Map other SnmpSyntax objects to OctetStr. More...
 
const char * get_printable () const
 Get a printable ASCII value of the string. More...
 
const char * get_printable_hex () const
 Get an ASCII formatted hex dump of the contents. More...
 
const char * get_printable_clear () const
 Get the contents with all non printable characters replaced. More...
 
void set_data (const unsigned char *str, unsigned long len)
 Set the data on an already constructed OctetStr. More...
 
unsigned long len () const
 Get the length of the string. More...
 
unsigned char * data () const
 Get a pointer to internal data. More...
 
int nCompare (const unsigned long n, const OctetStr &o) const
 
void clear ()
 Null out the contents of the string. More...
 
bool set_len (const unsigned long new_len)
 Append or shorten the internal data buffer. More...
 
- Public Member Functions inherited from SnmpSyntax
virtual ~SnmpSyntax ()
 Virtual destructor to ensure deletion of derived classes... More...
 

Static Public Member Functions

static void set_hex_output_type (const enum OutputType ot)
 Set the output format for get_pritable_hex(). More...
 
static void set_np_char (const char np)
 Set the char get_printable_hex() and get_printable_clear() will use for non printable characters. More...
 
static OctetStr from_hex_string (const OctetStr &hex_string)
 Build an OctetStr from a hex string. More...
 
static bool set_linefeed_chars (const char *lf_chars)
 Set the character for linefeeds in get_printable() functions. More...
 

Protected Types

enum  OutputFunction { OutputFunctionDefault, OutputFunctionHex, OutputFunctionClear }
 

Protected Attributes

SNMP_PP_MUTABLE char * output_buffer
 
SNMP_PP_MUTABLE unsigned int output_buffer_len
 
SNMP_PP_MUTABLE bool m_changed
 
SNMP_PP_MUTABLE enum OutputType output_last_type
 
SNMP_PP_MUTABLE char output_last_np_char
 
SNMP_PP_MUTABLE enum OutputFunction output_last_function
 
bool validity
 
- Protected Attributes inherited from SnmpSyntax
SmiVALUE smival
 

Static Protected Attributes

static enum OutputType hex_output_type
 
static char nonprintable_char
 
static char linefeed_chars [3]
 

Friends

DLLOPT friend int operator== (const OctetStr &lhs, const OctetStr &rhs)
 Equal operator for two OctetStr. More...
 
DLLOPT friend int operator!= (const OctetStr &lhs, const OctetStr &rhs)
 Not equal operator for two OctetStr. More...
 
DLLOPT friend int operator< (const OctetStr &lhs, const OctetStr &rhs)
 Not equal operator for two OctetStr. More...
 
DLLOPT friend int operator<= (const OctetStr &lhs, const OctetStr &rhs)
 Less than operator for two OctetStr. More...
 
DLLOPT friend int operator> (const OctetStr &lhs, const OctetStr &rhs)
 Greater than operator for two OctetStr. More...
 
DLLOPT friend int operator>= (const OctetStr &lhs, const OctetStr &rhs)
 Greater than or equal operator for two OctetStr. More...
 
DLLOPT friend int operator== (const OctetStr &lhs, const char *rhs)
 Equal operator for OctetStr and char string. More...
 
DLLOPT friend int operator!= (const OctetStr &lhs, const char *rhs)
 Not equal operator for OctetStr and char string. More...
 
DLLOPT friend int operator< (const OctetStr &lhs, const char *rhs)
 Less than operator for OctetStr and char string. More...
 
DLLOPT friend int operator<= (const OctetStr &lhs, const char *rhs)
 Less than or equal operator for OctetStr and char string. More...
 
DLLOPT friend int operator> (const OctetStr &lhs, const char *rhs)
 Greater than operator for OctetStr and char string. More...
 
DLLOPT friend int operator>= (const OctetStr &lhs, const char *rhs)
 Greater than or equal operator for OctetStr and char string. More...
 

Additional Inherited Members

- Protected Member Functions inherited from SnmpSyntax
 SnmpSyntax ()
 

Detailed Description

Definition at line 67 of file octet.h.

Member Enumeration Documentation

enum OctetStr::OutputFunction
protected
Enumerator
OutputFunctionDefault 
OutputFunctionHex 
OutputFunctionClear 

Definition at line 359 of file octet.h.

Enum for setting the hex output format.

Enumerator
OutputHexAndClear 
OutputHex 
OutputClear 

Definition at line 74 of file octet.h.

Constructor & Destructor Documentation

OctetStr::OctetStr ( )

Constructs a valid OctetStr with zero length.

OctetStr::OctetStr ( const char *  str)

Constructs a OctetStr with the given value.

The OctetStr will be valid unless a call to new fails.

Parameters
str- Null terminated string
OctetStr::OctetStr ( const unsigned char *  str,
unsigned long  len 
)

Constructs a OctetStr with the given value.

The OctetStr will be valid unless a call to new fails.

Parameters
str- string that may contain null bytes
len- length of the string
OctetStr::OctetStr ( const OctetStr octet)

Construct a OctetStr from another OctetStr.

The OctetStr will be valid unless a call to new fails.

Parameters
octet- Value for the new object
OctetStr::~OctetStr ( )

Destructor, frees allocated space.

Member Function Documentation

void OctetStr::clear ( )
virtual

Null out the contents of the string.

The string will be empty after calling this method

Implements SnmpSyntax.

SnmpSyntax* OctetStr::clone ( ) const
inlinevirtual

Clone this object.

Returns
Pointer to the newly created object (allocated through new).

Implements SnmpSyntax.

Reimplemented in OpaqueStr.

Definition at line 242 of file octet.h.

unsigned char* OctetStr::data ( ) const
inline

Get a pointer to internal data.

Definition at line 315 of file octet.h.

static OctetStr OctetStr::from_hex_string ( const OctetStr hex_string)
static

Build an OctetStr from a hex string.

Called with "5465 737469 6e672074686973206D657468 6f 64 21" the returned value will be "Testing this method!"

Parameters
hex_string- The hex string (may contain spaces)
Returns
created string
int OctetStr::get_asn1_length ( ) const
virtual

Return the space needed for serialization.

Implements SnmpSyntax.

const char* OctetStr::get_printable ( ) const
virtual

Get a printable ASCII value of the string.

Note
Depending on the selected output format, this method will return get_printable_hex() or get_printable_clear() if the string contains not printable characters.
Returns
Printable, null terminated string

Implements SnmpSyntax.

const char* OctetStr::get_printable_clear ( ) const

Get the contents with all non printable characters replaced.

Returns
Printable, null terminated string.
const char* OctetStr::get_printable_hex ( ) const

Get an ASCII formatted hex dump of the contents.

If the output format was set to OctetStr::OutputHexAndClear, the produced string of this method will look like this:

09 4F 63 74 65 74 53 74 72 3A 3A 67 65 74 5F 70    .OctetStr::get_p
72 69 6E 74 61 62 6C 65 5F 68 65 78 28 29          rintable_hex()
                                                                    

If the output format was set to OctetStr::OutputHex the produced string will look like this:

09 4F 63 74 65 74 53 74 72 3A 3A 67 65 74 5F 70
72 69 6E 74 61 62 6C 65 5F 68 65 78 28 29
                                                                    
Returns
Printable, null terminated string.
SmiUINT32 OctetStr::get_syntax ( ) const
inlinevirtual

Return the syntax.

Returns
This method always returns sNMP_SYNTAX_OCTETS.

Implements SnmpSyntax.

Reimplemented in OpaqueStr.

Definition at line 225 of file octet.h.

References sNMP_SYNTAX_OCTETS.

unsigned long OctetStr::len ( ) const
inline

Get the length of the string.

Definition at line 310 of file octet.h.

int OctetStr::nCompare ( const unsigned long  n,
const OctetStr o 
) const
OctetStr& OctetStr::operator+= ( const char *  a)

Append a char string to this OctetStr.

OctetStr& OctetStr::operator+= ( const unsigned char  c)

Append a single char to this OctetStr.

OctetStr& OctetStr::operator+= ( const OctetStr octet)

Append another OctetStr to this OctetStr.

OctetStr& OctetStr::operator= ( const char *  str)

Assign a char string to a OctetStr.

Referenced by OpaqueStr::operator=().

OctetStr& OctetStr::operator= ( const OctetStr octet)

Assign a OctetStr to a OctetStr.

SnmpSyntax& OctetStr::operator= ( const SnmpSyntax val)
virtual

Map other SnmpSyntax objects to OctetStr.

Implements SnmpSyntax.

Reimplemented in OpaqueStr.

unsigned char& OctetStr::operator[] ( int  i)
inline

Allow access as if it was an array.

Note
The given param is not checked for validity.

Definition at line 210 of file octet.h.

unsigned char OctetStr::operator[] ( int  i) const
inline

Allow access as if it was an array for const OctetStr objects.

Note
The given param is not checked for validity.

Definition at line 218 of file octet.h.

void OctetStr::set_data ( const unsigned char *  str,
unsigned long  len 
)

Set the data on an already constructed OctetStr.

The given string is copied to an internal member var, so the params can be destroyed afterwards.

Parameters
str- The new string value
len- Length of the given string
static void OctetStr::set_hex_output_type ( const enum OutputType  ot)
inlinestatic

Set the output format for get_pritable_hex().

Definition at line 288 of file octet.h.

bool OctetStr::set_len ( const unsigned long  new_len)

Append or shorten the internal data buffer.

The buffer will either be shortened or extended. In the second case zeroes are added to the end of the string.

Parameters
new_len- The new length for the string
Returns
true on success
static bool OctetStr::set_linefeed_chars ( const char *  lf_chars)
static

Set the character for linefeeds in get_printable() functions.

The default linefeeds are
for Unix and
on other systems.

Parameters
lf_chars- string less than 3 bytes
Returns
true on success
static void OctetStr::set_np_char ( const char  np)
inlinestatic

Set the char get_printable_hex() and get_printable_clear() will use for non printable characters.

Definition at line 295 of file octet.h.

bool OctetStr::valid ( ) const
inlinevirtual

Return validity of the object.

Implements SnmpSyntax.

Definition at line 235 of file octet.h.

Referenced by Pdu::get_context_name(), and Pdu::set_context_name().

Friends And Related Function Documentation

DLLOPT friend int operator!= ( const OctetStr lhs,
const OctetStr rhs 
)
friend

Not equal operator for two OctetStr.

DLLOPT friend int operator!= ( const OctetStr lhs,
const char *  rhs 
)
friend

Not equal operator for OctetStr and char string.

DLLOPT friend int operator< ( const OctetStr lhs,
const OctetStr rhs 
)
friend

Not equal operator for two OctetStr.

DLLOPT friend int operator< ( const OctetStr lhs,
const char *  rhs 
)
friend

Less than operator for OctetStr and char string.

DLLOPT friend int operator<= ( const OctetStr lhs,
const OctetStr rhs 
)
friend

Less than operator for two OctetStr.

DLLOPT friend int operator<= ( const OctetStr lhs,
const char *  rhs 
)
friend

Less than or equal operator for OctetStr and char string.

DLLOPT friend int operator== ( const OctetStr lhs,
const OctetStr rhs 
)
friend

Equal operator for two OctetStr.

DLLOPT friend int operator== ( const OctetStr lhs,
const char *  rhs 
)
friend

Equal operator for OctetStr and char string.

DLLOPT friend int operator> ( const OctetStr lhs,
const OctetStr rhs 
)
friend

Greater than operator for two OctetStr.

DLLOPT friend int operator> ( const OctetStr lhs,
const char *  rhs 
)
friend

Greater than operator for OctetStr and char string.

DLLOPT friend int operator>= ( const OctetStr lhs,
const OctetStr rhs 
)
friend

Greater than or equal operator for two OctetStr.

DLLOPT friend int operator>= ( const OctetStr lhs,
const char *  rhs 
)
friend

Greater than or equal operator for OctetStr and char string.

Member Data Documentation

enum OutputType OctetStr::hex_output_type
staticprotected

Definition at line 376 of file octet.h.

char OctetStr::linefeed_chars[3]
staticprotected

Definition at line 378 of file octet.h.

SNMP_PP_MUTABLE bool OctetStr::m_changed
protected

Definition at line 368 of file octet.h.

char OctetStr::nonprintable_char
staticprotected

Definition at line 377 of file octet.h.

SNMP_PP_MUTABLE char* OctetStr::output_buffer
protected

Definition at line 366 of file octet.h.

SNMP_PP_MUTABLE unsigned int OctetStr::output_buffer_len
protected

Definition at line 367 of file octet.h.

SNMP_PP_MUTABLE enum OutputFunction OctetStr::output_last_function
protected

Definition at line 371 of file octet.h.

SNMP_PP_MUTABLE char OctetStr::output_last_np_char
protected

Definition at line 370 of file octet.h.

SNMP_PP_MUTABLE enum OutputType OctetStr::output_last_type
protected

Definition at line 369 of file octet.h.

bool OctetStr::validity
protected

Definition at line 374 of file octet.h.


The documentation for this class was generated from the following file: