From stdcxx-commits-return-78-apmail-incubator-stdcxx-commits-archive=incubator.apache.org@incubator.apache.org Mon Sep 19 00:25:34 2005 Return-Path: Delivered-To: apmail-incubator-stdcxx-commits-archive@www.apache.org Received: (qmail 25931 invoked from network); 19 Sep 2005 00:25:34 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 19 Sep 2005 00:25:34 -0000 Received: (qmail 63609 invoked by uid 500); 19 Sep 2005 00:25:34 -0000 Delivered-To: apmail-incubator-stdcxx-commits-archive@incubator.apache.org Received: (qmail 63590 invoked by uid 500); 19 Sep 2005 00:25:34 -0000 Mailing-List: contact stdcxx-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: stdcxx-dev@incubator.apache.org Delivered-To: mailing list stdcxx-commits@incubator.apache.org Received: (qmail 63570 invoked by uid 500); 19 Sep 2005 00:25:34 -0000 Delivered-To: apmail-incubator-stdcxx-cvs@incubator.apache.org Received: (qmail 63567 invoked by uid 99); 19 Sep 2005 00:25:34 -0000 X-ASF-Spam-Status: No, hits=-9.8 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.29) with SMTP; Sun, 18 Sep 2005 17:25:33 -0700 Received: (qmail 25922 invoked by uid 65534); 19 Sep 2005 00:25:32 -0000 Message-ID: <20050919002532.25921.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r290028 - in /incubator/stdcxx/trunk/tests: include/any.h src/any.cpp Date: Mon, 19 Sep 2005 00:25:32 -0000 To: stdcxx-cvs@incubator.apache.org From: sebor@apache.org X-Mailer: svnmailer-1.0.5 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: sebor Date: Sun Sep 18 17:25:26 2005 New Revision: 290028 URL: http://svn.apache.org/viewcvs?rev=290028&view=rev Log: 2005-09-18 Martin Sebor STDCXX-3 * any.h: New. Definition of the rw_any_t helper class. * any.cpp: New. Definitions of the rw_any_t class member functions. Added: incubator/stdcxx/trunk/tests/include/any.h (with props) incubator/stdcxx/trunk/tests/src/any.cpp (with props) Added: incubator/stdcxx/trunk/tests/include/any.h URL: http://svn.apache.org/viewcvs/incubator/stdcxx/trunk/tests/include/any.h?rev=290028&view=auto ============================================================================== --- incubator/stdcxx/trunk/tests/include/any.h (added) +++ incubator/stdcxx/trunk/tests/include/any.h Sun Sep 18 17:25:26 2005 @@ -0,0 +1,133 @@ +/*************************************************************************** + * + * any.h - definition of the rw_any_t class + * + * $Id$ + * + *************************************************************************** + * + * Copyright (c) 1994-2005 Quovadx, Inc., acting through its Rogue Wave + * Software division. Licensed under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0. Unless required by + * applicable law or agreed to in writing, software distributed under + * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + * CONDITIONS OF ANY KIND, either express or implied. See the License + * for the specific language governing permissions and limitations under + * the License. + * + **************************************************************************/ + +#ifndef RW_ANY_H_INCLUDED +#define RW_ANY_H_INCLUDED + + +#include + + +class _TEST_EXPORT rw_any_t +{ +public: + +#ifndef _RWSTD_NO_BOOL + rw_any_t (bool); +#endif // _RWSTD_NO_BOOL + + rw_any_t (char); + rw_any_t (signed char); + rw_any_t (unsigned char); + + rw_any_t (signed short); + rw_any_t (unsigned short); + + rw_any_t (signed int); + rw_any_t (unsigned int); + + rw_any_t (signed long); + rw_any_t (unsigned long); + +#ifdef _RWSTD_LONG_LONG + rw_any_t (signed _RWSTD_LONG_LONG); + rw_any_t (unsigned _RWSTD_LONG_LONG); +#endif // _RWSTD_LONG_LONG + + rw_any_t (float); + rw_any_t (double); + +#ifndef _RWSTD_NO_LONG_DOUBLE + rw_any_t (long double); +#endif // _RWSTD_NO_LONG_DOUBLE + + rw_any_t (const void*); + rw_any_t (const char*); + +#ifndef _RWSTD_NO_NATIVE_WCHAR_T + rw_any_t (wchar_t); +#endif // _RWSTD_NO_NATIVE_WCHAR_T + +#ifndef _RWSTD_NO_WCHAR_T + rw_any_t (const wchar_t*); +#endif // _RWSTD_NO_WCHAR_T + + rw_any_t (const rw_any_t&); + + ~rw_any_t (); + + rw_any_t& operator= (const rw_any_t&); + + const char* tostr (const char* = 0); + const char* type_name () const; + + enum type_id_t { + t_none, + t_bool, t_schar, t_uchar, t_char, + t_sshrt, t_ushrt, t_sint, t_uint, t_slong, t_ulong, + t_sllong, t_ullong, + t_flt, t_dbl, t_ldbl, + t_wchar, + t_pvoid, + t_str, + t_wstr + }; + +private: + + union uval_t { + +#ifndef _RWSTD_NO_LONG_DOUBLE + long double ldbl_; +#endif // _RWSTD_NO_LONG_DOUBLE + const void *pvoid_; + double dbl_; +#ifdef _RWSTD_LONG_LONG + signed _RWSTD_LONG_LONG sllong_; + unsigned _RWSTD_LONG_LONG ullong_; +#endif // _RWSTD_LONG_LONG + float flt_; +#ifndef _RWSTD_NO_NATIVE_WCHAR_T + wchar_t wchar_; +#endif // _RWSTD_NO_NATIVE_WCHAR_T + signed long slong_; + unsigned long ulong_; + signed int sint_; + unsigned int uint_; + signed short sshrt_; + unsigned short ushrt_; + signed char schar_; + unsigned char uchar_; + char char_; +#ifndef _RWSTD_NO_BOOL + bool bool_; +#endif // _RWSTD_NO_BOOL + } val_; + + char *str_; + type_id_t tid_; +}; + + +#define TOSTR(x) rw_any_t (x).tostr () + + +#endif // RW_ANY_H_INCLUDED Propchange: incubator/stdcxx/trunk/tests/include/any.h ------------------------------------------------------------------------------ svn:eol-style = native Propchange: incubator/stdcxx/trunk/tests/include/any.h ------------------------------------------------------------------------------ svn:keywords = Id Added: incubator/stdcxx/trunk/tests/src/any.cpp URL: http://svn.apache.org/viewcvs/incubator/stdcxx/trunk/tests/src/any.cpp?rev=290028&view=auto ============================================================================== --- incubator/stdcxx/trunk/tests/src/any.cpp (added) +++ incubator/stdcxx/trunk/tests/src/any.cpp Sun Sep 18 17:25:26 2005 @@ -0,0 +1,366 @@ +/************************************************************************ + * + * any.cpp - definitions of the rw_any_t class members + * + * $Id$ + * + ************************************************************************ + * + * Copyright (c) 1994-2005 Quovadx, Inc., acting through its Rogue Wave + * Software division. Licensed under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0. Unless required by + * applicable law or agreed to in writing, software distributed under + * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + * CONDITIONS OF ANY KIND, either express or implied. See the License + * for the specific language governing permissions and limitations under + * the License. + * + **************************************************************************/ + +// expand _TEST_EXPORT macros +#define _RWSTD_TEST_SRC + +#include + +#include // for rw_sprintfa() +#include // for free() + + +#ifndef _RWSTD_NO_BOOL + +rw_any_t::rw_any_t (bool value) + : val_ (), str_ (0), tid_ (t_bool) +{ + val_.bool_ = value; +} + +#endif // _RWSTD_NO_BOOL + + +rw_any_t::rw_any_t (char value) + : val_ (), str_ (0), tid_ (t_char) +{ + val_.char_ = value; +} + + +rw_any_t::rw_any_t (signed char value) + : val_ (), str_ (0), tid_ (t_schar) +{ + val_.schar_ = value; +} + + +rw_any_t::rw_any_t (unsigned char value) + : val_ (), str_ (0), tid_ (t_uchar) +{ + val_.uchar_ = value; +} + + +rw_any_t::rw_any_t (signed short value) + : val_ (), str_ (0), tid_ (t_sshrt) +{ + val_.sshrt_ = value; +} + + +rw_any_t::rw_any_t (unsigned short value) + : val_ (), str_ (0), tid_ (t_ushrt) +{ + val_.ushrt_ = value; +} + + +rw_any_t::rw_any_t (signed int value) + : val_ (), str_ (0), tid_ (t_sint) +{ + val_.sint_ = value; +} + + +rw_any_t::rw_any_t (unsigned int value) + : val_ (), str_ (0), tid_ (t_uint) +{ + val_.uint_ = value; +} + + +rw_any_t::rw_any_t (signed long value) + : val_ (), str_ (0), tid_ (t_slong) +{ + val_.slong_ = value; +} + + +rw_any_t::rw_any_t (unsigned long value) + : val_ (), str_ (0), tid_ (t_ulong) +{ + val_.ulong_ = value; +} + + +#ifdef _RWSTD_LONG_LONG + +rw_any_t::rw_any_t (signed _RWSTD_LONG_LONG value) + : val_ (), str_ (0), tid_ (t_sllong) +{ + val_.sllong_ = value; +} + + +rw_any_t::rw_any_t (unsigned _RWSTD_LONG_LONG value) + : val_ (), str_ (0), tid_ (t_ullong) +{ + val_.ullong_ = value; +} + +#endif // _RWSTD_LONG_LONG + + +rw_any_t::rw_any_t (float value) + : val_ (), str_ (0), tid_ (t_flt) +{ + val_.flt_ = value; +} + + +rw_any_t::rw_any_t (double value) + : val_ (), str_ (0), tid_ (t_dbl) +{ + val_.dbl_ = value; +} + + +rw_any_t::rw_any_t (long double value) + : val_ (), str_ (0), tid_ (t_ldbl) +{ + val_.ldbl_ = value; +} + + +rw_any_t::rw_any_t (const void* value) + : val_ (), str_ (0), tid_ (t_pvoid) +{ + val_.pvoid_ = value; +} + + +rw_any_t::rw_any_t (const char* value) + : val_ (), str_ (0), tid_ (t_str) +{ + val_.pvoid_ = value; +} + + +#ifndef _RWSTD_NO_NATIVE_WCHAR_T + +rw_any_t::rw_any_t (wchar_t value) + : val_ (), str_ (0), tid_ (t_wchar) +{ + val_.wchar_ = value; +} + +#endif // _RWSTD_NO_NATIVE_WCHAR_T + + +#ifndef _RWSTD_NO_WCHAR_T + +rw_any_t::rw_any_t (const wchar_t* value) + : val_ (), str_ (0), tid_ (t_wstr) +{ + val_.pvoid_ = value; +} + +#endif // _RWSTD_NO_WCHAR_T + + +rw_any_t::rw_any_t (const rw_any_t &rhs) + : val_ (rhs.val_), str_ (0), tid_ (rhs.tid_) +{ +} + + +rw_any_t& rw_any_t::operator= (const rw_any_t &rhs) +{ + // free string allocated by tostr() (via a call to sprintfa()) + free (str_); + + val_ = rhs.val_; + str_ = 0; + tid_ = rhs.tid_; + + return *this; +} + + +rw_any_t::~rw_any_t () +{ + // free string allocated by tostr() (via a call to sprintfa()) + free (str_); + + val_ = uval_t (); + str_ = 0; + tid_ = type_id_t (); +} + + +const char* +rw_any_t::type_name () const +{ + static const char* const names[] = { + "", + "bool", "signed char", "unsigned char", "char", + "signed short", "unsigned short", "signed int", "unsigned int", + "signed long", "unsigned long", + "signed long long", "unsigned long long", + "float", "double", "long double", + "wchar_t", "void*", + "const char*", "const wchar_t*" + }; + + return names [tid_]; +} + + +const char* +rw_any_t::tostr (const char *fmt /* = 0 */) +{ + // free the previously allocated string + free (str_); + str_ = 0; + + switch (tid_) { + case t_bool: + return val_.bool_ ? "true" : "false"; + + case t_char: + if (0 == fmt) + fmt = "%c"; + str_ = rw_sprintfa (fmt, val_.char_); + break; + + case t_schar: + if (0 == fmt) + fmt = "%hhi"; + str_ = rw_sprintfa (fmt, val_.schar_); + break; + + case t_uchar: + if (0 == fmt) + fmt = "%hhu"; + str_ = rw_sprintfa (fmt, val_.uchar_); + break; + + case t_sshrt: + if (0 == fmt) + fmt = "%hi"; + str_ = rw_sprintfa (fmt, val_.sshrt_); + break; + + case t_ushrt: + if (0 == fmt) + fmt = "%hu"; + str_ = rw_sprintfa (fmt, val_.ushrt_); + break; + + case t_sint: + if (0 == fmt) + fmt = "%i"; + str_ = rw_sprintfa (fmt, val_.sint_); + break; + + case t_uint: + if (0 == fmt) + fmt = "%u"; + str_ = rw_sprintfa (fmt, val_.uint_); + break; + + case t_slong: + if (0 == fmt) + fmt = "%li"; + str_ = rw_sprintfa (fmt, val_.slong_); + break; + + case t_ulong: + if (0 == fmt) + fmt = "%lu"; + str_ = rw_sprintfa (fmt, val_.ulong_); + break; + +#ifdef _RWSTD_LONG_LONG + + case t_sllong: + if (0 == fmt) + fmt = "%lli"; + str_ = rw_sprintfa (fmt, val_.sllong_); + break; + + case t_ullong: + if (0 == fmt) + fmt = "%llu"; + str_ = rw_sprintfa (fmt, val_.ullong_); + break; + +#endif // _RWSTD_LONG_LONG + + case t_flt: + if (0 == fmt) + fmt = "%g"; + str_ = rw_sprintfa (fmt, val_.flt_); + break; + + case t_dbl: + if (0 == fmt) + fmt = "%g"; + str_ = rw_sprintfa (fmt, val_.dbl_); + break; + +#ifndef _RWSTD_NO_LONG_DOUBLE + + case t_ldbl: + if (0 == fmt) + fmt = "%Lg"; + str_ = rw_sprintfa (fmt, val_.ldbl_); + break; + +#endif // _RWSTD_NO_LONG_DOUBLE + + case t_pvoid: + if (0 == fmt) + fmt = "%p"; + str_ = rw_sprintfa (fmt, val_.pvoid_); + break; + +#ifndef _RWSTD_NO_NATIVE_WCHAR_T + + case t_wchar: + if (0 == fmt) + fmt = "%lc"; + str_ = rw_sprintfa (fmt, val_.wchar_); + break; + +#endif // _RWSTD_NO_NATIVE_WCHAR_T + + case t_str: + if (0 == fmt) + fmt = "%s"; + str_ = rw_sprintfa (fmt, val_.pvoid_); + break; + +#ifndef _RWSTD_NO_WCHAR_T + + case t_wstr: + if (0 == fmt) + fmt = "%ls"; + str_ = rw_sprintfa (fmt, val_.pvoid_); + break; + +#endif // _RWSTD_NO_WCHAR_T + + } + + return str_; +} Propchange: incubator/stdcxx/trunk/tests/src/any.cpp ------------------------------------------------------------------------------ svn:eol-style = native Propchange: incubator/stdcxx/trunk/tests/src/any.cpp ------------------------------------------------------------------------------ svn:keywords = Id