SNMP++  3.3.4
Oid Class Reference

The Object Identifier Class. More...

#include <oid.h>

Inheritance diagram for Oid:
Collaboration diagram for Oid:

Public Member Functions

 Oid ()
 Construct an invalid Oid. More...
 
 Oid (const char *oid_string, const bool is_dotted_oid_string=true)
 Construct an Oid from a string. More...
 
 Oid (const Oid &oid)
 Constructor using another oid object (copy constructor). More...
 
 Oid (const unsigned long *raw_oid, int oid_len)
 Constructor from array. More...
 
virtual ~Oid ()
 Destructor. More...
 
SmiUINT32 get_syntax () const
 Return the current syntax. More...
 
virtual Oidoperator= (const char *dotted_oid_string)
 Assignment from a string. More...
 
virtual Oidoperator= (const Oid &oid)
 Assign one Oid to another. More...
 
int get_asn1_length () const
 Return the space needed for serialization. More...
 
bool operator== (const Oid &rhs) const
 Overloaded equal operator. More...
 
bool operator!= (const Oid &rhs) const
 Overloaded not equal operator. More...
 
bool operator< (const Oid &rhs) const
 Overloaded less than < operator. More...
 
bool operator<= (const Oid &rhs) const
 Overloaded less than <= operator. More...
 
bool operator> (const Oid &rhs) const
 Overloaded greater than > operator. More...
 
bool operator>= (const Oid &rhs) const
 Overloaded greater than >= operator. More...
 
Oidoperator+= (const char *a)
 Append operator, appends the dotted oid string. More...
 
Oidoperator+= (const unsigned long i)
 Appends an int. More...
 
Oidoperator+= (const Oid &o)
 Appends an Oid. More...
 
unsigned long & operator[] (const unsigned int index)
 Allows element access as an array. More...
 
unsigned long operator[] (const unsigned int index) const
 Allows element access as an array for const objects. More...
 
SmiLPOID oidval ()
 Get the WinSnmp oid part. More...
 
void set_data (const unsigned long *raw_oid, const unsigned int oid_len)
 Set the data from raw form. More...
 
void set_data (const char *str, const unsigned int str_len)
 Set the data from raw form. More...
 
unsigned long len () const
 Get the length of the oid. More...
 
void trim (const unsigned long n=1)
 Trim off the rightmost values of an oid. More...
 
int nCompare (const unsigned long n, const Oid &o) const
 Compare two Oids from the left in direction left-to-right. More...
 
int nCompare (const Oid &o) const
 Compare two Oids from the left in direction left-to-right. More...
 
bool valid () const
 Return validity of the object. More...
 
const char * get_printable () const
 Get a printable ASCII string of the whole value. More...
 
const char * get_printable (const unsigned long n) const
 Get a printable ASCII string of the right part of the value. More...
 
const char * get_printable (const unsigned long start, const unsigned long n, char *&buffer) const
 Get a printable ASCII string of a part of the value. More...
 
const char * get_printable (const unsigned long start, const unsigned long n) const
 Get a printable ASCII string of a part of the value. More...
 
SnmpSyntaxclone () const
 Clone this object. More...
 
SnmpSyntaxoperator= (const SnmpSyntax &val)
 Map other SnmpSyntax objects to Oid. More...
 
void clear ()
 Clear the Oid. More...
 
- Public Member Functions inherited from SnmpSyntax
virtual ~SnmpSyntax ()
 Virtual destructor to ensure deletion of derived classes... More...
 

Protected Member Functions

virtual int StrToOid (const char *string, SmiLPOID dstOid) const
 Convert a string to an smi oid. More...
 
virtual int OidCopy (SmiLPOID srcOid, SmiLPOID dstOid) const
 Clone an smi oid. More...
 
virtual int OidToStr (const SmiOID *srcOid, SmiUINT32 size, char *string) const
 Convert an smi oid to its string representation. More...
 
void delete_oid_ptr ()
 Free the internal oid pointer and set the pointer and the length to zero. More...
 
- Protected Member Functions inherited from SnmpSyntax
 SnmpSyntax ()
 

Protected Attributes

SNMP_PP_MUTABLE char * iv_str
 
SNMP_PP_MUTABLE char * iv_part_str
 
SNMP_PP_MUTABLE bool m_changed
 
- Protected Attributes inherited from SnmpSyntax
SmiVALUE smival
 

Friends

DLLOPT friend Oid operator+ (const Oid &lhs, const Oid &rhs)
 Overloaded operator +, Concatenate two Oids. More...
 

Detailed Description

The Object Identifier Class.

The Object Identification (Oid) class is the encapsulation of an SMI object identifier. The SMI object is a data identifier for a data element found in a Management Information Base (MIB), as defined by a MIB definition. The SMI Oid, its related structures and functions, are a natural fit for object orientation. In fact, the Oid class shares many common features to the C++ String class. For those of you familiar with the C++ String class or Microsoft's Foundation Classes (MFC) CString class, the Oid class will be familiar and easy to use. The Oid class is designed to be efficient and fast. The Oid class allows definition and manipulation of object identifiers.

