]> git.stg.codes - ssmd.git/blob - 3rdparty/snmp++/include/snmp_pp/ctr64.h
Initial adding
[ssmd.git] / 3rdparty / snmp++ / include / snmp_pp / ctr64.h
1 /*_############################################################################
2   _## 
3   _##  ctr64.h  
4   _##
5   _##  SNMP++v3.2.25
6   _##  -----------------------------------------------
7   _##  Copyright (c) 2001-2010 Jochen Katz, Frank Fock
8   _##
9   _##  This software is based on SNMP++2.6 from Hewlett Packard:
10   _##  
11   _##    Copyright (c) 1996
12   _##    Hewlett-Packard Company
13   _##  
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. 
25   _##  
26   _##  Stuttgart, Germany, Thu Sep  2 00:07:47 CEST 2010 
27   _##  
28   _##########################################################################*/
29 /*===================================================================
30
31   Copyright (c) 1999
32   Hewlett-Packard Company
33
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.
44
45                 
46   SNMP++ C O U N T E R 6 4 . H
47
48   COUNTER64 CLASSES DEFINITION
49
50   DESIGN + AUTHOR:    Peter E Mellquist
51
52   DESCRIPTION:        SNMP Counter64 class definition.
53
54 =====================================================================*/
55 // $Id: ctr64.h 1558 2009-07-03 20:16:53Z katz $
56
57 #ifndef _CTR64
58 #define _CTR64
59
60 #include "snmp_pp/smival.h"
61
62 #ifdef SNMP_PP_NAMESPACE
63 namespace Snmp_pp {
64 #endif
65
66 #define CTR64OUTBUF 30  //!< maximum ascii string for a 64-bit counter
67
68 //---------[ 64 bit Counter Class ]--------------------------------
69 /**
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.
73  */
74 class DLLOPT Counter64: public  SnmpSyntax
75 {
76  public:
77
78   //-----------[ Constructors and Destrucotr ]----------------------
79
80   /**
81    * Constructs a valid Couter64 with value 0.
82    */
83   Counter64();
84
85   /**
86    * Constructs a valid Counter64 with the given value as the lower 32 bits.
87    *
88    * @param lo - value (0..MAX_UINT32)
89    */
90   Counter64(unsigned long lo);
91
92   /**
93    * Constructs a valid Counter64 with the given values.
94    *
95    * @param hi - value for the high 32 bits (0..MAX_UINT32)
96    * @param lo - value for the low  32 bits (0..MAX_UINT32)
97    */
98   Counter64(unsigned long hi, unsigned long lo);
99
100   /**
101    * Copy constructor.
102    *
103    * @param ctr64 - value
104    */
105   Counter64(const Counter64 &ctr64);
106
107   /**
108    * Destructor (ensure that SnmpSyntax::~SnmpSyntax() is overridden).
109    */
110   ~Counter64() {};
111
112   //-----------[ conversion from/to unsigned long long ]----------------
113
114   /**
115    * Get the value of the object as 64 bit integer.
116    *
117    * @param c64 - The Counter64 object whose value should be returned
118    * @return value as a unsigned 64 bit integer
119    */
120   static pp_uint64 c64_to_ll(const Counter64 &c64);
121
122   /**
123    * Get the value of this object as 64 bit integer.
124    *
125    * @return value as a unsigned 64 bit integer
126    */
127   pp_uint64 c64_to_ll() const;
128
129   /**
130    * Convert a 64 bit integer to a Counter64.
131    *
132    * @param ld - the value to convert
133    * @return A Counter64 object with the value of the param ld.
134    */
135   static Counter64 ll_to_c64(const pp_uint64 &ll);
136
137   //-----------[ get/set using 32 bit variables ]----------------------
138
139   /**
140    * Get the high 32 bit part.
141    *
142    * @return The high part of the Counter64
143    */
144   unsigned long high() const { return smival.value.hNumber.hipart; };
145
146   /**
147    * Get the low 32 bit part.
148    *
149    * @return The low part of the Counter64
150    */
151   unsigned long low() const { return smival.value.hNumber.lopart; };
152
153   /**
154    * Set the high 32 bit part. The low part will stay unchanged.
155    *
156    * @param h - The new high part of the Counter64
157    */
158   void set_high(const unsigned long h)
159     { smival.value.hNumber.hipart = h; m_changed = true; };
160
161   /**
162    * Set the low 32 bit part. The high part will stay unchanged.
163    *
164    * @param l - The new low part of the Counter64
165    */
166   void set_low(const unsigned long l)
167     { smival.value.hNumber.lopart = l; m_changed = true; };
168
169
170   //-----------[ SnmpSyntax methods ]----------------------
171
172   /**
173    * Get a printable ASCII string representing the current value.
174    *
175    * @note The returned string is valid as long as the object is not
176    *       modified.
177    *
178    * @return Null terminated string.
179    */
180   const char *get_printable() const;
181
182   /**
183    * Get the Syntax of the object.
184    *
185    * @return This method always returns sNMP_SYNTAX_CNTR64.
186    */
187   SmiUINT32 get_syntax() const { return sNMP_SYNTAX_CNTR64; };
188
189   /**
190    * Clone the object.
191    *
192    * @return A cloned Counter64 object allocated through new.
193    */
194   SnmpSyntax *clone() const { return (SnmpSyntax *) new Counter64(*this); };
195
196   /**
197    * Overloaded assignement operator.
198    *
199    * @param val - Try to map the given value to a Counter64 and assign it
200    * @return Always *this with the new value.
201    */
202   SnmpSyntax& operator=(const SnmpSyntax &val);
203
204   /**
205    * Return validity of the object.
206    *
207    * @return Always true
208    */
209   bool valid() const { return true; };
210
211   /**
212    * Return the space needed for serialization.
213    *
214    * @return The needed space that depends on the current value.
215    */
216   int get_asn1_length() const;
217
218   /**
219    * Reset the object.
220    */
221   void clear()
222     { smival.value.hNumber.hipart = 0; smival.value.hNumber.lopart = 0;
223       m_changed = true; };
224   
225   //-----------[ overloaded operators ]----------------------
226
227   /**
228    * Assign a Counter64 to a Counter64.
229    */
230   Counter64& operator=(const Counter64 &ctr64);
231
232   /**
233    * Assign a unsigned long to a Counter64.
234    *
235    * @param i - The new low part. The high part is cleared.
236    */
237   Counter64& operator=(const unsigned long i);
238
239   /**
240    * Add two Counter64.
241    */
242   Counter64 operator+(const Counter64 &c) const;
243
244   /**
245    * Add a unsigned long and a Counter64.
246    */
247   DLLOPT friend Counter64 operator+(unsigned long ul, const Counter64 &c64)
248     { return Counter64(ul) + c64; };
249
250   /**
251    * Subtract two Counter64.
252    */
253   Counter64 operator-(const Counter64 &c) const;
254
255   /**
256    * Subtract a unsigned long and a Counter64.
257    */
258   DLLOPT friend Counter64 operator-(unsigned long ul, const Counter64 &c64)
259     { return Counter64(ul) - c64; };
260
261   /**
262    * Multiply two Counter64.
263    */
264   Counter64 operator*(const Counter64 &c) const;
265
266   /**
267    * Multiply a unsigned long and a Counter64.
268    */
269   DLLOPT friend Counter64 operator*(unsigned long ul, const Counter64 &c64)
270     { return Counter64(ul) * c64; };
271
272   /**
273    * Divide two Counter64.
274    */
275   Counter64 operator/(const Counter64 &c) const;
276
277   /**
278    * Divide a unsigned long and a Counter64.
279    */
280   DLLOPT friend Counter64 operator/(unsigned long ul, const Counter64 &c64)
281     { return Counter64(ul) / c64; };
282
283   //-------[ overloaded comparison operators ]--------------
284
285   /**
286    * Equal operator for two Cunter64.
287    */
288   DLLOPT friend bool operator==(const Counter64 &lhs, const Counter64 &rhs);
289
290   /**
291    * Not equal operator for two Cunter64.
292    */
293   DLLOPT friend bool operator!=(const Counter64 &lhs, const Counter64 &rhs);
294
295   /**
296    * Less than operator for two Cunter64.
297    */
298   DLLOPT friend bool operator<(const Counter64 &lhs, const Counter64 &rhs);
299
300   /**
301    * Less than or equal operator for two Cunter64.
302    */
303   DLLOPT friend bool operator<=(const Counter64 &lhs, const Counter64 &rhs);
304
305   /**
306    * Greater than operator for two Cunter64.
307    */
308   DLLOPT friend bool operator>(const Counter64 &lhs, const Counter64 &rhs);
309
310   /**
311    * Greater than or equal operator for two Cunter64.
312    */
313   DLLOPT friend bool operator>=(const Counter64 &lhs, const Counter64 &rhs);
314
315  private:
316
317   SNMP_PP_MUTABLE char output_buffer[CTR64OUTBUF];
318   SNMP_PP_MUTABLE bool m_changed;
319 };
320
321 #ifdef SNMP_PP_NAMESPACE
322 } // end of namespace Snmp_pp
323 #endif 
324
325 #endif