Update contrib.
1 /************************************************************************
3 * valcmp.h - declarations of the rw_valcmp() family of helper functions
5 * $Id: valcmp.h 351516 2005-12-01 23:21:09Z 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 #ifndef RW_VALCMP_H_INCLUDED
23 #define RW_VALCMP_H_INCLUDED
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 */
39 rw_valcmp (const void*, const void*,
40 _RWSTD_SIZE_T, _RWSTD_SIZE_T, _RWSTD_SIZE_T, int);
43 * Compares the contents of two arrays of objects of integral types,
44 * possibly of different sizes, for equality, in a strncmp/memcmp
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
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.
56 template <class T, class U>
58 rw_valcmp (const T* buf1,
63 return rw_valcmp (buf1, buf2, nelems, sizeof (T), sizeof (U), flags);
67 /**************************************************************************/
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)
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
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
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
87 rw_strncmp (const char*, const char*,
88 _RWSTD_SIZE_T = _RWSTD_SIZE_MAX, int = CMP_NULTERM);
90 #ifndef _RWSTD_NO_WCHAR_T
93 rw_strncmp (const char*, const wchar_t*,
94 _RWSTD_SIZE_T = _RWSTD_SIZE_MAX, int = CMP_NULTERM);
97 rw_strncmp (const wchar_t*, const char*,
98 _RWSTD_SIZE_T = _RWSTD_SIZE_MAX, int = CMP_NULTERM);
101 rw_strncmp (const wchar_t*, const wchar_t*,
102 _RWSTD_SIZE_T = _RWSTD_SIZE_MAX, int = CMP_NULTERM);
104 #endif // _RWSTD_NO_WCHAR_T
108 * Compares two floating point numbers for equality.
110 * @param x The left hand side of the comparison.
111 * @param y The right hand side of the comparison.
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.
120 rw_fltcmp (float x, float y);
127 rw_dblcmp (double x, double y);
129 #ifndef _RWSTD_NO_LONG_DOUBLE
135 rw_ldblcmp (long double x, long double y);
137 #endif // _RWSTD_NO_LONG_DOUBLE
141 rw_strcmp (std::basic_string<char>& x ,long double y);
143 rw_strcmp (std::basic_string<wchar_t>& x ,long double y);
145 void WCtoC(const wchar_t *wstr, int len, char* str);
147 /**************************************************************************/
150 * Compares two values of the same type for equality.
152 * @param x The left hand side of the comparison.
153 * @param y The right hand side of the comparison.
155 * @return Returns 1 if the the values are the same, 0 otherwise.
158 inline int rw_equal (T x, T y)
166 inline int rw_equal (float x, float y)
168 return 0 == rw_fltcmp (x, y);
174 inline int rw_equal (double x, double y)
176 return 0 == rw_dblcmp (x, y);
179 #ifndef _RWSTD_NO_LONG_DOUBLE
184 inline int rw_equal (long double x, long double y)
186 return 0 == rw_ldblcmp (x, y);
189 #endif // _RWSTD_NO_LONG_DOUBLE
191 #endif // RW_VALCMP_H_INCLUDED