Note
Oid holds two internal buffers for get_printable() functions. The buffer returned by get_printable() is valid until the Oid object is modified. The functions get_printable(len) and get_printable(start, len) share the same buffer which is freed and newly allocated for each call.

Definition at line 94 of file oid.h.

Constructor & Destructor Documentation

Oid::Oid ( )
inline

Construct an invalid Oid.

Definition at line 101 of file oid.h.

References sNMP_SYNTAX_OID.

Oid::Oid ( const char *  oid_string,
const bool  is_dotted_oid_string = true 
)

Construct an Oid from a string.

Depending on the second param, the oid_string can either be

  • a dotted oid string (like "1.3.6.1.6"). An arbitrary part of the oid can be given as a string value enclosed in '$' characters. For example the oid string "1.3.6.1.6.1.12.1.3.$public_0$" will result to the oid 1.3.6.1.6.1.12.1.3.112.117.98.108.105.99.95.48
  • a normal string (like "public"). The Oid will have the ASCII values of the string characters. So "public" will result to the oid 112.117.98.108.105.99
Parameters
oid_string- for example "1.3.1.6.1.10"
is_dotted_oid_string- Select format within oid_string
Oid::Oid ( const Oid oid)
inline

Constructor using another oid object (copy constructor).

Parameters
oid- Source Oid

Definition at line 134 of file oid.h.

References SmiOID::len, SmiVALUE::oid, SnmpSyntax::smival, sNMP_SYNTAX_OID, and SmiVALUE::value.

Oid::Oid ( const unsigned long *  raw_oid,
int  oid_len 
)
inline

Constructor from array.

Parameters
raw_oid- array of oid values
oid_len- length of array

Definition at line 159 of file oid.h.

References sNMP_SYNTAX_OID.

virtual Oid::~Oid ( )
inlinevirtual

Destructor.

Definition at line 183 of file oid.h.

Member Function Documentation

void Oid::clear ( )
inlinevirtual

Clear the Oid.

Implements SnmpSyntax.

Definition at line 647 of file oid.h.

SnmpSyntax* Oid::clone ( ) const
inlinevirtual

Clone this object.

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

Implements SnmpSyntax.

Definition at line 637 of file oid.h.

void Oid::delete_oid_ptr ( )
inlineprotected

Free the internal oid pointer and set the pointer and the length to zero.

Definition at line 707 of file oid.h.

int Oid::get_asn1_length ( ) const
virtual

Return the space needed for serialization.

Implements SnmpSyntax.

const char* Oid::get_printable ( ) const
inlinevirtual

Get a printable ASCII string of the whole value.

Returns
Dotted oid string (for example "1.3.6.1.6.0")

Implements SnmpSyntax.

Definition at line 590 of file oid.h.

const char* Oid::get_printable ( const unsigned long  n) const
inline

Get a printable ASCII string of the right part of the value.

Parameters
n- positions to print, counted from right.
Returns
Dotted oid string (for example "6.0")

Definition at line 600 of file oid.h.

const char* Oid::get_printable ( const unsigned long  start,
const unsigned long  n,
char *&  buffer 
) const

Get a printable ASCII string of a part of the value.

Parameters
start- First position to print, starting with 1 (not zero!)
n- positions to print.
buffer- pointer to the returned buffer
Note
If buffer is not NULL, this function calls "delete [] buffer", a new buffer is allocated using "new" and the caller has to delete it.
Returns
Dotted oid string (for example "3.6.1.6")
const char* Oid::get_printable ( const unsigned long  start,
const unsigned long  n 
) const
inline

Get a printable ASCII string of a part of the value.

Parameters
start- First position to print, starting with 1 (not zero!)
n- positions to print.
Returns
Dotted oid string (for example "3.6.1.6")

Definition at line 628 of file oid.h.

SmiUINT32 Oid::get_syntax ( ) const
inlinevirtual

Return the current syntax.

Returns
always sNMP_SYNTAX_OID

Implements SnmpSyntax.

Definition at line 195 of file oid.h.

References sNMP_SYNTAX_OID.

unsigned long Oid::len ( ) const
inline

Get the length of the oid.

Definition at line 463 of file oid.h.

Referenced by Pdu::get_notify_enterprise(), operator<(), operator==(), and Pdu::set_notify_enterprise().

int Oid::nCompare ( const unsigned long  n,
const Oid o 
) const
inline

Compare two Oids from the left in direction left-to-right.

Parameters
n- Subvalues to compare
o- The Oid to compare with
Returns
0 if equal / -1 if less / 1 if greater

Definition at line 490 of file oid.h.

References SmiOID::len, SmiVALUE::oid, SmiOID::ptr, SnmpSyntax::smival, and SmiVALUE::value.

int Oid::nCompare ( const Oid o) const
inline

Compare two Oids from the left in direction left-to-right.

Parameters
n- Subvalues to compare
o- The Oid to compare with
Returns
0 if equal / -1 if less / 1 if greater

Definition at line 540 of file oid.h.

