]> git.stg.codes - ssmd.git/blob - 3rdparty/snmp++/include/snmp_pp/integer.h
Initial adding
[ssmd.git] / 3rdparty / snmp++ / include / snmp_pp / integer.h
1 /*_############################################################################
2   _## 
3   _##  integer.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++ I N T E G E R. H
47
48   INTEGER CLASS DEFINITION
49
50   DESIGN + AUTHOR:  Jeff Meyer
51
52   DESCRIPTION:
53   Class definition for Integer classes.
54
55 =====================================================================*/
56 // $Id: integer.h 1541 2009-05-29 11:29:22Z katz $
57
58 #ifndef _SNMPINTEGER
59 #define _SNMPINTEGER
60
61 #include "snmp_pp/smival.h"
62
63 #ifdef SNMP_PP_NAMESPACE
64 namespace Snmp_pp {
65 #endif
66
67 #define INTOUTBUF 15  // largest ASCII formatted integer
68
69 //------------[ Integer Classes ]------------------------------------------
70
71 /**
72  * 32 bit unsigned integer class.
73  *
74  * The integer class allows all the functionality of the various
75  * integers but is contained in a Value object for consistency
76  * among the various types.
77  * class objects may be set or get into Vb objects.
78  */
79 class DLLOPT SnmpUInt32 : public SnmpSyntax
80 {
81  public:
82
83   /**
84    * Constructor, sets value to zero.
85    */
86   SnmpUInt32();
87
88   /**
89    * Constructor with value.
90    *
91    * @param i - initial value
92    */
93   SnmpUInt32(const unsigned long i);
94
95   /**
96    * Copy constructor.
97    *
98    * @param c - initial value
99    */
100   SnmpUInt32(const SnmpUInt32 &c);
101
102   /**
103    * Destructor (ensure that SnmpSyntax::~SnmpSyntax() is overridden).
104    */
105   virtual ~SnmpUInt32() {};
106
107   /**
108    * Return the syntax.
109    *
110    * @return This method always returns sNMP_SYNTAX_UINT32.
111    */
112   virtual SmiUINT32 get_syntax() const { return sNMP_SYNTAX_UINT32; };
113
114   /**
115    * Overloaded assignment for unsigned longs.
116    *
117    * @param i - new value
118    * @return self reference
119    */
120   SnmpUInt32& operator=(const unsigned long i);
121
122   /**
123    * Overloaded assignment for SnmpUInt32.
124    *
125    * @param uli - new value
126    * @return self reference
127    */
128   SnmpUInt32& operator=(const SnmpUInt32 &uli);
129
130   /**
131    * Map other SnmpSyntax objects to SnmpUInt32.
132    */
133   SnmpSyntax& operator=(const SnmpSyntax &val);
134
135   /**
136    * Behave like an unsigned long.
137    *
138    * @return value as unsigned long
139    */
140   operator unsigned long() const { return smival.value.uNumber; };
141
142   /**
143    * Get a printable ASCII value.
144    */
145   virtual const char *get_printable() const;
146
147   /**
148    * Clone operator.
149    *
150    * @return Pointer to a newly created copy of the object.
151    */
152   virtual SnmpSyntax *clone() const
153     { return (SnmpSyntax *)new SnmpUInt32(*this); };
154
155   /**
156    * Return validity of the object.
157    * An SnmpUInt32 will only be invalid after a failed asignment
158    * of another SnmpSyntax object.
159    */
160   bool valid() const { return valid_flag; };
161
162   /**
163    * Return the space needed for serialization.
164    */
165   int get_asn1_length() const;
166
167   /**
168    * Reset the object.
169    */
170   void clear()
171     { smival.value.uNumber = 0; valid_flag = true; m_changed = true; };
172
173  protected:
174   bool valid_flag;
175   SNMP_PP_MUTABLE char output_buffer[INTOUTBUF];
176   SNMP_PP_MUTABLE bool m_changed;
177 };
178
179
180 /**
181  * 32 bit signed integer class.
182  */
183 class DLLOPT SnmpInt32 : public SnmpSyntax
184 {
185  public:
186
187   /**
188    * Constructor, sets value to zero.
189    */
190   SnmpInt32();
191
192   /**
193    * Constructor with value.
194    *
195    * @param i - initial value
196    */
197   SnmpInt32 (const long i);
198
199   /**
200    * Copy constructor.
201    *
202    * @param c - initial value
203    */
204   SnmpInt32 (const SnmpInt32 &c);
205
206   /**
207    * Destructor (ensure that SnmpSyntax::~SnmpSyntax() is overridden).
208    */
209   virtual ~SnmpInt32() {};
210
211   /**
212    * Return the syntax.
213    *
214    * @return This method always returns sNMP_SYNTAX_INT32.
215    */
216   virtual SmiUINT32 get_syntax() const { return sNMP_SYNTAX_INT32; };
217
218   /**
219    * Overloaded assignment for longs.
220    *
221    * @param i - new value
222    * @return self reference
223    */
224   SnmpInt32& operator=(const long i);
225
226   /**
227    * Overloaded assignment for SnmpInt32.
228    *
229    * @param li - new value
230    * @return self reference
231    */
232   SnmpInt32& operator=(const SnmpInt32 &li);
233
234   /**
235    * Map other SnmpSyntax objects to SnmpInt32.
236    */
237   SnmpSyntax& operator=(const SnmpSyntax &val);
238
239   /**
240    * Behave like an long.
241    *
242    * @return value as long
243    */
244   operator long() const { return (long) smival.value.sNumber; };
245
246   /**
247    * Get a printable ASCII value.
248    */
249   const char *get_printable() const;
250
251   /**
252    * Clone operator.
253    *
254    * @return Pointer to a newly created copy of the object.
255    */
256   SnmpSyntax *clone() const { return (SnmpSyntax *)new SnmpInt32(*this); };
257
258   /**
259    * Return validity of the object.
260    * An SnmpUInt32 will only be invalid after a failed asignment
261    * of another SnmpSyntax object.
262    */
263   bool valid() const { return valid_flag; };
264
265   /**
266    * Return the space needed for serialization.
267    */
268   int get_asn1_length() const;
269
270   /**
271    * Reset the object.
272    */
273   void clear()
274     { smival.value.sNumber = 0; valid_flag = true; m_changed = true; };
275
276  protected:
277   bool valid_flag;
278   SNMP_PP_MUTABLE char output_buffer[INTOUTBUF];
279   SNMP_PP_MUTABLE bool m_changed;
280 };
281
282 #ifdef SNMP_PP_NAMESPACE
283 } // end of namespace Snmp_pp
284 #endif 
285
286 #endif