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