<< Back to man.lupaworld.com

14.  Counter64 Class

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


14.1.  The Counter64 Class

The SNMP++ 64bit counter class allows for the usage of SMI 64 bit counters. 64 bit counters are defined as a SNMP version 2 SMI variable. So, for SNMP version 1, this MIB variable does not exist. The Counter64 class allows for easy usage of 64 bit counters which are made up of two unsigned long portions ( high and low). The Counter64 class provides overloaded operators for addition, subtraction, multiplication and division, giving  the Counter64 class a natural feel.

 

14.2. Overview of Counter64 Class Member Functions

 

 

Counter64 Class Member Functions

Description

Constructors

 

     Counter64::Counter64( void);

Construct a Counter64 with no data.

     Counter64::Counter64(  const unsigned long hi, const unsigned

                                            long low );

Construct a Counter64 with two unsigned long ints.

     Counter64::Counter64( const Counter64 &ctr64);

Copy Constructor.

     Counter64::Counter64( const unsigned long ul);

Construct a Counter64 with a single unsigned long.

Destructor

Destroy an OctetStr object

     Counter64::~Counter64( );

 


14.3. Overview of Counter64Class Member Functions Continued

 

 Counter64 Class Member Functions

Description

Overloaded Operators

 

     Counter64& operator = ( const Counter64 &ctr64);

Assign a Counter64 to a Counter64.

     Counter64& operator = ( const unsigned long i );

Assign a Counter64 an unsigned long, sets low, clears high.

     Counter64 operator + ( const Counter64 &ctr64);

Add two Counter64’s.

     Counter64 operator - ( const Counter64 &ctr64);

Subtract two Counter64’s.

     Counter64 operator * ( const Counter64 &ctr64);

Multiply two Counter64’s.

     Counter64 operator / ( const Counter64 &ctr64);

Divide two Counter64’s.

     int operator == ( Counter64 &lhs, Counter64 &rhs);

Test if two Counter64’s are equal.

     int operator != ( Counter64 &lhs, Counter64 &rhs);

Test if two Counter64’s are not equal.

     int operator < ( Counter64 &lhs, Counter64 &rhs);

Test if one Counter64 is less than another Counter64.

     int operator <= ( Counter64 &lhs, Counter64 &rhs);

Test if one Counter64 is less or equal to than another Counter64.

     int operator > ( Counter64 &lhs, Counter64 &rhs);

Test if one Counter64 is greater than another Counter64

     int operator >= ( Counter64 &lhs, Counter64 &rhs);

Test if one Counter64 is greater than or equal to than another Counter64.

Member Functions

 

     unsigned long high();

Returns high portion.

     unsigned long low();

Returns low portion.

     void set_high();

Sets the high portion.

     void set_low();

Sets the low portion.


 

14.4. Some Counter64 Class Examples

// Counter64 examples

#include “ctr64.h”

void counter64_example()

{

   Counter64 c64;                            // instantiate a 64 bit counter object with no parms

   Counter64 my_c64( 100, 100);       // instantiate a 64 bit counter with a hi and low value

   Counter64 your_c64( my_c64);      // instantiate a 64 counter using another 64bit counter

 

   cout << my_c64.high();            // print out the high portion of the c64

   cout << my_c64.low();             // print out the low portion of the c64

 

   c64 = my_c64 + your_c64;           // overloaded addition

   c64 = my_c64 * your_c64;            // overloaded multiplication

   c64 = my_c64 / your_c64;           // overloaded division

   c64 = my_c64 - your_c64;           // overloaded subtraction

 

    if ( c64 == my_c64)                     // overloaded equivalence test

      cout << “c64 equals my_c64\n”;

 

    if ( c64 != my_c64)                // overloaded not equal test

      cout << “c64 not equal to my_c64\n”;

 

   if ( c64 < my_c64)                 // overloaded less than

      cout << “c64 less than my_c64\n”;

 

}; // end Counter64 example