2 //=============================================================================
6 * Class implemtation for SMI Integer classes.
8 * @author Jeff MeyerMichael R MacFaden mrm@cisco.com - rework & ACE port
10 //=============================================================================
12 /*===================================================================
15 Hewlett-Packard Company
17 ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.
18 Permission to use, copy, modify, distribute and/or sell this software
19 and/or its documentation is hereby granted without fee. User agrees
20 to display the above copyright notice and this license notice in all
21 copies of the software and any documentation of the software. User
22 agrees to assume all liability for the use of the software; Hewlett-Packard
23 makes no representations about the suitability of this software for any
24 purpose. It is provided "AS-IS without warranty of any kind,either express
25 or implied. User hereby grants a royalty-free license to any and all
26 derivatives based upon this software code base.
27 =====================================================================*/
29 #include "asnmp/integer.h" // header file for gauge class
30 #include "ace/OS_NS_stdio.h"
32 // constructor with value
33 SnmpUInt32::SnmpUInt32 (const unsigned long i
)
35 smival
.value
.uNumber
=i
;
36 smival
.syntax
= sNMP_SYNTAX_UINT32
;
41 SnmpUInt32::SnmpUInt32( const SnmpUInt32
&c
)
44 smival
.value
.uNumber
=c
.smival
.value
.uNumber
;
45 smival
.syntax
= sNMP_SYNTAX_UINT32
;
49 // destructor (ensure that SnmpSyntax::~SnmpSyntax() is overridden)
50 SnmpUInt32::~SnmpUInt32()
55 SmiUINT32
SnmpUInt32::get_syntax()
57 return sNMP_SYNTAX_UINT32
;
61 int SnmpUInt32::valid() const
66 // overloaded assignment
67 SnmpUInt32
& SnmpUInt32::operator=( const unsigned long int i
)
69 smival
.value
.uNumber
=i
;
74 // general assignment from any Value
75 SnmpSyntax
& SnmpUInt32::operator=( SnmpSyntax
&in_val
)
77 if ( this == &in_val
) // handle assignement from itself
80 valid_flag
= 0; // will get set true if really valid
83 switch (in_val
.get_syntax())
85 case sNMP_SYNTAX_UINT32
:
86 // case sNMP_SYNTAX_GAUGE32: .. indistinquishable from UINT32
87 case sNMP_SYNTAX_CNTR32
:
88 case sNMP_SYNTAX_TIMETICKS
:
89 case sNMP_SYNTAX_INT32
: // implied cast int -> uint
90 this->smival
.value
.uNumber
=
91 ((SnmpUInt32
&)in_val
).smival
.value
.uNumber
;
99 // overloaded assignment
100 SnmpUInt32
& SnmpUInt32::operator=( const SnmpUInt32
&uli
)
102 this->smival
.value
.uNumber
= uli
.smival
.value
.uNumber
; return *this;
105 // otherwise, behave like an unsigned long int
106 SnmpUInt32::operator unsigned long()
108 return smival
.value
.uNumber
;
111 // create a new instance of this Value
112 SnmpSyntax
* SnmpUInt32::clone() const
114 return (SnmpSyntax
*) new SnmpUInt32(*this);
117 // ASCII format return
118 const char * SnmpUInt32::to_string()
120 ACE_OS::sprintf(output_buffer
, "%d", (int) (this->smival
.value
.uNumber
));
121 return output_buffer
;
125 //====================================================================
126 // INT 32 Implementation
127 //====================================================================
129 // default constructor
130 SnmpInt32::SnmpInt32 (const long i
)
132 smival
.value
.sNumber
=i
;
133 smival
.syntax
= sNMP_SYNTAX_INT32
;
137 // constructor with value
138 SnmpInt32::SnmpInt32 (const SnmpInt32
&c
)
141 smival
.value
.sNumber
=c
.smival
.value
.sNumber
;
142 smival
.syntax
= sNMP_SYNTAX_INT32
;
147 SnmpInt32::~SnmpInt32()
152 SmiUINT32
SnmpInt32::get_syntax()
154 return sNMP_SYNTAX_INT32
;
158 int SnmpInt32::valid() const
163 // overloaded assignment
164 SnmpInt32
& SnmpInt32::operator=( const long i
)
166 this->smival
.value
.sNumber
= (unsigned long) i
;
171 // overloaded assignment
172 SnmpInt32
& SnmpInt32::operator=( const SnmpInt32
&uli
)
174 this->smival
.value
.sNumber
= uli
.smival
.value
.sNumber
;
179 // general assignment from any Value
180 SnmpSyntax
& SnmpInt32::operator=( SnmpSyntax
&in_val
)
182 if ( this == &in_val
) // handle assignement from itself
185 valid_flag
= 0; // will get set true if really valid
188 switch (in_val
.get_syntax())
190 case sNMP_SYNTAX_INT32
:
191 case sNMP_SYNTAX_UINT32
: // implied cast uint -> int
192 // case sNMP_SYNTAX_GAUGE32: .. indistinquishable from UINT32
193 case sNMP_SYNTAX_CNTR32
: // implied cast uint -> int
194 case sNMP_SYNTAX_TIMETICKS
: // implied cast uint -> int
195 this->smival
.value
.sNumber
=
196 ((SnmpInt32
&)in_val
).smival
.value
.sNumber
;
204 // otherwise, behave like a long int
205 SnmpInt32::operator long()
207 return (long) smival
.value
.sNumber
;
210 // clone - create a new instance of this Value
211 SnmpSyntax
* SnmpInt32::clone() const
213 return ( SnmpSyntax
*) new SnmpInt32(*this);
216 // ASCII format return
218 const char *SnmpInt32::to_string()
220 ACE_OS::sprintf(output_buffer
, "%d", (int) (long) this->smival
.value
.sNumber
);
221 return output_buffer
;