References SmiOID::len, SmiVALUE::oid, SmiOID::ptr, SnmpSyntax::smival, and SmiVALUE::value.

virtual int Oid::OidCopy ( SmiLPOID  srcOid,
SmiLPOID  dstOid 
) const
inlineprotectedvirtual

Clone an smi oid.

Parameters
srcOid- source oid
dstOid- destination oid

Definition at line 664 of file oid.h.

References SmiOID::len, MEMCPY, and SmiOID::ptr.

virtual int Oid::OidToStr ( const SmiOID srcOid,
SmiUINT32  size,
char *  string 
) const
protectedvirtual

Convert an smi oid to its string representation.

Parameters
srcOid- source oid
size- size of string
string- pointer to string
SmiLPOID Oid::oidval ( )
inline

Get the WinSnmp oid part.

Note
This method returns a pointer to internal data. If it is modified, the Oid changes too.
Returns
pointer to the internal oid structure.

Definition at line 442 of file oid.h.

bool Oid::operator!= ( const Oid rhs) const
inline

Overloaded not equal operator.

Definition at line 243 of file oid.h.

Oid& Oid::operator+= ( const char *  a)

Append operator, appends the dotted oid string.

Parameters
a- dotted oid string, for example "5.192.14.6"
Oid& Oid::operator+= ( const unsigned long  i)
inline

Appends an int.

Parameters
i- Value to add at the end of the Oid

Definition at line 363 of file oid.h.

Oid& Oid::operator+= ( const Oid o)
inline

Appends an Oid.

Parameters
o- Oid to add at the end

Definition at line 375 of file oid.h.

References SmiOID::len, MEMCPY, SmiVALUE::oid, SmiOID::ptr, SnmpSyntax::smival, and SmiVALUE::value.

bool Oid::operator< ( const Oid rhs) const
inline

Overloaded less than < operator.

Definition at line 249 of file oid.h.

References len().

bool Oid::operator<= ( const Oid rhs) const
inline

Overloaded less than <= operator.

Definition at line 264 of file oid.h.

virtual Oid& Oid::operator= ( const char *  dotted_oid_string)
virtual

Assignment from a string.

Parameters
dotted_oid_string- New value (for example "1.3.6.1.6.0");
virtual Oid& Oid::operator= ( const Oid oid)
inlinevirtual

Assign one Oid to another.

Definition at line 207 of file oid.h.

References SmiOID::len, SmiVALUE::oid, SnmpSyntax::smival, and SmiVALUE::value.

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

Map other SnmpSyntax objects to Oid.

Implements SnmpSyntax.

bool Oid::operator== ( const Oid rhs) const
inline

Overloaded equal operator.

Definition at line 232 of file oid.h.

References len().

bool Oid::operator> ( const Oid rhs) const
inline

Overloaded greater than > operator.

Definition at line 270 of file oid.h.

bool Oid::operator>= ( const Oid rhs) const
inline

Overloaded greater than >= operator.

Definition at line 276 of file oid.h.

unsigned long& Oid::operator[] ( const unsigned int  index)
inline

Allows element access as an array.

This method behaves like real array: if your index is out of bounds, you're lost!

Parameters
index- valid index – 0 to (len() - 1)
Returns
Value on the given index

Definition at line 420 of file oid.h.

unsigned long Oid::operator[] ( const unsigned int  index) const
inline

Allows element access as an array for const objects.

This method behaves like real array: if your index is out of bounds, you're lost!

Parameters
index- valid index – 0 to (len() - 1)
Returns
Value on the given position

Definition at line 432 of file oid.h.

void Oid::set_data ( const unsigned long *  raw_oid,
const unsigned int  oid_len 
)

Set the data from raw form.

Parameters
raw_oid- Array of new values
oid_len- Length of the array raw_oid
void Oid::set_data ( const char *  str,
const unsigned int  str_len 
)

Set the data from raw form.

Parameters
str- Array of new values (a string)
str_len- Length of the array raw_oid
virtual int Oid::StrToOid ( const char *  string,
SmiLPOID  dstOid 
) const
protectedvirtual

Convert a string to an smi oid.

Parameters
string- input string
dstOid- destination oid
void Oid::trim ( const unsigned long  n = 1)
inline

Trim off the rightmost values of an oid.

Parameters
n- Trim off n values from the right (default is one)

Definition at line 470 of file oid.h.

bool Oid::valid ( ) const
inlinevirtual

Return validity of the object.

Implements SnmpSyntax.

Definition at line 583 of file oid.h.

Friends And Related Function Documentation

DLLOPT friend Oid operator+ ( const Oid lhs,
const Oid rhs 
)
friend

Overloaded operator +, Concatenate two Oids.

Definition at line 348 of file oid.h.

Member Data Documentation

SNMP_PP_MUTABLE char* Oid::iv_part_str
protected

Definition at line 698 of file oid.h.

SNMP_PP_MUTABLE char* Oid::iv_str
protected

Definition at line 697 of file oid.h.

SNMP_PP_MUTABLE bool Oid::m_changed
protected

Definition at line 699 of file oid.h.


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