1 /******************************************************************************** 2 * * 3 * FOX Definitions, Types, and Macros * 4 * * 5 ********************************************************************************* 6 * Copyright (C) 1997,2020 by Jeroen van der Zijp. All Rights Reserved. * 7 ********************************************************************************* 8 * This library is free software; you can redistribute it and/or modify * 9 * it under the terms of the GNU Lesser General Public License as published by * 10 * the Free Software Foundation; either version 3 of the License, or * 11 * (at your option) any later version. * 12 * * 13 * This library is distributed in the hope that it will be useful, * 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 16 * GNU Lesser General Public License for more details. * 17 * * 18 * You should have received a copy of the GNU Lesser General Public License * 19 * along with this program. If not, see <http://www.gnu.org/licenses/> * 20 ********************************************************************************/ 21 #ifndef FXDEFS_H 22 #define FXDEFS_H 23 24 25 26 /******************************** Definitions ********************************/ 27 28 // Placement new 29 #include <new> 30 31 32 // Path separator 33 #ifdef WIN32 34 #define PATHSEP '\\' 35 #define PATHSEPSTRING "\\" 36 #define PATHLISTSEP ';' 37 #define PATHLISTSEPSTRING ";" 38 #define ISPATHSEP(c) ((c)=='\\' || (c)=='/') 39 #else 40 #define PATHSEP '/' 41 #define PATHSEPSTRING "/" 42 #define PATHLISTSEP ':' 43 #define PATHLISTSEPSTRING ":" 44 #define ISPATHSEP(c) ((c)=='/') 45 #endif 46 47 48 // End Of Line 49 #ifdef WIN32 50 #define ENDLINE "\r\n" 51 #else 52 #define ENDLINE "\n" 53 #endif 54 55 56 // For Windows 57 #ifdef _DEBUG 58 #ifndef DEBUG 59 #define DEBUG 60 #endif 61 #endif 62 #ifdef _NDEBUG 63 #ifndef NDEBUG 64 #define NDEBUG 65 #endif 66 #endif 67 68 69 // Shared library support 70 #ifdef WIN32 71 #if defined(__GNUC__) 72 #define FXLOCAL 73 #define FXEXPORT __attribute__ ((dllexport)) 74 #define FXIMPORT __attribute__ ((dllimport)) 75 #else 76 #define FXLOCAL 77 #define FXEXPORT __declspec(dllexport) 78 #define FXIMPORT __declspec(dllimport) 79 #endif 80 #else 81 #if defined(__GNUC__) && (__GNUC__ >= 4) 82 #define FXLOCAL __attribute__((visibility("hidden"))) 83 #define FXEXPORT __attribute__((visibility("default"))) 84 #define FXIMPORT __attribute__((visibility("default"))) 85 #else 86 #define FXLOCAL 87 #define FXEXPORT 88 #define FXIMPORT 89 #endif 90 #endif 91 92 93 // Define FXAPI for DLL builds 94 #ifdef FOXDLL 95 #ifdef FOXDLL_EXPORTS 96 #define FXAPI FXEXPORT 97 #define FXTEMPLATE_EXTERN 98 #else 99 #define FXAPI FXIMPORT 100 #define FXTEMPLATE_EXTERN extern 101 #endif 102 #else 103 #define FXAPI 104 #define FXTEMPLATE_EXTERN 105 #endif 106 107 108 // Data alignment attribute 109 #if defined(__GNUC__) 110 #define __align(x) __attribute__((aligned(x))) 111 #elif defined(_MSC_VER) 112 #define __align(x) __declspec(align(x)) 113 #else 114 #define __align(x) 115 #endif 116 117 // Get alignment of pointer p to b=2^n bytes, returning 0..b-1 118 #define __alignment(p,b) (((FXival)(p))&((b)-1)) 119 120 // Check if pointer p is aligned to b=2^n bytes 121 #define __isaligned(p,b) (__alignment(p,b)==0) 122 123 // Align pointer to b=2^n bytes 124 #define __alignto(p,b) ((void*)((((FXival)(p))+((FXival)((b)-1)))&~((FXival)((b)-1)))) 125 126 127 // Thread-local storage attribute 128 #if defined(__GNUC__) 129 #define __threadlocal __thread 130 #elif defined(_MSC_VER) 131 #define __threadlocal __declspec(thread) 132 #else 133 #define __threadlocal 134 #endif 135 136 137 // Non-returning function 138 #if defined(__GNUC__) 139 #define __noreturn __attribute__((__noreturn__)) 140 #elif (_MSC_VER >= 1400) 141 #define __noreturn __declspec(noreturn) 142 #else 143 #define __noreturn 144 #endif 145 146 // Branch prediction optimization 147 #if (__GNUC__ >= 3) 148 #define __likely(cond) __builtin_expect(!!(cond),1) 149 #define __unlikely(cond) __builtin_expect(!!(cond),0) 150 #else 151 #define __likely(cond) (!!(cond)) 152 #define __unlikely(cond) (!!(cond)) 153 #endif 154 155 156 // Prefetch address 157 #if (__GNUC__ >= 4) && (defined(__i386__) || defined(__x86_64__)) 158 #define __prefetch(addr) __builtin_prefetch((addr),0) 159 #define __prefetchw(addr) __builtin_prefetch((addr),1) 160 #else 161 #define __prefetch(addr) 162 #define __prefetchw(addr) 163 #endif 164 165 166 // Standard call calling sequence 167 #ifdef WIN32 168 #ifndef CALLBACK 169 #define CALLBACK __stdcall 170 #endif 171 #endif 172 173 174 // C Language calling sequence 175 #ifdef WIN32 176 #ifndef CDECL 177 #define CDECL __cdecl 178 #endif 179 #else 180 #ifndef CDECL 181 #define CDECL 182 #endif 183 #endif 184 185 186 // Checking printf and scanf format strings 187 #if defined(_CC_GNU_) || defined(__GNUG__) || defined(__GNUC__) 188 #define FX_PRINTF(fmt,arg) __attribute__((format(printf,fmt,arg))) 189 #define FX_SCANF(fmt,arg) __attribute__((format(scanf,fmt,arg))) 190 #define FX_FORMAT(arg) __attribute__((format_arg(arg))) 191 #else 192 #define FX_PRINTF(fmt,arg) 193 #define FX_SCANF(fmt,arg) 194 #define FX_FORMAT(arg) 195 #endif 196 197 198 // Word size issues 199 #if defined(_MSC_VER) || defined(__MINGW32__) // Windows 200 #if defined(_WIN64) 201 #define LLP64 1 // Long longs and pointers are 64 bit 202 #else 203 #define ILP32 1 // Ints, longs, and pointers are 32 bit 204 #endif 205 #elif defined(__LP64__) || defined(_LP64) || (_MIPS_SZLONG == 64) || (__WORDSIZE == 64) 206 #define LP64 1 // Longs and pointers are 64 bit 207 #else 208 #define ILP32 1 // Longs, integers, and pointers are 32 bit 209 #endif 210 211 // Suffixes for 64-bit constants 212 #if defined(LP64) 213 #define FXLONG(c) c ## L // Long suffix for 64 bit 214 #define FXULONG(c) c ## UL 215 #elif defined(_MSC_VER) && (_MSC_VER < 1900) 216 #define FXLONG(c) c ## i64 // Special suffix for 64 bit 217 #define FXULONG(c) c ## ui64 218 #else 219 #define FXLONG(c) c ## LL // Long long suffix for 64 bit 220 #define FXULONG(c) c ## ULL 221 #endif 222 223 224 // Raw event type 225 #ifdef WIN32 226 struct tagMSG; 227 #else 228 union _XEvent; 229 #endif 230 231 232 namespace FX { 233 234 235 /// Third logic state: unknown/indeterminate 236 enum { maybe=2 }; 237 238 239 /// Exponent display 240 enum FXExponent { 241 EXP_NEVER=0, /// Never use exponential notation 242 EXP_ALWAYS=1, /// Always use exponential notation 243 EXP_AUTO=2 /// Use exponential notation if needed 244 }; 245 246 247 /// Search modes for search/replace dialogs 248 enum { 249 SEARCH_BACKWARD = 1, /// Search backward 250 SEARCH_FORWARD = 2, /// Search forward 251 SEARCH_NOWRAP = 0, /// Don't wrap (default) 252 SEARCH_WRAP = 4, /// Wrap around to start 253 SEARCH_EXACT = 0, /// Exact match (default) 254 SEARCH_IGNORECASE = 8, /// Ignore case 255 SEARCH_REGEX = 16, /// Regular expression match 256 SEARCH_PREFIX = 32, /// Prefix of subject string 257 SEARCH_SUFFIX = 64 /// Suffix of subject string 258 }; 259 260 261 /********************************* Typedefs **********************************/ 262 263 // Forward declarations 264 class FXObject; 265 class FXStream; 266 class FXString; 267 268 269 // Streamable types; these are fixed size! 270 typedef char FXchar; 271 typedef signed char FXschar; 272 typedef unsigned char FXuchar; 273 typedef bool FXbool; 274 typedef unsigned short FXushort; 275 typedef short FXshort; 276 typedef unsigned int FXuint; 277 typedef int FXint; 278 typedef float FXfloat; 279 typedef double FXdouble; 280 #if defined(WIN32) 281 typedef unsigned int FXwchar; 282 #if defined(_MSC_VER) && !defined(_NATIVE_WCHAR_T_DEFINED) 283 typedef unsigned short FXnchar; 284 #elif defined(__WATCOMC__) && !defined(_WCHAR_T_DEFINED) 285 typedef long char FXnchar; 286 #else 287 typedef wchar_t FXnchar; 288 #endif 289 #else 290 typedef wchar_t FXwchar; 291 typedef unsigned short FXnchar; 292 #endif 293 #if defined(LP64) 294 typedef long FXlong; 295 typedef unsigned long FXulong; 296 #elif defined(_MSC_VER) && (_MSC_VER < 1900) 297 typedef __int64 FXlong; 298 typedef unsigned __int64 FXulong; 299 #else 300 typedef long long FXlong; 301 typedef unsigned long long FXulong; 302 #endif 303 304 // Integral types large enough to hold value of a pointer 305 #if defined(LP64) || defined(ILP32) // Long for LP64 and ILP32 models 306 typedef long FXival; 307 typedef unsigned long FXuval; 308 #elif defined(LLP64) // Long long for LLP64 models 309 #if defined(_MSC_VER) && (_MSC_VER < 1900) 310 typedef __int64 FXival; 311 typedef unsigned __int64 FXuval; 312 #else 313 typedef long long FXival; 314 typedef unsigned long long FXuval; 315 #endif 316 #endif 317 318 // Generic void pointer 319 typedef void* FXptr; 320 321 322 // Handle to something in server 323 #ifdef WIN32 324 typedef void* FXID; 325 #else 326 typedef unsigned long FXID; 327 #endif 328 329 // Time since January 1, 1970 (UTC) 330 typedef FXlong FXTime; 331 332 // Pixel type (could be color index) 333 typedef unsigned long FXPixel; 334 335 // RGBA pixel value 336 typedef FXuint FXColor; 337 338 // Hot key 339 typedef FXuint FXHotKey; 340 341 // Input source handle type 342 #ifdef WIN32 343 typedef void* FXInputHandle; 344 #else 345 typedef FXint FXInputHandle; 346 #endif 347 348 // Thread ID type 349 #if defined(WIN32) 350 typedef void* FXThreadID; 351 #else 352 typedef unsigned long FXThreadID; 353 #endif 354 355 // Thread-local storage key 356 typedef FXuval FXThreadStorageKey; 357 358 // Raw event type 359 #ifdef WIN32 360 typedef tagMSG FXRawEvent; 361 #else 362 typedef _XEvent FXRawEvent; 363 #endif 364 365 366 /// Drag and drop data type 367 #ifdef WIN32 368 typedef FXushort FXDragType; 369 #else 370 typedef FXID FXDragType; 371 #endif 372 373 374 /// A time in the far, far future 375 const FXTime forever=FXLONG(9223372036854775807); 376 377 378 /********************************** Macros ***********************************/ 379 380 /// Get bit b from val 381 #define FXBIT(val,b) (((val)>>(b))&1) 382 383 /// Abolute value 384 #define FXABS(val) (((val)>=0)?(val):-(val)) 385 386 /// Return 1 if val >= 0 and -1 otherwise 387 #define FXSGN(val) (((val)<0)?-1:1) 388 389 /// Return 1 if val > 0, -1 if val < 0, and 0 otherwise 390 #define FXSGNZ(val) ((val)<0?-1:(val)>0?1:0) 391 392 /// Sign-extend bit-field of b bits to 32 bit signed integer 393 #define FXSGNX(x,b) (((FXint)((x)<<(32-(b))))>>(32-(b))) 394 395 /// Return the maximum of a or b 396 #define FXMAX(a,b) (((a)>(b))?(a):(b)) 397 398 /// Return the minimum of a or b 399 #define FXMIN(a,b) (((a)>(b))?(b):(a)) 400 401 /// Return the minimum of x, y and z 402 #define FXMIN3(x,y,z) ((x)<(y)?FXMIN(x,z):FXMIN(y,z)) 403 404 /// Return the maximum of x, y and z 405 #define FXMAX3(x,y,z) ((x)>(y)?FXMAX(x,z):FXMAX(y,z)) 406 407 /// Return the minimum of x, y, z, and w 408 #define FXMIN4(x,y,z,w) (FXMIN(FXMIN(x,y),FXMIN(z,w))) 409 410 /// Return the maximum of of x, y, z, and w 411 #define FXMAX4(x,y,z,w) (FXMAX(FXMAX(x,y),FXMAX(z,w))) 412 413 /// Return minimum and maximum of a, b 414 #define FXMINMAX(lo,hi,a,b) ((a)<(b)?((lo)=(a),(hi)=(b)):((lo)=(b),(hi)=(a))) 415 416 /// Clamp value x to range [lo..hi] 417 #define FXCLAMP(lo,x,hi) ((x)<(lo)?(lo):((x)>(hi)?(hi):(x))) 418 419 /// Swap a pair of numbers 420 #define FXSWAP(a,b,t) ((t)=(a),(a)=(b),(b)=(t)) 421 422 /// Linear interpolation between a and b, where 0<=f<=1 423 #define FXLERP(a,b,f) ((a)+((b)-(a))*(f)) 424 425 /// Offset of member in a structure 426 #define STRUCTOFFSET(str,member) (((char *)(&(((str *)0)->member)))-((char *)0)) 427 428 /// Number of elements in a static array 429 #define ARRAYNUMBER(array) (sizeof(array)/sizeof(array[0])) 430 431 /// Container class of a member class 432 #define CONTAINER(ptr,str,mem) ((str*)(((char*)(ptr))-STRUCTOFFSET(str,mem))) 433 434 /// Make int out of two shorts 435 #define MKUINT(l,h) ((((FX::FXuint)(l))&0xffff) | (((FX::FXuint)(h))<<16)) 436 437 /// Make selector from message type and message id 438 #define FXSEL(type,id) ((((FX::FXuint)(id))&0xffff) | (((FX::FXuint)(type))<<16)) 439 440 /// Get type from selector 441 #define FXSELTYPE(s) ((FX::FXushort)(((s)>>16)&0xffff)) 442 443 /// Get ID from selector 444 #define FXSELID(s) ((FX::FXushort)((s)&0xffff)) 445 446 /// Test if character c is at the start of a utf8 sequence (not a follower byte) 447 #define FXISUTF8(c) (((c)&0xC0)!=0x80) 448 449 /// Check if c is leader/follower of a utf8 multi-byte sequence 450 #define FXISLEADUTF8(c) (((c)&0xC0)==0xC0) 451 #define FXISFOLLOWUTF8(c) (((c)&0xC0)==0x80) 452 453 /// Check if c is part of a utf8 multi-byte sequence 454 #define FXISSEQUTF8(c) (((c)&0x80)==0x80) 455 456 /// Number of FXchars in utf8 sequence 457 #define FXUTF8LEN(c) (((0xE5000000>>((((FXuchar)(c))>>4)<<1))&3)+1) 458 459 /// Test if character c is at start of utf16 sequence (not a follower from surrogate pair) 460 #define FXISUTF16(c) (((c)&0xFC00)!=0xDC00) 461 462 /// Check if c is leader/follower of a utf16 surrogate pair sequence 463 #define FXISLEADUTF16(c) (((c)&0xFC00)==0xD800) 464 #define FXISFOLLOWUTF16(c) (((c)&0xFC00)==0xDC00) 465 466 /// Check if c is part of a utf16 surrogate pair sequence 467 #define FXISSEQUTF16(c) (((c)&0xF800)==0xD800) 468 469 /// Number of FXnchars in utf16 sequence 470 #define FXUTF16LEN(c) (FXISLEADUTF16(c)+1) 471 472 /// Test if c is a legal utf32 character 473 #define FXISUTF32(c) ((c)<0x110000) 474 475 /// Average of two FXColor ca and FXColor cb 476 #define FXAVGCOLOR(ca,cb) (((ca)&(cb))+((((ca)^(cb))&0xFEFEFEFE)>>1)) 477 478 479 // Definitions for big-endian machines 480 #if FOX_BIGENDIAN == 1 481 482 /// Make RGBA color 483 #define FXRGBA(r,g,b,a) (((FX::FXuint)(FX::FXuchar)(a)) | ((FX::FXuint)(FX::FXuchar)(r)<<8) | ((FX::FXuint)(FX::FXuchar)(g)<<16) | ((FX::FXuint)(FX::FXuchar)(b)<<24)) 484 485 /// Make RGB color 486 #define FXRGB(r,g,b) (((FX::FXuint)(FX::FXuchar)(r)<<8) | ((FX::FXuint)(FX::FXuchar)(g)<<16) | ((FX::FXuint)(FX::FXuchar)(b)<<24) | 0x000000ff) 487 488 /// Get red value from RGBA color 489 #define FXREDVAL(rgba) ((FX::FXuchar)(((rgba)>>8)&0xff)) 490 491 /// Get green value from RGBA color 492 #define FXGREENVAL(rgba) ((FX::FXuchar)(((rgba)>>16)&0xff)) 493 494 /// Get blue value from RGBA color 495 #define FXBLUEVAL(rgba) ((FX::FXuchar)(((rgba)>>24)&0xff)) 496 497 /// Get alpha value from RGBA color 498 #define FXALPHAVAL(rgba) ((FX::FXuchar)((rgba)&0xff)) 499 500 /// Get component value of RGBA color 501 #define FXRGBACOMPVAL(rgba,comp) ((FX::FXuchar)(((rgba)>>((comp)<<3))&0xff)) 502 503 /// Get RGB color from COLORREF 504 #define FXCOLORREF2RGB(ref) (FX::FXuint)((((ref)<<8)&0xff000000) | (((ref)<<8)&0xff0000) | (((ref)<<8)&0xff00) | 0x000000ff) 505 506 /// Get COLORREF from RGB color 507 #define FXRGB2COLORREF(rgb) (FX::FXuint)((((rgb)>>8)&0xff0000) | (((rgb)>>8)&0xff00) | (((rgb)>>8)&0xff)) 508 509 #endif 510 511 512 // Definitions for little-endian machines 513 #if FOX_BIGENDIAN == 0 514 515 /// Make RGBA color 516 #define FXRGBA(r,g,b,a) (((FX::FXuint)(FX::FXuchar)(a)<<24) | ((FX::FXuint)(FX::FXuchar)(r)<<16) | ((FX::FXuint)(FX::FXuchar)(g)<<8) | ((FX::FXuint)(FX::FXuchar)(b))) 517 518 /// Make RGB color 519 #define FXRGB(r,g,b) (((FX::FXuint)(FX::FXuchar)(r)<<16) | ((FX::FXuint)(FX::FXuchar)(g)<<8) | ((FX::FXuint)(FX::FXuchar)(b)) | 0xff000000) 520 521 /// Get red value from RGBA color 522 #define FXREDVAL(rgba) ((FX::FXuchar)(((rgba)>>16)&0xff)) 523 524 /// Get green value from RGBA color 525 #define FXGREENVAL(rgba) ((FX::FXuchar)(((rgba)>>8)&0xff)) 526 527 /// Get blue value from RGBA color 528 #define FXBLUEVAL(rgba) ((FX::FXuchar)((rgba)&0xff)) 529 530 /// Get alpha value from RGBA color 531 #define FXALPHAVAL(rgba) ((FX::FXuchar)(((rgba)>>24)&0xff)) 532 533 /// Get component value of RGBA color 534 #define FXRGBACOMPVAL(rgba,comp) ((FX::FXuchar)(((rgba)>>((3-(comp))<<3))&0xff)) 535 536 /// Get RGB color from COLORREF 537 #define FXCOLORREF2RGB(ref) (FX::FXuint)((((ref)>>16)&0xff) | ((ref)&0xff00) | (((ref)<<16)&0xff0000) | 0xff000000) 538 539 /// Get COLORREF from RGB color 540 #define FXRGB2COLORREF(rgb) (FX::FXuint)((((rgb)<<16)&0xff0000) | ((rgb)&0xff00) | (((rgb)>>16)&0xff)) 541 542 #endif 543 544 545 /** 546 * FXASSERT() prints out a message when the expression fails, 547 * and nothing otherwise. Unlike assert(), FXASSERT() will not 548 * terminate the execution of the application. 549 * When compiling your application for release, all assertions 550 * are compiled out; thus there is no impact on execution speed. 551 */ 552 #ifndef NDEBUG 553 #define FXASSERT(exp) (__likely(exp)?((void)0):(void)FX::fxassert(#exp,__FILE__,__LINE__)) 554 #else 555 #define FXASSERT(exp) ((void)0) 556 #endif 557 558 559 /** 560 * FXVERIFY prints out a message when the expression fails, 561 * and nothing otherwise. 562 * When compiling your application for release, these messages 563 * are compiled out, but unlike FXASSERT, FXVERIFY will still execute 564 * the expression. 565 */ 566 #ifndef NDEBUG 567 #define FXVERIFY(exp) (__likely(exp)?((void)0):(void)FX::fxverify(#exp,__FILE__,__LINE__)) 568 #else 569 #define FXVERIFY(exp) ((void)(exp)) 570 #endif 571 572 573 /** 574 * FXTRACE() allows you to trace the execution of your application 575 * with increasing levels of detail the higher the trace level. 576 * The trace level is determined by variable fxTraceLevel, which 577 * may be set from the command line with "-tracelevel <level>". 578 * When compiling your application for release, all trace statements 579 * are compiled out, just like FXASSERT. 580 * A statement like: FXTRACE((10,"The value of x=%d\n",x)) will 581 * generate output only if fxTraceLevel is set to 11 or greater. 582 * The default value fxTraceLevel=0 will block all trace outputs. 583 * Note the double parentheses! 584 */ 585 #ifndef NDEBUG 586 #define FXTRACE(arguments) FX::fxtrace arguments 587 #else 588 #define FXTRACE(arguments) ((void)0) 589 #endif 590 591 /** 592 * Allocate a memory block of no elements of type and store a pointer 593 * to it into the address pointed to by ptr. 594 * Return false if size!=0 and allocation fails, true otherwise. 595 * An allocation of a zero size block returns a NULL pointer. 596 */ 597 #define FXMALLOC(ptr,type,no) (FX::fxmalloc((void **)(ptr),sizeof(type)*(no))) 598 599 /** 600 * Allocate a zero-filled memory block no elements of type and store a pointer 601 * to it into the address pointed to by ptr. 602 * Return false if size!=0 and allocation fails, true otherwise. 603 * An allocation of a zero size block returns a NULL pointer. 604 */ 605 #define FXCALLOC(ptr,type,no) (FX::fxcalloc((void **)(ptr),sizeof(type)*(no))) 606 607 /** 608 * Resize the memory block referred to by the pointer at the address ptr, to a 609 * hold no elements of type. 610 * Returns false if size!=0 and reallocation fails, true otherwise. 611 * If reallocation fails, pointer is left to point to old block; a reallocation 612 * to a zero size block has the effect of freeing it. 613 * The ptr argument must be the address where the pointer to the allocated 614 * block is to be stored. 615 */ 616 #define FXRESIZE(ptr,type,no) (FX::fxresize((void **)(ptr),sizeof(type)*(no))) 617 618 /** 619 * Allocate and initialize memory from another block. 620 * Return false if size!=0 and source!=NULL and allocation fails, true otherwise. 621 * An allocation of a zero size block returns a NULL pointer. 622 * The ptr argument must be the address where the pointer to the allocated 623 * block is to be stored. 624 */ 625 #define FXMEMDUP(ptr,src,type,no) (FX::fxmemdup((void **)(ptr),(const void*)(src),sizeof(type)*(no))) 626 627 /** 628 * Free a block of memory allocated with either FXMALLOC, FXCALLOC, FXRESIZE, or FXMEMDUP. 629 * It is OK to call free a NULL pointer. The argument must be the address of the 630 * pointer to the block to be released. The pointer is set to NULL to prevent 631 * any further references to the block after releasing it. 632 */ 633 #define FXFREE(ptr) (FX::fxfree((void **)(ptr))) 634 635 /********************************** Globals **********************************/ 636 637 /// Allocate memory 638 extern FXAPI FXbool fxmalloc(void** ptr,FXuval size); 639 640 /// Allocate cleaned memory 641 extern FXAPI FXbool fxcalloc(void** ptr,FXuval size); 642 643 /// Resize memory 644 extern FXAPI FXbool fxresize(void** ptr,FXuval size); 645 646 /// Duplicate memory 647 extern FXAPI FXbool fxmemdup(void** ptr,const void* src,FXuval size); 648 649 /// Free memory, resets ptr to NULL afterward 650 extern FXAPI void fxfree(void** ptr); 651 652 /// Error routine 653 extern FXAPI __noreturn void fxerror(const FXchar* format,...) FX_PRINTF(1,2) ; 654 655 /// Warning routine 656 extern FXAPI void fxwarning(const FXchar* format,...) FX_PRINTF(1,2) ; 657 658 /// Log message to [typically] stderr 659 extern FXAPI void fxmessage(const FXchar* format,...) FX_PRINTF(1,2) ; 660 661 /// Assert failed routine:- usually not called directly but called through FXASSERT 662 extern FXAPI void fxassert(const FXchar* expression,const FXchar* filename,unsigned int lineno); 663 664 /// Verify failed routine:- usually not called directly but called through FXVERIFY 665 extern FXAPI void fxverify(const FXchar* expression,const FXchar* filename,unsigned int lineno); 666 667 /// Trace printout routine:- usually not called directly but called through FXTRACE 668 extern FXAPI void fxtrace(FXint level,const FXchar* format,...) FX_PRINTF(2,3) ; 669 670 /// Convert string of length len to MSDOS; return new string and new length 671 extern FXAPI FXbool fxtoDOS(FXchar*& string,FXint& len); 672 673 /// Convert string of length len from MSDOS; return new string and new length 674 extern FXAPI FXbool fxfromDOS(FXchar*& string,FXint& len); 675 676 /// Duplicate string 677 extern FXAPI FXchar *fxstrdup(const FXchar* str); 678 679 /// Calculate a hash value from a string 680 extern FXAPI FXuint fxstrhash(const FXchar* str); 681 682 /// Safe string copy 683 extern FXAPI FXival fxstrlcpy(FXchar* dst,const FXchar* src,FXival len); 684 685 /// Safe string concat 686 extern FXAPI FXival fxstrlcat(FXchar* dst,const FXchar* src,FXival len); 687 688 /// Convert RGB to HSV 689 extern FXAPI void fxrgb_to_hsv(FXfloat& h,FXfloat& s,FXfloat& v,FXfloat r,FXfloat g,FXfloat b); 690 691 /// Convert HSV to RGB 692 extern FXAPI void fxhsv_to_rgb(FXfloat& r,FXfloat& g,FXfloat& b,FXfloat h,FXfloat s,FXfloat v); 693 694 /// Convert RGB to HSL 695 extern FXAPI void fxrgb_to_hsl(FXfloat& h,FXfloat& s,FXfloat& l,FXfloat r,FXfloat g,FXfloat b); 696 697 /// Convert HSL to RGB 698 extern FXAPI void fxhsl_to_rgb(FXfloat& r,FXfloat& g,FXfloat& b,FXfloat h,FXfloat s,FXfloat l); 699 700 /// Encode src to dst in base64 701 extern FXchar* fxencode64(FXchar* dst,FXchar* dstend,const FXchar* src,const FXchar* srcend); 702 703 /// Decode src to dst from base64 704 extern FXchar* fxdecode64(FXchar* dst,FXchar* dstend,const FXchar* src,const FXchar* srcend); 705 706 /// Encode src to dst in base85 707 extern FXchar* fxencode85(FXchar* dst,FXchar* dstend,const FXchar* src,const FXchar* srcend); 708 709 /// Decode src to dst from base85 710 extern FXchar* fxdecode85(FXchar* dst,FXchar* dstend,const FXchar* src,const FXchar* srcend); 711 712 /// Convert keysym to unicode character 713 extern FXAPI FXwchar fxkeysym2ucs(FXwchar sym); 714 715 /// Convert unicode character to keysym 716 extern FXAPI FXwchar fxucs2keysym(FXwchar ucs); 717 718 /// Parse geometry, a-la X11 geometry specification 719 extern FXAPI FXint fxparsegeometry(const FXchar *string,FXint& x,FXint& y,FXint& w,FXint& h); 720 721 /// True if executable with given path is a console application 722 extern FXAPI FXbool fxisconsole(const FXchar *path); 723 724 /// Return clock ticks from cpu tick-counter 725 extern FXAPI FXTime fxgetticks(); 726 727 /// Version number that the library has been compiled with 728 extern FXAPI const FXuchar fxversion[3]; 729 730 /// Controls tracing level 731 extern FXAPI FXint fxTraceLevel; 732 733 734 /// Return wide character from utf8 string at ptr 735 extern FXAPI FXwchar wc(const FXchar *ptr); 736 737 /// Return wide character from utf16 string at ptr 738 extern FXAPI FXwchar wc(const FXnchar *ptr); 739 740 741 /// Increment to start of next wide character in utf8 string 742 extern FXAPI const FXchar* wcinc(const FXchar* ptr); 743 744 /// Increment to start of next wide character in utf8 string 745 extern FXAPI FXchar* wcinc(FXchar* ptr); 746 747 /// Increment to start of next wide character in utf16 string 748 extern FXAPI const FXnchar* wcinc(const FXnchar* ptr); 749 750 /// Increment to start of next wide character in utf16 string 751 extern FXAPI FXnchar* wcinc(FXnchar* ptr); 752 753 /// Decrement to start of previous wide character in utf8 string 754 extern FXAPI const FXchar* wcdec(const FXchar* ptr); 755 756 /// Decrement to start of previous wide character in utf8 string 757 extern FXAPI FXchar* wcdec(FXchar* ptr); 758 759 /// Decrement to start of previous wide character in utf16 string 760 extern FXAPI const FXnchar* wcdec(const FXnchar* ptr); 761 762 /// Decrement to start of previous wide character in utf16 string 763 extern FXAPI FXnchar* wcdec(FXnchar* ptr); 764 765 /// Adjust ptr to point to leader of multi-byte sequence 766 extern FXAPI const FXchar* wcstart(const FXchar* ptr); 767 768 /// Adjust ptr to point to leader of multi-byte sequence 769 extern FXAPI FXchar* wcstart(FXchar* ptr); 770 771 /// Adjust ptr to point to leader of surrogate pair sequence 772 extern FXAPI const FXnchar* wcstart(const FXnchar *ptr); 773 774 /// Adjust ptr to point to leader of surrogate pair sequence 775 extern FXAPI FXnchar* wcstart(FXnchar *ptr); 776 777 /// Return number of FXchar's of wide character at ptr 778 extern FXAPI FXival wclen(const FXchar *ptr); 779 780 /// Return number of FXnchar's of narrow character at ptr 781 extern FXAPI FXival wclen(const FXnchar *ptr); 782 783 /// Check if valid utf8 wide character representation; returns length or 0 784 extern FXAPI FXival wcvalid(const FXchar* ptr); 785 786 /// Check if valid utf16 wide character representation; returns length or 0 787 extern FXAPI FXival wcvalid(const FXnchar* ptr); 788 789 790 /// Return number of bytes for utf8 representation of wide character w 791 extern FXAPI FXival wc2utf(FXwchar w); 792 793 /// Return number of narrow characters for utf16 representation of wide character w 794 extern FXAPI FXival wc2nc(FXwchar w); 795 796 /// Return number of bytes for utf8 representation of wide character string 797 extern FXAPI FXival wcs2utf(const FXwchar* src,FXival srclen); 798 extern FXAPI FXival wcs2utf(const FXwchar* src); 799 800 /// Return number of bytes for utf8 representation of narrow character string 801 extern FXAPI FXival ncs2utf(const FXnchar* src,FXival srclen); 802 extern FXAPI FXival ncs2utf(const FXnchar* src); 803 804 /// Return number of wide characters for utf8 character string 805 extern FXAPI FXival utf2wcs(const FXchar src,FXival srclen); 806 extern FXAPI FXival utf2wcs(const FXchar *src); 807 808 /// Return number of narrow characters for utf8 character string 809 extern FXAPI FXival utf2ncs(const FXchar *src,FXival srclen); 810 extern FXAPI FXival utf2ncs(const FXchar *src); 811 812 813 /// Convert wide character to utf8 string; return number of items written to dst 814 extern FXAPI FXival wc2utf(FXchar *dst,FXwchar w); 815 816 /// Convert wide character to narrow character string; return number of items written to dst 817 extern FXAPI FXival wc2nc(FXnchar *dst,FXwchar w); 818 819 /// Convert wide character string to utf8 string; return number of items written to dst 820 extern FXAPI FXival wcs2utf(FXchar *dst,const FXwchar* src,FXival dstlen,FXival srclen); 821 extern FXAPI FXival wcs2utf(FXchar *dst,const FXwchar* src,FXival dstlen); 822 823 /// Convert narrow character string to utf8 string; return number of items written to dst 824 extern FXAPI FXival ncs2utf(FXchar *dst,const FXnchar* src,FXival dsrlen,FXival srclen); 825 extern FXAPI FXival ncs2utf(FXchar *dst,const FXnchar* src,FXival dsrlen); 826 827 /// Convert utf8 string to wide character string; return number of items written to dst 828 extern FXAPI FXival utf2wcs(FXwchar *dst,const FXchar* src,FXival dsrlen,FXival srclen); 829 extern FXAPI FXival utf2wcs(FXwchar *dst,const FXchar* src,FXival dsrlen); 830 831 /// Convert utf8 string to narrow character string; return number of items written to dst 832 extern FXAPI FXival utf2ncs(FXnchar *dst,const FXchar* src,FXival dsrlen,FXival srclen); 833 extern FXAPI FXival utf2ncs(FXnchar *dst,const FXchar* src,FXival dsrlen); 834 835 /// Swap non-overlapping arrays 836 extern FXAPI void memswap(void* dst,void* src,FXuval n); 837 838 } 839 840 #endif 841