<< Back to man.ChinaUnix.net

12.  Counter32 Class

Object Modeling Technique (OMT) view of the SNMP++ Counter32 Class

12.1.  The Counter32 Class

The SNMP++ Counter class provides benefits where SMI 32 bit counters are needed. SMI counter are defined with the storage capabilities of an unsigned long integer. In addition to being an unsigned long integers, SMI counters are treated as a distinct type. For this reason, the SNMP++ Counter32 class has all the functionality and behavior of an unsigned long int, but is a separate class. Anything that can be done with an unsigned long int can be done with a Counter32 object. The Counter32 class has additional behavior when interfacing with other SNMP++ classes like the Vb class. When used with the Vb class, Counter32 objects can be set into ( Vb::set) and gotten out of ( Vb::get) of Vb objects. This allows the developer to get all the functionality of unsigned long and provide a one-to-one mapping to SMI counter.


12.2. Overview of Counter32 Class Member Functions

Counter32 Class Member Functions




     Counter32::Counter32( void);

Constructs an empty Counter32 object.

     Counter32::Counter32( const unsigned long i );

Construct a Counter32 object using an unsigned long.

     Counter32::Counter32(  const Counter32 &c);

Construct a Counter32 object using another Counter32 object.



     Counter32::~Counter32( );

Destroy a Counter32 object.

Overloaded Operators


     Counter32& operator = ( const Counter32& c);

Overloaded assignment operator.

     char * get_printable();

Returns Counter32 formatted for output.

     operator unsigned long( );

Gives unsigned long behavior.


12.3. Some Counter32 Class Examples


// Counter Examples

#include counter.h

void counter_example()


    Counter32 ctr;                                     // create an un-initialized counter instance

    Counter32 ctr1( (unsigned long) 57);           // create a counter using a number

    Counter32 ctr2(ctr1);                                 // create a counter using another instance


    ctr = 192;                                                     // overloaded assignment to a number

    ctr1 = ctr;                                               // overloaded assignment to another counter

    cout << (unsigned long) ctr;                       // behave like an unsigned long int



};  // end counter example