Update contrib.
1 /************************************************************************
3 * any.cpp - definitions of the rw_any_t class members
5 * $Id: any.cpp 345524 2005-11-18 17:08:11Z sebor $
7 ************************************************************************
9 * Copyright (c) 1994-2005 Quovadx, Inc., acting through its Rogue Wave
10 * Software division. Licensed under the Apache License, Version 2.0 (the
11 * "License"); you may not use this file except in compliance with the
12 * License. You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0. Unless required by
14 * applicable law or agreed to in writing, software distributed under
15 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
16 * CONDITIONS OF ANY KIND, either express or implied. See the License
17 * for the specific language governing permissions and limitations under
20 **************************************************************************/
22 // expand _TEST_EXPORT macros
23 #define _RWSTD_TEST_SRC
27 #include <printf.h> // for rw_sprintfa()
28 #include <stdlib.h> // for free()
29 #include <string.h> // for memset()
32 #ifndef _RWSTD_NO_BOOL
34 _TEST_EXPORT rw_any_t::rw_any_t (bool value)
35 : str_ (0), tid_ (t_bool)
37 // using memset instead of default-initialization in the ctor
38 // initializer list here and in all other ctors to work around
39 // a SunPro -xarch=v9 bug (PR #28328) that causes the following:
40 // Warning (Anachronism): Assigning int to __BIT_BLAST_16_16.
41 // Error: Cannot cast from int to __BIT_BLAST_16_16
43 memset (&val_, 0, sizeof val_);
47 #endif // _RWSTD_NO_BOOL
49 _TEST_EXPORT rw_any_t::rw_any_t (char value)
50 : str_ (0), tid_ (t_char)
52 memset (&val_, 0, sizeof val_);
57 _TEST_EXPORT rw_any_t::rw_any_t (signed char value)
58 : str_ (0), tid_ (t_schar)
60 memset (&val_, 0, sizeof val_);
65 _TEST_EXPORT rw_any_t::rw_any_t (unsigned char value)
66 : str_ (0), tid_ (t_uchar)
68 memset (&val_, 0, sizeof val_);
73 _TEST_EXPORT rw_any_t::rw_any_t (signed short value)
74 : str_ (0), tid_ (t_sshrt)
76 memset (&val_, 0, sizeof val_);
81 _TEST_EXPORT rw_any_t::rw_any_t (unsigned short value)
82 : str_ (0), tid_ (t_ushrt)
84 memset (&val_, 0, sizeof val_);
89 _TEST_EXPORT rw_any_t::rw_any_t (signed int value)
90 : str_ (0), tid_ (t_sint)
92 memset (&val_, 0, sizeof val_);
97 _TEST_EXPORT rw_any_t::rw_any_t (unsigned int value)
98 : str_ (0), tid_ (t_uint)
100 memset (&val_, 0, sizeof val_);
105 _TEST_EXPORT rw_any_t::rw_any_t (signed long value)
106 : str_ (0), tid_ (t_slong)
108 memset (&val_, 0, sizeof val_);
113 _TEST_EXPORT rw_any_t::rw_any_t (unsigned long value)
114 : str_ (0), tid_ (t_ulong)
116 memset (&val_, 0, sizeof val_);
121 #ifdef _RWSTD_LONG_LONG
123 _TEST_EXPORT rw_any_t::rw_any_t (signed _RWSTD_LONG_LONG value)
124 : str_ (0), tid_ (t_sllong)
126 memset (&val_, 0, sizeof val_);
127 val_.sllong_ = value;
131 _TEST_EXPORT rw_any_t::rw_any_t (unsigned _RWSTD_LONG_LONG value)
132 : str_ (0), tid_ (t_ullong)
134 memset (&val_, 0, sizeof val_);
135 val_.ullong_ = value;
138 #endif // _RWSTD_LONG_LONG
141 _TEST_EXPORT rw_any_t::rw_any_t (float value)
142 : str_ (0), tid_ (t_flt)
144 memset (&val_, 0, sizeof val_);
149 _TEST_EXPORT rw_any_t::rw_any_t (double value)
150 : str_ (0), tid_ (t_dbl)
152 memset (&val_, 0, sizeof val_);
157 #ifndef _RWSTD_NO_LONG_DOUBLE
159 _TEST_EXPORT rw_any_t::rw_any_t (long double value)
160 : str_ (0), tid_ (t_ldbl)
162 memset (&val_, 0, sizeof val_);
166 #endif // _RWSTD_NO_LONG_DOUBLE
169 _TEST_EXPORT rw_any_t::rw_any_t (const void* value)
170 : str_ (0), tid_ (t_pvoid)
172 memset (&val_, 0, sizeof val_);
177 _TEST_EXPORT rw_any_t::rw_any_t (const char* value)
178 : str_ (0), tid_ (t_str)
180 memset (&val_, 0, sizeof val_);
185 #ifndef _RWSTD_NO_NATIVE_WCHAR_T
187 _TEST_EXPORT rw_any_t::rw_any_t (wchar_t value)
188 : str_ (0), tid_ (t_wchar)
190 memset (&val_, 0, sizeof val_);
194 #endif // _RWSTD_NO_NATIVE_WCHAR_T
197 #ifndef _RWSTD_NO_WCHAR_T
199 _TEST_EXPORT rw_any_t::rw_any_t (const wchar_t* value)
200 : str_ (0), tid_ (t_wstr)
202 memset (&val_, 0, sizeof val_);
206 #endif // _RWSTD_NO_WCHAR_T
209 _TEST_EXPORT rw_any_t::rw_any_t (const rw_any_t &rhs)
210 : val_ (rhs.val_), str_ (0), tid_ (rhs.tid_)
215 _TEST_EXPORT rw_any_t& rw_any_t::operator= (const rw_any_t &rhs)
217 // free string allocated by tostr() (via a call to sprintfa())
228 _TEST_EXPORT rw_any_t::~rw_any_t ()
230 // free string allocated by tostr() (via a call to sprintfa())
233 memset (&val_, 0, sizeof val_);
240 _TEST_EXPORT const char*
241 rw_any_t::type_name () const
243 static const char* const names[] = {
245 "bool", "signed char", "unsigned char", "char",
246 "short", "unsigned short", "int", "unsigned int",
247 "long", "unsigned long",
248 "long long", "unsigned long long",
249 "float", "double", "long double",
251 "const char*", "const wchar_t*"
254 // the liftime of the returned string must extend
255 // to the end of the program
260 _TEST_EXPORT const char*
261 rw_any_t::tostr (const char *fmt /* = 0 */)
263 // free the previously allocated string
272 return val_.bool_ ? "true" : "false";
277 str_ = rw_sprintfa (fmt, val_.char_);
283 str_ = rw_sprintfa (fmt, val_.schar_);
289 str_ = rw_sprintfa (fmt, val_.uchar_);
295 str_ = rw_sprintfa (fmt, val_.sshrt_);
301 str_ = rw_sprintfa (fmt, val_.ushrt_);
307 str_ = rw_sprintfa (fmt, val_.sint_);
313 str_ = rw_sprintfa (fmt, val_.uint_);
319 str_ = rw_sprintfa (fmt, val_.slong_);
325 str_ = rw_sprintfa (fmt, val_.ulong_);
328 #ifdef _RWSTD_LONG_LONG
333 str_ = rw_sprintfa (fmt, val_.sllong_);
339 str_ = rw_sprintfa (fmt, val_.ullong_);
342 #endif // _RWSTD_LONG_LONG
347 str_ = rw_sprintfa (fmt, val_.flt_);
353 str_ = rw_sprintfa (fmt, val_.dbl_);
356 #ifndef _RWSTD_NO_LONG_DOUBLE
361 str_ = rw_sprintfa (fmt, val_.ldbl_);
364 #endif // _RWSTD_NO_LONG_DOUBLE
369 str_ = rw_sprintfa (fmt, val_.pvoid_);
372 #ifndef _RWSTD_NO_NATIVE_WCHAR_T
377 str_ = rw_sprintfa (fmt, val_.wchar_);
380 #endif // _RWSTD_NO_NATIVE_WCHAR_T
385 str_ = rw_sprintfa (fmt, val_.pvoid_);
388 #ifndef _RWSTD_NO_WCHAR_T
393 str_ = rw_sprintfa (fmt, val_.pvoid_);
396 #endif // _RWSTD_NO_WCHAR_T