Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
rw_valcmp.h
Go to the documentation of this file.
1
29#ifndef RW_VALCMP_H_INCLUDED
30#define RW_VALCMP_H_INCLUDED
31
32#include <rw_testdefs.h>
33
34
35#define CMP_NULTERM 1 /* the first 0 terminates processing */
36#define CMP_RETOFF 2 /* return offset of the first mismatch */
37#define CMP_NOCASE 4 /* case-insensitive character comparison */
38#define CMP_FP 8 /* safe floating pointing comparison */
39
40
42rw_valcmp (const void*, const void*,
43 _RWSTD_SIZE_T, _RWSTD_SIZE_T, _RWSTD_SIZE_T, int);
44
59template <class T, class U>
60inline int
61rw_valcmp (const T* buf1,
62 const U* buf2,
63 _RWSTD_SIZE_T nelems,
64 int flags = 0)
65{
66 return rw_valcmp (buf1, buf2, nelems, sizeof (T), sizeof (U), flags);
67}
68
69
70
72// compares up to a maximum number of characters from the two strings
73// posisbly including any embedded NULs (when the cmp_nul bit is set)
74// and returns -1, 0, or +1 if the first string compares less, equal,
75// or greater, respectively, than the second string, or the offset+1
76// of the first mismatched character (when the cmp_off bit is set)
77// or 0 otherwise
78//
79// rw_strncmp(s1, s2) is equivalent to a call to strcmp(s1, s2) when
80// the type of s1 and s2 is char*, wcscmp(s1, s2) when the type is
81// wchar_t*
82//
83// rw_strncmp(s1, s2, n) with (n != ~0U) is equivalent to a call to
84// strncmp(s1, s2, n) or wcsncmp(s1, s2, n), respectively
85//
86// rw_strncmp(s1, s2, n, cmp_nul) with (n != ~0U) is equivalent to
87// a call to memcmp(s1, s2, n) or wmemcmp(s1, s2, n), respectively
88
90rw_strncmp (const char*, const char*,
91 _RWSTD_SIZE_T = _RWSTD_SIZE_MAX, int = CMP_NULTERM);
92
93#ifndef _RWSTD_NO_WCHAR_T
94
96rw_strncmp (const char*, const wchar_t*,
97 _RWSTD_SIZE_T = _RWSTD_SIZE_MAX, int = CMP_NULTERM);
98
100rw_strncmp (const wchar_t*, const char*,
101 _RWSTD_SIZE_T = _RWSTD_SIZE_MAX, int = CMP_NULTERM);
102
103_TEST_EXPORT int
104rw_strncmp (const wchar_t*, const wchar_t*,
105 _RWSTD_SIZE_T = _RWSTD_SIZE_MAX, int = CMP_NULTERM);
106
107#endif // _RWSTD_NO_WCHAR_T
108
109
122_TEST_EXPORT int
123rw_fltcmp (float x, float y);
124
125
129_TEST_EXPORT int
130rw_dblcmp (double x, double y);
131
132#ifndef _RWSTD_NO_LONG_DOUBLE
133
137_TEST_EXPORT int
138rw_ldblcmp (long double x, long double y);
139
140#endif // _RWSTD_NO_LONG_DOUBLE
141
142
152template <class T>
153inline int rw_equal (T x, T y)
154{
155 return x == y;
156}
157
161inline int rw_equal (float x, float y)
162{
163 return 0 == rw_fltcmp (x, y);
164}
165
169inline int rw_equal (double x, double y)
170{
171 return 0 == rw_dblcmp (x, y);
172}
173
174#ifndef _RWSTD_NO_LONG_DOUBLE
175
179inline int rw_equal (long double x, long double y)
180{
181 return 0 == rw_ldblcmp (x, y);
182}
183
184#endif // _RWSTD_NO_LONG_DOUBLE
185
186#endif // RW_VALCMP_H_INCLUDED
#define T
Definition 17.names.cpp:163
#define y
Definition 17.names.cpp:141
#define x
Definition 17.names.cpp:140
#define U
Definition 17.names.cpp:164
#define flags
#define _TEST_EXPORT
Definition rw_testdefs.h:55
_TEST_EXPORT int rw_valcmp(const void *, const void *, _RWSTD_SIZE_T, _RWSTD_SIZE_T, _RWSTD_SIZE_T, int)
int rw_equal(T x, T y)
Definition rw_valcmp.h:153
_TEST_EXPORT int rw_strncmp(const char *, const char *, _RWSTD_SIZE_T=_RWSTD_SIZE_MAX, int=CMP_NULTERM)
#define CMP_NULTERM
Definition rw_valcmp.h:35
_TEST_EXPORT int rw_fltcmp(float x, float y)
Definition valcmp.cpp:712
_TEST_EXPORT int rw_ldblcmp(long double x, long double y)
Definition valcmp.cpp:816
_TEST_EXPORT int rw_dblcmp(double x, double y)
Definition valcmp.cpp:753