Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / ACE / ASNMP / asnmp / integer.cpp
blob403b34de7ee1585f75bce224332372e7959bfe5a
2 //=============================================================================
3 /**
4 * @file integer.cpp
6 * Class implemtation for SMI Integer classes.
8 * @author Jeff MeyerMichael R MacFaden mrm@cisco.com - rework & ACE port
9 */
10 //=============================================================================
12 /*===================================================================
14 Copyright (c) 1996
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;
37 valid_flag = 1;
40 // copy constructor
41 SnmpUInt32::SnmpUInt32( const SnmpUInt32 &c)
42 : SnmpSyntax (c)
44 smival.value.uNumber=c.smival.value.uNumber;
45 smival.syntax = sNMP_SYNTAX_UINT32;
46 valid_flag = 1;
49 // destructor (ensure that SnmpSyntax::~SnmpSyntax() is overridden)
50 SnmpUInt32::~SnmpUInt32()
54 // syntax type
55 SmiUINT32 SnmpUInt32::get_syntax()
57 return sNMP_SYNTAX_UINT32;
60 // object validity
61 int SnmpUInt32::valid() const
63 return valid_flag;
66 // overloaded assignment
67 SnmpUInt32& SnmpUInt32::operator=( const unsigned long int i)
69 smival.value.uNumber=i;
70 valid_flag = 1;
71 return *this;
74 // general assignment from any Value
75 SnmpSyntax& SnmpUInt32::operator=( SnmpSyntax &in_val)
77 if ( this == &in_val ) // handle assignement from itself
78 return *this;
80 valid_flag = 0; // will get set true if really valid
81 if (in_val.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;
92 valid_flag = 1;
93 break;
96 return *this;
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;
134 valid_flag = 1;
137 // constructor with value
138 SnmpInt32::SnmpInt32 (const SnmpInt32 &c)
139 : SnmpSyntax (c)
141 smival.value.sNumber=c.smival.value.sNumber;
142 smival.syntax = sNMP_SYNTAX_INT32;
143 valid_flag = 1;
146 // destructor
147 SnmpInt32::~SnmpInt32()
151 // syntax type
152 SmiUINT32 SnmpInt32::get_syntax()
154 return sNMP_SYNTAX_INT32;
157 // object validity
158 int SnmpInt32::valid() const
160 return valid_flag;
163 // overloaded assignment
164 SnmpInt32& SnmpInt32::operator=( const long i)
166 this->smival.value.sNumber = (unsigned long) i;
167 valid_flag = 1;
168 return *this;
171 // overloaded assignment
172 SnmpInt32& SnmpInt32::operator=( const SnmpInt32 &uli)
174 this->smival.value.sNumber = uli.smival.value.sNumber;
175 valid_flag = 1;
176 return *this;
179 // general assignment from any Value
180 SnmpSyntax& SnmpInt32::operator=( SnmpSyntax &in_val)
182 if ( this == &in_val ) // handle assignement from itself
183 return *this;
185 valid_flag = 0; // will get set true if really valid
186 if (in_val.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;
197 valid_flag = 1;
198 break;
201 return *this;
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;