1 /*_############################################################################
6 _## -----------------------------------------------
7 _## Copyright (c) 2001-2010 Jochen Katz, Frank Fock
9 _## This software is based on SNMP++2.6 from Hewlett Packard:
11 _## Copyright (c) 1996
12 _## Hewlett-Packard Company
14 _## ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.
15 _## Permission to use, copy, modify, distribute and/or sell this software
16 _## and/or its documentation is hereby granted without fee. User agrees
17 _## to display the above copyright notice and this license notice in all
18 _## copies of the software and any documentation of the software. User
19 _## agrees to assume all liability for the use of the software;
20 _## Hewlett-Packard and Jochen Katz make no representations about the
21 _## suitability of this software for any purpose. It is provided
22 _## "AS-IS" without warranty of any kind, either express or implied. User
23 _## hereby grants a royalty-free license to any and all derivatives based
24 _## upon this software code base.
26 _## Stuttgart, Germany, Thu Sep 2 00:07:47 CEST 2010
28 _##########################################################################*/
29 /*===================================================================
32 Hewlett-Packard Company
34 ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.
35 Permission to use, copy, modify, distribute and/or sell this software
36 and/or its documentation is hereby granted without fee. User agrees
37 to display the above copyright notice and this license notice in all
38 copies of the software and any documentation of the software. User
39 agrees to assume all liability for the use of the software; Hewlett-Packard
40 makes no representations about the suitability of this software for any
41 purpose. It is provided "AS-IS without warranty of any kind,either express
42 or implied. User hereby grants a royalty-free license to any and all
43 derivatives based upon this software code base.
46 SNMP++ C O U N T E R 6 4 . H
48 COUNTER64 CLASSES DEFINITION
50 DESIGN + AUTHOR: Peter E Mellquist
52 DESCRIPTION: SNMP Counter64 class definition.
54 =====================================================================*/
55 // $Id: ctr64.h 1558 2009-07-03 20:16:53Z katz $
60 #include "snmp_pp/smival.h"
62 #ifdef SNMP_PP_NAMESPACE
66 #define CTR64OUTBUF 30 //!< maximum ascii string for a 64-bit counter
68 //---------[ 64 bit Counter Class ]--------------------------------
70 * Counter64 Class encapsulates two unsigned integers into a
71 * a single entity. This type has is available in SNMPv2 but
72 * may be used anywhere where needed.
74 class DLLOPT Counter64: public SnmpSyntax
78 //-----------[ Constructors and Destrucotr ]----------------------
81 * Constructs a valid Couter64 with value 0.
86 * Constructs a valid Counter64 with the given value as the lower 32 bits.
88 * @param lo - value (0..MAX_UINT32)
90 Counter64(unsigned long lo);
93 * Constructs a valid Counter64 with the given values.
95 * @param hi - value for the high 32 bits (0..MAX_UINT32)
96 * @param lo - value for the low 32 bits (0..MAX_UINT32)
98 Counter64(unsigned long hi, unsigned long lo);
103 * @param ctr64 - value
105 Counter64(const Counter64 &ctr64);
108 * Destructor (ensure that SnmpSyntax::~SnmpSyntax() is overridden).
112 //-----------[ conversion from/to unsigned long long ]----------------
115 * Get the value of the object as 64 bit integer.
117 * @param c64 - The Counter64 object whose value should be returned
118 * @return value as a unsigned 64 bit integer
120 static pp_uint64 c64_to_ll(const Counter64 &c64);
123 * Get the value of this object as 64 bit integer.
125 * @return value as a unsigned 64 bit integer
127 pp_uint64 c64_to_ll() const;
130 * Convert a 64 bit integer to a Counter64.
132 * @param ld - the value to convert
133 * @return A Counter64 object with the value of the param ld.
135 static Counter64 ll_to_c64(const pp_uint64 &ll);
137 //-----------[ get/set using 32 bit variables ]----------------------
140 * Get the high 32 bit part.
142 * @return The high part of the Counter64
144 unsigned long high() const { return smival.value.hNumber.hipart; };
147 * Get the low 32 bit part.
149 * @return The low part of the Counter64
151 unsigned long low() const { return smival.value.hNumber.lopart; };
154 * Set the high 32 bit part. The low part will stay unchanged.
156 * @param h - The new high part of the Counter64
158 void set_high(const unsigned long h)
159 { smival.value.hNumber.hipart = h; m_changed = true; };
162 * Set the low 32 bit part. The high part will stay unchanged.
164 * @param l - The new low part of the Counter64
166 void set_low(const unsigned long l)
167 { smival.value.hNumber.lopart = l; m_changed = true; };
170 //-----------[ SnmpSyntax methods ]----------------------
173 * Get a printable ASCII string representing the current value.
175 * @note The returned string is valid as long as the object is not
178 * @return Null terminated string.
180 const char *get_printable() const;
183 * Get the Syntax of the object.
185 * @return This method always returns sNMP_SYNTAX_CNTR64.
187 SmiUINT32 get_syntax() const { return sNMP_SYNTAX_CNTR64; };
192 * @return A cloned Counter64 object allocated through new.
194 SnmpSyntax *clone() const { return (SnmpSyntax *) new Counter64(*this); };
197 * Overloaded assignement operator.
199 * @param val - Try to map the given value to a Counter64 and assign it
200 * @return Always *this with the new value.
202 SnmpSyntax& operator=(const SnmpSyntax &val);
205 * Return validity of the object.
207 * @return Always true
209 bool valid() const { return true; };
212 * Return the space needed for serialization.
214 * @return The needed space that depends on the current value.
216 int get_asn1_length() const;
222 { smival.value.hNumber.hipart = 0; smival.value.hNumber.lopart = 0;
225 //-----------[ overloaded operators ]----------------------
228 * Assign a Counter64 to a Counter64.
230 Counter64& operator=(const Counter64 &ctr64);
233 * Assign a unsigned long to a Counter64.
235 * @param i - The new low part. The high part is cleared.
237 Counter64& operator=(const unsigned long i);
242 Counter64 operator+(const Counter64 &c) const;
245 * Add a unsigned long and a Counter64.
247 DLLOPT friend Counter64 operator+(unsigned long ul, const Counter64 &c64)
248 { return Counter64(ul) + c64; };
251 * Subtract two Counter64.
253 Counter64 operator-(const Counter64 &c) const;
256 * Subtract a unsigned long and a Counter64.
258 DLLOPT friend Counter64 operator-(unsigned long ul, const Counter64 &c64)
259 { return Counter64(ul) - c64; };
262 * Multiply two Counter64.
264 Counter64 operator*(const Counter64 &c) const;
267 * Multiply a unsigned long and a Counter64.
269 DLLOPT friend Counter64 operator*(unsigned long ul, const Counter64 &c64)
270 { return Counter64(ul) * c64; };
273 * Divide two Counter64.
275 Counter64 operator/(const Counter64 &c) const;
278 * Divide a unsigned long and a Counter64.
280 DLLOPT friend Counter64 operator/(unsigned long ul, const Counter64 &c64)
281 { return Counter64(ul) / c64; };
283 //-------[ overloaded comparison operators ]--------------
286 * Equal operator for two Cunter64.
288 DLLOPT friend bool operator==(const Counter64 &lhs, const Counter64 &rhs);
291 * Not equal operator for two Cunter64.
293 DLLOPT friend bool operator!=(const Counter64 &lhs, const Counter64 &rhs);
296 * Less than operator for two Cunter64.
298 DLLOPT friend bool operator<(const Counter64 &lhs, const Counter64 &rhs);
301 * Less than or equal operator for two Cunter64.
303 DLLOPT friend bool operator<=(const Counter64 &lhs, const Counter64 &rhs);
306 * Greater than operator for two Cunter64.
308 DLLOPT friend bool operator>(const Counter64 &lhs, const Counter64 &rhs);
311 * Greater than or equal operator for two Cunter64.
313 DLLOPT friend bool operator>=(const Counter64 &lhs, const Counter64 &rhs);
317 SNMP_PP_MUTABLE char output_buffer[CTR64OUTBUF];
318 SNMP_PP_MUTABLE bool m_changed;
321 #ifdef SNMP_PP_NAMESPACE
322 } // end of namespace Snmp_pp