stdcpp/tsrc/Stdcpp_test/stdcxx/include/valcmp.h
changeset 31 ce057bb09d0b
parent 0 e4d67989cc36
equal deleted inserted replaced
30:e20de85af2ee 31:ce057bb09d0b
       
     1 /************************************************************************
       
     2  *
       
     3  * valcmp.h - declarations of the rw_valcmp() family of helper functions
       
     4  *
       
     5  * $Id: valcmp.h 351516 2005-12-01 23:21:09Z sebor $
       
     6  *
       
     7  ************************************************************************
       
     8  *
       
     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
       
    18  * the License.
       
    19  * 
       
    20  **************************************************************************/
       
    21 
       
    22 #ifndef RW_VALCMP_H_INCLUDED
       
    23 #define RW_VALCMP_H_INCLUDED
       
    24 
       
    25 #include <testdefs.h>
       
    26 
       
    27 #ifdef __SYMBIAN32__
       
    28 #include<sstream>
       
    29 #include<iterator>
       
    30 #include<istream>
       
    31 #endif
       
    32 #define CMP_NULTERM   1   /* the first 0 terminates processing */
       
    33 #define CMP_RETOFF    2   /* return offset of the first mismatch */
       
    34 #define CMP_NOCASE    4   /* case-insensitive character comparison */
       
    35 #define CMP_FP        8   /* safe floating pointing comparison */
       
    36 
       
    37 
       
    38 _TEST_EXPORT int
       
    39 rw_valcmp (const void*, const void*,
       
    40            _RWSTD_SIZE_T, _RWSTD_SIZE_T, _RWSTD_SIZE_T, int);
       
    41 
       
    42 /**
       
    43  * Compares the contents of two arrays of objects of integral types,
       
    44  * possibly of different sizes, for equality, in a strncmp/memcmp
       
    45  * way.
       
    46  *
       
    47  * @param buf1  Pointer to an array of 0 or more objects of integral type.
       
    48  * @param buf2  Pointer to an array of 0 or more objects of integral type.
       
    49  * @param nelems  The maximum number of elements to compare.
       
    50  * @param flags  Bitmap of flags that determine how the objects are
       
    51  *               compared.
       
    52  * @return  Returns -1, 0, or +1, depending on whether the first array
       
    53  *          is less than, equal to, or greater than the second array.
       
    54  */
       
    55 
       
    56 template <class T, class U>
       
    57 inline int
       
    58 rw_valcmp (const T*      buf1,
       
    59            const U*      buf2,
       
    60            _RWSTD_SIZE_T nelems,
       
    61            int           flags = 0)
       
    62 {
       
    63     return rw_valcmp (buf1, buf2, nelems, sizeof (T), sizeof (U), flags);
       
    64 }
       
    65 
       
    66 
       
    67 /**************************************************************************/
       
    68 
       
    69 // compares up to a maximum number of characters from the two strings
       
    70 // posisbly including any embedded NULs (when the cmp_nul bit is set)
       
    71 // and returns -1, 0, or +1 if the first string compares less, equal,
       
    72 // or greater, respectively, than the second string, or the offset+1
       
    73 // of the first mismatched character (when the cmp_off bit is set)
       
    74 // or 0 otherwise
       
    75 //
       
    76 // rw_strncmp(s1, s2) is equivalent to a call to strcmp(s1, s2) when
       
    77 // the type of s1 and s2 is char*, wcscmp(s1, s2) when the type is
       
    78 // wchar_t*
       
    79 //
       
    80 // rw_strncmp(s1, s2, n) with (n != ~0U) is equivalent to a call to
       
    81 // strncmp(s1, s2, n) or wcsncmp(s1, s2, n), respectively
       
    82 //
       
    83 // rw_strncmp(s1, s2, n, cmp_nul) with (n != ~0U) is equivalent to
       
    84 // a call to memcmp(s1, s2, n) or wmemcmp(s1, s2, n), respectively
       
    85 
       
    86 _TEST_EXPORT int
       
    87 rw_strncmp (const char*, const char*,
       
    88             _RWSTD_SIZE_T = _RWSTD_SIZE_MAX, int = CMP_NULTERM);
       
    89 
       
    90 #ifndef _RWSTD_NO_WCHAR_T
       
    91 
       
    92 _TEST_EXPORT int
       
    93 rw_strncmp (const char*, const wchar_t*,
       
    94             _RWSTD_SIZE_T = _RWSTD_SIZE_MAX, int = CMP_NULTERM);
       
    95 
       
    96 _TEST_EXPORT int
       
    97 rw_strncmp (const wchar_t*, const char*,
       
    98             _RWSTD_SIZE_T = _RWSTD_SIZE_MAX, int = CMP_NULTERM);
       
    99 
       
   100 _TEST_EXPORT int
       
   101 rw_strncmp (const wchar_t*, const wchar_t*,
       
   102             _RWSTD_SIZE_T = _RWSTD_SIZE_MAX, int = CMP_NULTERM);
       
   103 
       
   104 #endif   // _RWSTD_NO_WCHAR_T
       
   105 
       
   106 
       
   107 /**
       
   108  * Compares two floating point numbers for equality.
       
   109  *
       
   110  * @param x  The left hand side of the comparison.
       
   111  * @param y  The right hand side of the comparison.
       
   112  *
       
   113  * @return  Returns a negative value, 0, or a positive value, depending
       
   114  *          on whether the first number is less than, equal to, or greater
       
   115  *          than the second number. The magnitude of the returned value
       
   116  *          indicates the number of distinct values representable in
       
   117  *          the type of the number between the two arguments.
       
   118  */
       
   119 _TEST_EXPORT int
       
   120 rw_fltcmp (float x, float y);
       
   121 
       
   122 
       
   123 /**
       
   124  * @see rw_fltcmp.
       
   125  */
       
   126 _TEST_EXPORT int
       
   127 rw_dblcmp (double x, double y);
       
   128 
       
   129 #ifndef _RWSTD_NO_LONG_DOUBLE
       
   130 
       
   131 /**
       
   132  * @see rw_fltcmp.
       
   133  */
       
   134 _TEST_EXPORT int
       
   135 rw_ldblcmp (long double x, long double y);
       
   136 
       
   137 #endif   // _RWSTD_NO_LONG_DOUBLE
       
   138 
       
   139 #ifdef __SYMBIAN32__
       
   140 _TEST_EXPORT int 
       
   141  rw_strcmp (std::basic_string<char>& x ,long double y);
       
   142  _TEST_EXPORT int 
       
   143  rw_strcmp (std::basic_string<wchar_t>& x ,long double y);
       
   144  _TEST_EXPORT
       
   145  void WCtoC(const wchar_t *wstr, int len, char* str);
       
   146  #endif
       
   147 /**************************************************************************/
       
   148 
       
   149 /**
       
   150  * Compares two values of the same type for equality.
       
   151  *
       
   152  * @param x  The left hand side of the comparison.
       
   153  * @param y  The right hand side of the comparison.
       
   154  *
       
   155  * @return  Returns 1 if the the values are the same, 0 otherwise.
       
   156  */
       
   157 template <class T>
       
   158 inline int rw_equal (T x, T y)
       
   159 {
       
   160     return x == y;
       
   161 }
       
   162 
       
   163 /**
       
   164  * @see rw_equal.
       
   165  */
       
   166 inline int rw_equal (float x, float y)
       
   167 {
       
   168     return 0 == rw_fltcmp (x, y);
       
   169 }
       
   170 
       
   171 /**
       
   172  * @see rw_equal.
       
   173  */
       
   174 inline int rw_equal (double x, double y)
       
   175 {
       
   176     return 0 == rw_dblcmp (x, y);
       
   177 }
       
   178 
       
   179 #ifndef _RWSTD_NO_LONG_DOUBLE
       
   180 
       
   181 /**
       
   182  * @see rw_equal.
       
   183  */
       
   184 inline int rw_equal (long double x, long double y)
       
   185 {
       
   186     return 0 == rw_ldblcmp (x, y);
       
   187 }
       
   188 
       
   189 #endif   // _RWSTD_NO_LONG_DOUBLE
       
   190 
       
   191 #endif   // RW_VALCMP_H_INCLUDED