OLD | NEW |
(Empty) | |
| 1 /* |
| 2 ****************************************************************************** |
| 3 * |
| 4 * Copyright (C) 1997-2010, International Business Machines |
| 5 * Corporation and others. All Rights Reserved. |
| 6 * |
| 7 ****************************************************************************** |
| 8 * |
| 9 * FILE NAME : putilimp.h |
| 10 * |
| 11 * Date Name Description |
| 12 * 10/17/04 grhoten Move internal functions from putil.h to this file. |
| 13 ****************************************************************************** |
| 14 */ |
| 15 |
| 16 #ifndef PUTILIMP_H |
| 17 #define PUTILIMP_H |
| 18 |
| 19 #include "unicode/utypes.h" |
| 20 #include "unicode/putil.h" |
| 21 |
| 22 /*==========================================================================*/ |
| 23 /* Platform utilities */ |
| 24 /*==========================================================================*/ |
| 25 |
| 26 /** |
| 27 * Platform utilities isolates the platform dependencies of the |
| 28 * libarary. For each platform which this code is ported to, these |
| 29 * functions may have to be re-implemented. |
| 30 */ |
| 31 |
| 32 /** |
| 33 * Floating point utility to determine if a double is Not a Number (NaN). |
| 34 * @internal |
| 35 */ |
| 36 U_INTERNAL UBool U_EXPORT2 uprv_isNaN(double d); |
| 37 /** |
| 38 * Floating point utility to determine if a double has an infinite value. |
| 39 * @internal |
| 40 */ |
| 41 U_INTERNAL UBool U_EXPORT2 uprv_isInfinite(double d); |
| 42 /** |
| 43 * Floating point utility to determine if a double has a positive infinite value
. |
| 44 * @internal |
| 45 */ |
| 46 U_INTERNAL UBool U_EXPORT2 uprv_isPositiveInfinity(double d); |
| 47 /** |
| 48 * Floating point utility to determine if a double has a negative infinite value
. |
| 49 * @internal |
| 50 */ |
| 51 U_INTERNAL UBool U_EXPORT2 uprv_isNegativeInfinity(double d); |
| 52 /** |
| 53 * Floating point utility that returns a Not a Number (NaN) value. |
| 54 * @internal |
| 55 */ |
| 56 U_INTERNAL double U_EXPORT2 uprv_getNaN(void); |
| 57 /** |
| 58 * Floating point utility that returns an infinite value. |
| 59 * @internal |
| 60 */ |
| 61 U_INTERNAL double U_EXPORT2 uprv_getInfinity(void); |
| 62 |
| 63 /** |
| 64 * Floating point utility to truncate a double. |
| 65 * @internal |
| 66 */ |
| 67 U_INTERNAL double U_EXPORT2 uprv_trunc(double d); |
| 68 /** |
| 69 * Floating point utility to calculate the floor of a double. |
| 70 * @internal |
| 71 */ |
| 72 U_INTERNAL double U_EXPORT2 uprv_floor(double d); |
| 73 /** |
| 74 * Floating point utility to calculate the ceiling of a double. |
| 75 * @internal |
| 76 */ |
| 77 U_INTERNAL double U_EXPORT2 uprv_ceil(double d); |
| 78 /** |
| 79 * Floating point utility to calculate the absolute value of a double. |
| 80 * @internal |
| 81 */ |
| 82 U_INTERNAL double U_EXPORT2 uprv_fabs(double d); |
| 83 /** |
| 84 * Floating point utility to calculate the fractional and integer parts of a dou
ble. |
| 85 * @internal |
| 86 */ |
| 87 U_INTERNAL double U_EXPORT2 uprv_modf(double d, double* pinteger); |
| 88 /** |
| 89 * Floating point utility to calculate the remainder of a double divided by anot
her double. |
| 90 * @internal |
| 91 */ |
| 92 U_INTERNAL double U_EXPORT2 uprv_fmod(double d, double y); |
| 93 /** |
| 94 * Floating point utility to calculate d to the power of exponent (d^exponent). |
| 95 * @internal |
| 96 */ |
| 97 U_INTERNAL double U_EXPORT2 uprv_pow(double d, double exponent); |
| 98 /** |
| 99 * Floating point utility to calculate 10 to the power of exponent (10^exponent)
. |
| 100 * @internal |
| 101 */ |
| 102 U_INTERNAL double U_EXPORT2 uprv_pow10(int32_t exponent); |
| 103 /** |
| 104 * Floating point utility to calculate the maximum value of two doubles. |
| 105 * @internal |
| 106 */ |
| 107 U_INTERNAL double U_EXPORT2 uprv_fmax(double d, double y); |
| 108 /** |
| 109 * Floating point utility to calculate the minimum value of two doubles. |
| 110 * @internal |
| 111 */ |
| 112 U_INTERNAL double U_EXPORT2 uprv_fmin(double d, double y); |
| 113 /** |
| 114 * Private utility to calculate the maximum value of two integers. |
| 115 * @internal |
| 116 */ |
| 117 U_INTERNAL int32_t U_EXPORT2 uprv_max(int32_t d, int32_t y); |
| 118 /** |
| 119 * Private utility to calculate the minimum value of two integers. |
| 120 * @internal |
| 121 */ |
| 122 U_INTERNAL int32_t U_EXPORT2 uprv_min(int32_t d, int32_t y); |
| 123 |
| 124 #if U_IS_BIG_ENDIAN |
| 125 # define uprv_isNegative(number) (*((signed char *)&(number))<0) |
| 126 #else |
| 127 # define uprv_isNegative(number) (*((signed char *)&(number)+sizeof(number)-1)
<0) |
| 128 #endif |
| 129 |
| 130 /** |
| 131 * Return the largest positive number that can be represented by an integer |
| 132 * type of arbitrary bit length. |
| 133 * @internal |
| 134 */ |
| 135 U_INTERNAL double U_EXPORT2 uprv_maxMantissa(void); |
| 136 |
| 137 /** |
| 138 * Floating point utility to calculate the logarithm of a double. |
| 139 * @internal |
| 140 */ |
| 141 U_INTERNAL double U_EXPORT2 uprv_log(double d); |
| 142 |
| 143 /** |
| 144 * Does common notion of rounding e.g. uprv_floor(x + 0.5); |
| 145 * @param x the double number |
| 146 * @return the rounded double |
| 147 * @internal |
| 148 */ |
| 149 U_INTERNAL double U_EXPORT2 uprv_round(double x); |
| 150 |
| 151 #if 0 |
| 152 /** |
| 153 * Returns the number of digits after the decimal point in a double number x. |
| 154 * |
| 155 * @param x the double number |
| 156 * @return the number of digits after the decimal point in a double number x. |
| 157 * @internal |
| 158 */ |
| 159 /*U_INTERNAL int32_t U_EXPORT2 uprv_digitsAfterDecimal(double x);*/ |
| 160 #endif |
| 161 |
| 162 /** |
| 163 * Time zone utilities |
| 164 * |
| 165 * Wrappers for C runtime library functions relating to timezones. |
| 166 * The t_tzset() function (similar to tzset) uses the current setting |
| 167 * of the environment variable TZ to assign values to three global |
| 168 * variables: daylight, timezone, and tzname. These variables have the |
| 169 * following meanings, and are declared in <time.h>. |
| 170 * |
| 171 * daylight Nonzero if daylight-saving-time zone (DST) is specified |
| 172 * in TZ; otherwise, 0. Default value is 1. |
| 173 * timezone Difference in seconds between coordinated universal |
| 174 * time and local time. E.g., -28,800 for PST (GMT-8hrs) |
| 175 * tzname(0) Three-letter time-zone name derived from TZ environment |
| 176 * variable. E.g., "PST". |
| 177 * tzname(1) Three-letter DST zone name derived from TZ environment |
| 178 * variable. E.g., "PDT". If DST zone is omitted from TZ, |
| 179 * tzname(1) is an empty string. |
| 180 * |
| 181 * Notes: For example, to set the TZ environment variable to correspond |
| 182 * to the current time zone in Germany, you can use one of the |
| 183 * following statements: |
| 184 * |
| 185 * set TZ=GST1GDT |
| 186 * set TZ=GST+1GDT |
| 187 * |
| 188 * If the TZ value is not set, t_tzset() attempts to use the time zone |
| 189 * information specified by the operating system. Under Windows NT |
| 190 * and Windows 95, this information is specified in the Control Panel's |
| 191 * Date/Time application. |
| 192 * @internal |
| 193 */ |
| 194 U_INTERNAL void U_EXPORT2 uprv_tzset(void); |
| 195 |
| 196 /** |
| 197 * Difference in seconds between coordinated universal |
| 198 * time and local time. E.g., -28,800 for PST (GMT-8hrs) |
| 199 * @return the difference in seconds between coordinated universal time and loca
l time. |
| 200 * @internal |
| 201 */ |
| 202 U_INTERNAL int32_t U_EXPORT2 uprv_timezone(void); |
| 203 |
| 204 /** |
| 205 * tzname(0) Three-letter time-zone name derived from TZ environment |
| 206 * variable. E.g., "PST". |
| 207 * tzname(1) Three-letter DST zone name derived from TZ environment |
| 208 * variable. E.g., "PDT". If DST zone is omitted from TZ, |
| 209 * tzname(1) is an empty string. |
| 210 * @internal |
| 211 */ |
| 212 U_INTERNAL const char* U_EXPORT2 uprv_tzname(int n); |
| 213 |
| 214 /** |
| 215 * Get UTC (GMT) time measured in milliseconds since 0:00 on 1/1/1970. |
| 216 * This function is affected by 'faketime' and should be the bottleneck for all
user-visible ICU time functions. |
| 217 * @return the UTC time measured in milliseconds |
| 218 * @internal |
| 219 */ |
| 220 U_INTERNAL UDate U_EXPORT2 uprv_getUTCtime(void); |
| 221 |
| 222 /** |
| 223 * Get UTC (GMT) time measured in milliseconds since 0:00 on 1/1/1970. |
| 224 * This function is not affected by 'faketime', so it should only be used by low
level test functions- not by anything that |
| 225 * exposes time to the end user. |
| 226 * @return the UTC time measured in milliseconds |
| 227 * @internal |
| 228 */ |
| 229 U_INTERNAL UDate U_EXPORT2 uprv_getRawUTCtime(void); |
| 230 |
| 231 /** |
| 232 * Determine whether a pathname is absolute or not, as defined by the platform. |
| 233 * @param path Pathname to test |
| 234 * @return TRUE if the path is absolute |
| 235 * @internal (ICU 3.0) |
| 236 */ |
| 237 U_INTERNAL UBool U_EXPORT2 uprv_pathIsAbsolute(const char *path); |
| 238 |
| 239 /** |
| 240 * Use U_MAX_PTR instead of this function. |
| 241 * @param void pointer to test |
| 242 * @return the largest possible pointer greater than the base |
| 243 * @internal (ICU 3.8) |
| 244 */ |
| 245 U_INTERNAL void * U_EXPORT2 uprv_maximumPtr(void *base); |
| 246 |
| 247 /** |
| 248 * Maximum value of a (void*) - use to indicate the limit of an 'infinite' buffe
r. |
| 249 * In fact, buffer sizes must not exceed 2GB so that the difference between |
| 250 * the buffer limit and the buffer start can be expressed in an int32_t. |
| 251 * |
| 252 * The definition of U_MAX_PTR must fulfill the following conditions: |
| 253 * - return the largest possible pointer greater than base |
| 254 * - return a valid pointer according to the machine architecture (AS/400, 64-bi
t, etc.) |
| 255 * - avoid wrapping around at high addresses |
| 256 * - make sure that the returned pointer is not farther from base than 0x7ffffff
f |
| 257 * |
| 258 * @param base The beginning of a buffer to find the maximum offset from |
| 259 * @internal |
| 260 */ |
| 261 #ifndef U_MAX_PTR |
| 262 # if defined(OS390) && !defined(_LP64) |
| 263 /* We have 31-bit pointers. */ |
| 264 # define U_MAX_PTR(base) ((void *)0x7fffffff) |
| 265 # elif defined(OS400) |
| 266 # define U_MAX_PTR(base) uprv_maximumPtr((void *)base) |
| 267 # elif defined(__GNUC__) && __GNUC__ >= 4 |
| 268 /* |
| 269 * Due to a compiler optimization bug, gcc 4 causes test failures when doing |
| 270 * this math arithmetic on pointers on some platforms. It seems like the |
| 271 * pointers are considered signed instead of unsigned. The uintptr_t type |
| 272 * isn't available on all platforms (i.e MSVC 6) and pointers aren't always |
| 273 * a scalar value (i.e. i5/OS see uprv_maximumPtr function). |
| 274 */ |
| 275 # define U_MAX_PTR(base) \ |
| 276 ((void *)(((uintptr_t)(base)+0x7fffffffu) > (uintptr_t)(base) \ |
| 277 ? ((uintptr_t)(base)+0x7fffffffu) \ |
| 278 : (uintptr_t)-1)) |
| 279 # else |
| 280 # define U_MAX_PTR(base) \ |
| 281 ((char *)(((char *)(base)+0x7fffffffu) > (char *)(base) \ |
| 282 ? ((char *)(base)+0x7fffffffu) \ |
| 283 : (char *)-1)) |
| 284 # endif |
| 285 #endif |
| 286 |
| 287 #if U_ENABLE_DYLOAD |
| 288 /* Dynamic Library Functions */ |
| 289 |
| 290 /** |
| 291 * Load a library |
| 292 * @internal (ICU 4.4) |
| 293 */ |
| 294 U_INTERNAL void * U_EXPORT2 uprv_dl_open(const char *libName, UErrorCode *status
); |
| 295 |
| 296 /** |
| 297 * Close a library |
| 298 * @internal (ICU 4.4) |
| 299 */ |
| 300 U_INTERNAL void U_EXPORT2 uprv_dl_close( void *lib, UErrorCode *status); |
| 301 |
| 302 /** |
| 303 * Extract a symbol from a library |
| 304 * @internal (ICU 4.4) |
| 305 */ |
| 306 U_INTERNAL void * U_EXPORT2 uprv_dl_sym( void *lib, const char *symbolName, UErr
orCode *status); |
| 307 |
| 308 #endif |
| 309 |
| 310 #endif |
OLD | NEW |