sl@0: /************************************************************************ sl@0: * sl@0: * valcmp.h - declarations of the rw_valcmp() family of helper functions sl@0: * sl@0: * $Id: valcmp.h 351516 2005-12-01 23:21:09Z sebor $ sl@0: * sl@0: ************************************************************************ sl@0: * sl@0: * Copyright (c) 1994-2005 Quovadx, Inc., acting through its Rogue Wave sl@0: * Software division. Licensed under the Apache License, Version 2.0 (the sl@0: * "License"); you may not use this file except in compliance with the sl@0: * License. You may obtain a copy of the License at sl@0: * http://www.apache.org/licenses/LICENSE-2.0. Unless required by sl@0: * applicable law or agreed to in writing, software distributed under sl@0: * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR sl@0: * CONDITIONS OF ANY KIND, either express or implied. See the License sl@0: * for the specific language governing permissions and limitations under sl@0: * the License. sl@0: * sl@0: **************************************************************************/ sl@0: sl@0: #ifndef RW_VALCMP_H_INCLUDED sl@0: #define RW_VALCMP_H_INCLUDED sl@0: sl@0: #include sl@0: sl@0: #ifdef __SYMBIAN32__ sl@0: #include sl@0: #include sl@0: #include sl@0: #endif sl@0: #define CMP_NULTERM 1 /* the first 0 terminates processing */ sl@0: #define CMP_RETOFF 2 /* return offset of the first mismatch */ sl@0: #define CMP_NOCASE 4 /* case-insensitive character comparison */ sl@0: #define CMP_FP 8 /* safe floating pointing comparison */ sl@0: sl@0: sl@0: _TEST_EXPORT int sl@0: rw_valcmp (const void*, const void*, sl@0: _RWSTD_SIZE_T, _RWSTD_SIZE_T, _RWSTD_SIZE_T, int); sl@0: sl@0: /** sl@0: * Compares the contents of two arrays of objects of integral types, sl@0: * possibly of different sizes, for equality, in a strncmp/memcmp sl@0: * way. sl@0: * sl@0: * @param buf1 Pointer to an array of 0 or more objects of integral type. sl@0: * @param buf2 Pointer to an array of 0 or more objects of integral type. sl@0: * @param nelems The maximum number of elements to compare. sl@0: * @param flags Bitmap of flags that determine how the objects are sl@0: * compared. sl@0: * @return Returns -1, 0, or +1, depending on whether the first array sl@0: * is less than, equal to, or greater than the second array. sl@0: */ sl@0: sl@0: template sl@0: inline int sl@0: rw_valcmp (const T* buf1, sl@0: const U* buf2, sl@0: _RWSTD_SIZE_T nelems, sl@0: int flags = 0) sl@0: { sl@0: return rw_valcmp (buf1, buf2, nelems, sizeof (T), sizeof (U), flags); sl@0: } sl@0: sl@0: sl@0: /**************************************************************************/ sl@0: sl@0: // compares up to a maximum number of characters from the two strings sl@0: // posisbly including any embedded NULs (when the cmp_nul bit is set) sl@0: // and returns -1, 0, or +1 if the first string compares less, equal, sl@0: // or greater, respectively, than the second string, or the offset+1 sl@0: // of the first mismatched character (when the cmp_off bit is set) sl@0: // or 0 otherwise sl@0: // sl@0: // rw_strncmp(s1, s2) is equivalent to a call to strcmp(s1, s2) when sl@0: // the type of s1 and s2 is char*, wcscmp(s1, s2) when the type is sl@0: // wchar_t* sl@0: // sl@0: // rw_strncmp(s1, s2, n) with (n != ~0U) is equivalent to a call to sl@0: // strncmp(s1, s2, n) or wcsncmp(s1, s2, n), respectively sl@0: // sl@0: // rw_strncmp(s1, s2, n, cmp_nul) with (n != ~0U) is equivalent to sl@0: // a call to memcmp(s1, s2, n) or wmemcmp(s1, s2, n), respectively sl@0: sl@0: _TEST_EXPORT int sl@0: rw_strncmp (const char*, const char*, sl@0: _RWSTD_SIZE_T = _RWSTD_SIZE_MAX, int = CMP_NULTERM); sl@0: sl@0: #ifndef _RWSTD_NO_WCHAR_T sl@0: sl@0: _TEST_EXPORT int sl@0: rw_strncmp (const char*, const wchar_t*, sl@0: _RWSTD_SIZE_T = _RWSTD_SIZE_MAX, int = CMP_NULTERM); sl@0: sl@0: _TEST_EXPORT int sl@0: rw_strncmp (const wchar_t*, const char*, sl@0: _RWSTD_SIZE_T = _RWSTD_SIZE_MAX, int = CMP_NULTERM); sl@0: sl@0: _TEST_EXPORT int sl@0: rw_strncmp (const wchar_t*, const wchar_t*, sl@0: _RWSTD_SIZE_T = _RWSTD_SIZE_MAX, int = CMP_NULTERM); sl@0: sl@0: #endif // _RWSTD_NO_WCHAR_T sl@0: sl@0: sl@0: /** sl@0: * Compares two floating point numbers for equality. sl@0: * sl@0: * @param x The left hand side of the comparison. sl@0: * @param y The right hand side of the comparison. sl@0: * sl@0: * @return Returns a negative value, 0, or a positive value, depending sl@0: * on whether the first number is less than, equal to, or greater sl@0: * than the second number. The magnitude of the returned value sl@0: * indicates the number of distinct values representable in sl@0: * the type of the number between the two arguments. sl@0: */ sl@0: _TEST_EXPORT int sl@0: rw_fltcmp (float x, float y); sl@0: sl@0: sl@0: /** sl@0: * @see rw_fltcmp. sl@0: */ sl@0: _TEST_EXPORT int sl@0: rw_dblcmp (double x, double y); sl@0: sl@0: #ifndef _RWSTD_NO_LONG_DOUBLE sl@0: sl@0: /** sl@0: * @see rw_fltcmp. sl@0: */ sl@0: _TEST_EXPORT int sl@0: rw_ldblcmp (long double x, long double y); sl@0: sl@0: #endif // _RWSTD_NO_LONG_DOUBLE sl@0: sl@0: #ifdef __SYMBIAN32__ sl@0: _TEST_EXPORT int sl@0: rw_strcmp (std::basic_string& x ,long double y); sl@0: _TEST_EXPORT int sl@0: rw_strcmp (std::basic_string& x ,long double y); sl@0: _TEST_EXPORT sl@0: void WCtoC(const wchar_t *wstr, int len, char* str); sl@0: #endif sl@0: /**************************************************************************/ sl@0: sl@0: /** sl@0: * Compares two values of the same type for equality. sl@0: * sl@0: * @param x The left hand side of the comparison. sl@0: * @param y The right hand side of the comparison. sl@0: * sl@0: * @return Returns 1 if the the values are the same, 0 otherwise. sl@0: */ sl@0: template sl@0: inline int rw_equal (T x, T y) sl@0: { sl@0: return x == y; sl@0: } sl@0: sl@0: /** sl@0: * @see rw_equal. sl@0: */ sl@0: inline int rw_equal (float x, float y) sl@0: { sl@0: return 0 == rw_fltcmp (x, y); sl@0: } sl@0: sl@0: /** sl@0: * @see rw_equal. sl@0: */ sl@0: inline int rw_equal (double x, double y) sl@0: { sl@0: return 0 == rw_dblcmp (x, y); sl@0: } sl@0: sl@0: #ifndef _RWSTD_NO_LONG_DOUBLE sl@0: sl@0: /** sl@0: * @see rw_equal. sl@0: */ sl@0: inline int rw_equal (long double x, long double y) sl@0: { sl@0: return 0 == rw_ldblcmp (x, y); sl@0: } sl@0: sl@0: #endif // _RWSTD_NO_LONG_DOUBLE sl@0: sl@0: #endif // RW_VALCMP_H_INCLUDED