SNMP++  3.3.4
integer.h
Go to the documentation of this file.
1 /*_############################################################################
2  _##
3  _## integer.h
4  _##
5  _## SNMP++ v3.3
6  _## -----------------------------------------------
7  _## Copyright (c) 2001-2013 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  _##########################################################################*/
27 /*===================================================================
28 
29  Copyright (c) 1999
30  Hewlett-Packard Company
31 
32  ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.
33  Permission to use, copy, modify, distribute and/or sell this software
34  and/or its documentation is hereby granted without fee. User agrees
35  to display the above copyright notice and this license notice in all
36  copies of the software and any documentation of the software. User
37  agrees to assume all liability for the use of the software; Hewlett-Packard
38  makes no representations about the suitability of this software for any
39  purpose. It is provided "AS-IS without warranty of any kind,either express
40  or implied. User hereby grants a royalty-free license to any and all
41  derivatives based upon this software code base.
42 
43 
44  SNMP++ I N T E G E R. H
45 
46  INTEGER CLASS DEFINITION
47 
48  DESIGN + AUTHOR: Jeff Meyer
49 
50  DESCRIPTION:
51  Class definition for Integer classes.
52 
53 =====================================================================*/
54 // $Id: integer.h 2359 2013-05-09 20:07:01Z fock $
55 
56 #ifndef _SNMPINTEGER
57 #define _SNMPINTEGER
58 
59 #include "snmp_pp/smival.h"
60 
61 #ifdef SNMP_PP_NAMESPACE
62 namespace Snmp_pp {
63 #endif
64 
65 #define INTOUTBUF 15 // largest ASCII formatted integer
66 
67 //------------[ Integer Classes ]------------------------------------------
68 
69 /**
70  * 32 bit unsigned integer class.
71  *
72  * The integer class allows all the functionality of the various
73  * integers but is contained in a Value object for consistency
74  * among the various types.
75  * class objects may be set or get into Vb objects.
76  */
78 {
79  public:
80 
81  /**
82  * Constructor with value (defaults to 0).
83  *
84  * @param i - initial value
85  */
86  SnmpUInt32(const unsigned long i = 0)
87  : SnmpSyntax()
88  , valid_flag(true)
89  , m_changed(true)
90  {
91  smival.value.uNumber = i;
92  smival.syntax = sNMP_SYNTAX_UINT32;
93  }
94 
95  /**
96  * Copy constructor.
97  *
98  * @param c - initial value
99  */
101  : SnmpSyntax()
102  , valid_flag(c.valid_flag)
103  , m_changed(true)
104  {
105  smival.value.uNumber = c.smival.value.uNumber;
106  smival.syntax = sNMP_SYNTAX_UINT32;
107  }
108 
109  /**
110  * Destructor (ensure that SnmpSyntax::~SnmpSyntax() is overridden).
111  */
112  virtual ~SnmpUInt32() {}
113 
114  /**
115  * Return the syntax.
116  *
117  * @return This method always returns sNMP_SYNTAX_UINT32.
118  */
119  virtual SmiUINT32 get_syntax() const { return sNMP_SYNTAX_UINT32; }
120 
121  /**
122  * Overloaded assignment for unsigned longs.
123  *
124  * @param i - new value
125  * @return self reference
126  */
127  SnmpUInt32 & operator = (const unsigned long i)
128  {
129  smival.value.uNumber = i;
130  valid_flag = true;
131  m_changed = true;
132  return *this;
133  }
134 
135  /**
136  * Overloaded assignment for SnmpUInt32.
137  *
138  * @param uli - new value
139  * @return self reference
140  */
141  SnmpUInt32 & operator = (const SnmpUInt32 &uli)
142  {
143  if (this == &uli)
144  return *this; // check for self assignment
145 
146  smival.value.uNumber = uli.smival.value.uNumber;
147  valid_flag = uli.valid_flag;
148  m_changed = true;
149  return *this;
150  }
151 
152  /**
153  * Map other SnmpSyntax objects to SnmpUInt32.
154  */
155  SnmpSyntax& operator=(const SnmpSyntax &val);
156 
157  /**
158  * Behave like an unsigned long.
159  *
160  * @return value as unsigned long
161  */
162  operator unsigned long() const { return smival.value.uNumber; };
163 
164  /**
165  * Get a printable ASCII value.
166  */
167  virtual const char *get_printable() const;
168 
169  /**
170  * Clone operator.
171  *
172  * @return Pointer to a newly created copy of the object.
173  */
174  virtual SnmpSyntax *clone() const
175  { return (SnmpSyntax *)new SnmpUInt32(*this); };
176 
177  /**
178  * Return validity of the object.
179  * An SnmpUInt32 will only be invalid after a failed asignment
180  * of another SnmpSyntax object.
181  */
182  bool valid() const { return valid_flag; }
183 
184  /**
185  * Return the space needed for serialization.
186  */
187  int get_asn1_length() const;
188 
189  /**
190  * Reset the object.
191  */
192  void clear()
193  { smival.value.uNumber = 0; valid_flag = true; m_changed = true; }
194 
195  protected:
197  SNMP_PP_MUTABLE char output_buffer[INTOUTBUF];
199 };
200 
201 
202 /**
203  * 32 bit signed integer class.
204  */
206 {
207  public:
208 #if 0
209  /**
210  * Constructor, sets value to zero.
211  */
212  SnmpInt32();
213 #endif
214 
215  /**
216  * Constructor with value.
217  *
218  * @param i - initial value
219  */
220  SnmpInt32 (const long i = 0)
221  : SnmpSyntax()
222  , valid_flag(true)
223  , m_changed(true)
224  {
225  smival.value.sNumber = i;
226  smival.syntax = sNMP_SYNTAX_INT32;
227  }
228 
229  /**
230  * Copy constructor.
231  *
232  * @param c - initial value
233  */
234  SnmpInt32 (const SnmpInt32 &c)
235  : SnmpSyntax()
236  , valid_flag(c.valid_flag)
237  , m_changed(true)
238  {
239  smival.value.sNumber = c.smival.value.sNumber;
240  smival.syntax = sNMP_SYNTAX_INT32;
241  }
242 
243  /**
244  * Destructor (ensure that SnmpSyntax::~SnmpSyntax() is overridden).
245  */
246  virtual ~SnmpInt32() {}
247 
248  /**
249  * Return the syntax.
250  *
251  * @return This method always returns sNMP_SYNTAX_INT32.
252  */
253  virtual SmiUINT32 get_syntax() const { return sNMP_SYNTAX_INT32; }
254 
255  /**
256  * Overloaded assignment for longs.
257  *
258  * @param i - new value
259  * @return self reference
260  */
261  SnmpInt32 & operator = (const long i)
262  {
263  smival.value.sNumber = i;
264  valid_flag = true;
265  m_changed = true;
266  return *this;
267  }
268 
269  /**
270  * Overloaded assignment for SnmpInt32.
271  *
272  * @param li - new value
273  * @return self reference
274  */
275  SnmpInt32 & operator = (const SnmpInt32 &li)
276  {
277  if (this == &li)
278  return *this; // check for self assignment
279 
280  smival.value.sNumber = li.smival.value.sNumber;
281  valid_flag = li.valid_flag;
282  m_changed = true;
283  return *this;
284  }
285 
286  /**
287  * Map other SnmpSyntax objects to SnmpInt32.
288  */
289  SnmpSyntax& operator=(const SnmpSyntax &val);
290 
291  /**
292  * Behave like an long.
293  *
294  * @return value as long
295  */
296  operator long () const { return (long) smival.value.sNumber; }
297 
298  /**
299  * Get a printable ASCII value.
300  */
301  const char *get_printable() const;
302 
303  /**
304  * Clone operator.
305  *
306  * @return Pointer to a newly created copy of the object.
307  */
308  SnmpSyntax *clone() const { return (SnmpSyntax *)new SnmpInt32(*this); };
309 
310  /**
311  * Return validity of the object.
312  * An SnmpUInt32 will only be invalid after a failed asignment
313  * of another SnmpSyntax object.
314  */
315  bool valid() const { return valid_flag; }
316 
317  /**
318  * Return the space needed for serialization.
319  */
320  int get_asn1_length() const;
321 
322  /**
323  * Reset the object.
324  */
325  void clear()
326  { smival.value.sNumber = 0; valid_flag = true; m_changed = true; }
327 
328  protected:
330  SNMP_PP_MUTABLE char output_buffer[INTOUTBUF];
332 };
333 
334 #ifdef SNMP_PP_NAMESPACE
335 } // end of namespace Snmp_pp
336 #endif
337 
338 #endif
#define sNMP_SYNTAX_UINT32
Definition: smi.h:112
unsigned long SmiUINT32
Definition: smi.h:157
SmiVALUE smival
Definition: smival.h:179
#define SNMP_PP_MUTABLE
SmiUINT32 uNumber
Definition: smival.h:89
virtual SmiUINT32 get_syntax() const
Return the syntax.
Definition: integer.h:119
SNMP_PP_MUTABLE bool m_changed
Definition: integer.h:198
void clear()
Reset the object.
Definition: integer.h:325
virtual SnmpSyntax * clone() const
Clone operator.
Definition: integer.h:174
virtual ~SnmpInt32()
Destructor (ensure that SnmpSyntax::~SnmpSyntax() is overridden).
Definition: integer.h:246
32 bit signed integer class.
Definition: integer.h:205
bool valid_flag
Definition: integer.h:196
#define DLLOPT
SnmpUInt32(const SnmpUInt32 &c)
Copy constructor.
Definition: integer.h:100
bool valid() const
Return validity of the object.
Definition: integer.h:315
virtual ~SnmpUInt32()
Destructor (ensure that SnmpSyntax::~SnmpSyntax() is overridden).
Definition: integer.h:112
SnmpInt32(const long i=0)
Constructor with value.
Definition: integer.h:220
SnmpInt32(const SnmpInt32 &c)
Copy constructor.
Definition: integer.h:234
32 bit unsigned integer class.
Definition: integer.h:77
union SmiVALUE::@1 value
SnmpSyntax * clone() const
Clone operator.
Definition: integer.h:308
#define sNMP_SYNTAX_INT32
Definition: smi.h:105
SNMP_PP_MUTABLE bool m_changed
Definition: integer.h:331
void clear()
Reset the object.
Definition: integer.h:192
SmiINT sNumber
Definition: smival.h:87
SnmpUInt32(const unsigned long i=0)
Constructor with value (defaults to 0).
Definition: integer.h:86
An "abstract" (pure virtual) class that serves as the base class for all specific SNMP syntax types...
Definition: smival.h:116
#define INTOUTBUF
Definition: integer.h:65
bool valid_flag
Definition: integer.h:329
virtual SmiUINT32 get_syntax() const
Return the syntax.
Definition: integer.h:253
bool valid() const
Return validity of the object.
Definition: integer.h:182