os/ossrv/stdcpp/tsrc/Stdcpp_test/stdcxx/include/valcmp.h
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/stdcpp/tsrc/Stdcpp_test/stdcxx/include/valcmp.h	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,191 @@
     1.4 +/************************************************************************
     1.5 + *
     1.6 + * valcmp.h - declarations of the rw_valcmp() family of helper functions
     1.7 + *
     1.8 + * $Id: valcmp.h 351516 2005-12-01 23:21:09Z sebor $
     1.9 + *
    1.10 + ************************************************************************
    1.11 + *
    1.12 + * Copyright (c) 1994-2005 Quovadx,  Inc., acting through its  Rogue Wave
    1.13 + * Software division. Licensed under the Apache License, Version 2.0 (the
    1.14 + * "License");  you may  not use this file except  in compliance with the
    1.15 + * License.    You    may   obtain   a   copy   of    the   License    at
    1.16 + * http://www.apache.org/licenses/LICENSE-2.0.    Unless   required    by
    1.17 + * applicable law  or agreed to  in writing,  software  distributed under
    1.18 + * the License is distributed on an "AS IS" BASIS,  WITHOUT WARRANTIES OR
    1.19 + * CONDITIONS OF  ANY KIND, either  express or implied.  See  the License
    1.20 + * for the specific language governing permissions  and limitations under
    1.21 + * the License.
    1.22 + * 
    1.23 + **************************************************************************/
    1.24 +
    1.25 +#ifndef RW_VALCMP_H_INCLUDED
    1.26 +#define RW_VALCMP_H_INCLUDED
    1.27 +
    1.28 +#include <testdefs.h>
    1.29 +
    1.30 +#ifdef __SYMBIAN32__
    1.31 +#include<sstream>
    1.32 +#include<iterator>
    1.33 +#include<istream>
    1.34 +#endif
    1.35 +#define CMP_NULTERM   1   /* the first 0 terminates processing */
    1.36 +#define CMP_RETOFF    2   /* return offset of the first mismatch */
    1.37 +#define CMP_NOCASE    4   /* case-insensitive character comparison */
    1.38 +#define CMP_FP        8   /* safe floating pointing comparison */
    1.39 +
    1.40 +
    1.41 +_TEST_EXPORT int
    1.42 +rw_valcmp (const void*, const void*,
    1.43 +           _RWSTD_SIZE_T, _RWSTD_SIZE_T, _RWSTD_SIZE_T, int);
    1.44 +
    1.45 +/**
    1.46 + * Compares the contents of two arrays of objects of integral types,
    1.47 + * possibly of different sizes, for equality, in a strncmp/memcmp
    1.48 + * way.
    1.49 + *
    1.50 + * @param buf1  Pointer to an array of 0 or more objects of integral type.
    1.51 + * @param buf2  Pointer to an array of 0 or more objects of integral type.
    1.52 + * @param nelems  The maximum number of elements to compare.
    1.53 + * @param flags  Bitmap of flags that determine how the objects are
    1.54 + *               compared.
    1.55 + * @return  Returns -1, 0, or +1, depending on whether the first array
    1.56 + *          is less than, equal to, or greater than the second array.
    1.57 + */
    1.58 +
    1.59 +template <class T, class U>
    1.60 +inline int
    1.61 +rw_valcmp (const T*      buf1,
    1.62 +           const U*      buf2,
    1.63 +           _RWSTD_SIZE_T nelems,
    1.64 +           int           flags = 0)
    1.65 +{
    1.66 +    return rw_valcmp (buf1, buf2, nelems, sizeof (T), sizeof (U), flags);
    1.67 +}
    1.68 +
    1.69 +
    1.70 +/**************************************************************************/
    1.71 +
    1.72 +// compares up to a maximum number of characters from the two strings
    1.73 +// posisbly including any embedded NULs (when the cmp_nul bit is set)
    1.74 +// and returns -1, 0, or +1 if the first string compares less, equal,
    1.75 +// or greater, respectively, than the second string, or the offset+1
    1.76 +// of the first mismatched character (when the cmp_off bit is set)
    1.77 +// or 0 otherwise
    1.78 +//
    1.79 +// rw_strncmp(s1, s2) is equivalent to a call to strcmp(s1, s2) when
    1.80 +// the type of s1 and s2 is char*, wcscmp(s1, s2) when the type is
    1.81 +// wchar_t*
    1.82 +//
    1.83 +// rw_strncmp(s1, s2, n) with (n != ~0U) is equivalent to a call to
    1.84 +// strncmp(s1, s2, n) or wcsncmp(s1, s2, n), respectively
    1.85 +//
    1.86 +// rw_strncmp(s1, s2, n, cmp_nul) with (n != ~0U) is equivalent to
    1.87 +// a call to memcmp(s1, s2, n) or wmemcmp(s1, s2, n), respectively
    1.88 +
    1.89 +_TEST_EXPORT int
    1.90 +rw_strncmp (const char*, const char*,
    1.91 +            _RWSTD_SIZE_T = _RWSTD_SIZE_MAX, int = CMP_NULTERM);
    1.92 +
    1.93 +#ifndef _RWSTD_NO_WCHAR_T
    1.94 +
    1.95 +_TEST_EXPORT int
    1.96 +rw_strncmp (const char*, const wchar_t*,
    1.97 +            _RWSTD_SIZE_T = _RWSTD_SIZE_MAX, int = CMP_NULTERM);
    1.98 +
    1.99 +_TEST_EXPORT int
   1.100 +rw_strncmp (const wchar_t*, const char*,
   1.101 +            _RWSTD_SIZE_T = _RWSTD_SIZE_MAX, int = CMP_NULTERM);
   1.102 +
   1.103 +_TEST_EXPORT int
   1.104 +rw_strncmp (const wchar_t*, const wchar_t*,
   1.105 +            _RWSTD_SIZE_T = _RWSTD_SIZE_MAX, int = CMP_NULTERM);
   1.106 +
   1.107 +#endif   // _RWSTD_NO_WCHAR_T
   1.108 +
   1.109 +
   1.110 +/**
   1.111 + * Compares two floating point numbers for equality.
   1.112 + *
   1.113 + * @param x  The left hand side of the comparison.
   1.114 + * @param y  The right hand side of the comparison.
   1.115 + *
   1.116 + * @return  Returns a negative value, 0, or a positive value, depending
   1.117 + *          on whether the first number is less than, equal to, or greater
   1.118 + *          than the second number. The magnitude of the returned value
   1.119 + *          indicates the number of distinct values representable in
   1.120 + *          the type of the number between the two arguments.
   1.121 + */
   1.122 +_TEST_EXPORT int
   1.123 +rw_fltcmp (float x, float y);
   1.124 +
   1.125 +
   1.126 +/**
   1.127 + * @see rw_fltcmp.
   1.128 + */
   1.129 +_TEST_EXPORT int
   1.130 +rw_dblcmp (double x, double y);
   1.131 +
   1.132 +#ifndef _RWSTD_NO_LONG_DOUBLE
   1.133 +
   1.134 +/**
   1.135 + * @see rw_fltcmp.
   1.136 + */
   1.137 +_TEST_EXPORT int
   1.138 +rw_ldblcmp (long double x, long double y);
   1.139 +
   1.140 +#endif   // _RWSTD_NO_LONG_DOUBLE
   1.141 +
   1.142 +#ifdef __SYMBIAN32__
   1.143 +_TEST_EXPORT int 
   1.144 + rw_strcmp (std::basic_string<char>& x ,long double y);
   1.145 + _TEST_EXPORT int 
   1.146 + rw_strcmp (std::basic_string<wchar_t>& x ,long double y);
   1.147 + _TEST_EXPORT
   1.148 + void WCtoC(const wchar_t *wstr, int len, char* str);
   1.149 + #endif
   1.150 +/**************************************************************************/
   1.151 +
   1.152 +/**
   1.153 + * Compares two values of the same type for equality.
   1.154 + *
   1.155 + * @param x  The left hand side of the comparison.
   1.156 + * @param y  The right hand side of the comparison.
   1.157 + *
   1.158 + * @return  Returns 1 if the the values are the same, 0 otherwise.
   1.159 + */
   1.160 +template <class T>
   1.161 +inline int rw_equal (T x, T y)
   1.162 +{
   1.163 +    return x == y;
   1.164 +}
   1.165 +
   1.166 +/**
   1.167 + * @see rw_equal.
   1.168 + */
   1.169 +inline int rw_equal (float x, float y)
   1.170 +{
   1.171 +    return 0 == rw_fltcmp (x, y);
   1.172 +}
   1.173 +
   1.174 +/**
   1.175 + * @see rw_equal.
   1.176 + */
   1.177 +inline int rw_equal (double x, double y)
   1.178 +{
   1.179 +    return 0 == rw_dblcmp (x, y);
   1.180 +}
   1.181 +
   1.182 +#ifndef _RWSTD_NO_LONG_DOUBLE
   1.183 +
   1.184 +/**
   1.185 + * @see rw_equal.
   1.186 + */
   1.187 +inline int rw_equal (long double x, long double y)
   1.188 +{
   1.189 +    return 0 == rw_ldblcmp (x, y);
   1.190 +}
   1.191 +
   1.192 +#endif   // _RWSTD_NO_LONG_DOUBLE
   1.193 +
   1.194 +#endif   // RW_VALCMP_H_INCLUDED