types.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /* Copyright 2013 Google Inc. All Rights Reserved.
  2. Distributed under MIT license.
  3. See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
  4. */
  5. /**
  6. * @file
  7. * Common types used in decoder and encoder API.
  8. */
  9. #ifndef BROTLI_COMMON_TYPES_H_
  10. #define BROTLI_COMMON_TYPES_H_
  11. #include <stddef.h> /* for size_t */
  12. #if defined(_MSC_VER) && (_MSC_VER < 1600)
  13. typedef __int8 int8_t;
  14. typedef unsigned __int8 uint8_t;
  15. typedef __int16 int16_t;
  16. typedef unsigned __int16 uint16_t;
  17. typedef __int32 int32_t;
  18. typedef unsigned __int32 uint32_t;
  19. typedef unsigned __int64 uint64_t;
  20. typedef __int64 int64_t;
  21. #else
  22. #include <stdint.h>
  23. #endif /* defined(_MSC_VER) && (_MSC_VER < 1600) */
  24. /**
  25. * A portable @c bool replacement.
  26. *
  27. * ::BROTLI_BOOL is a "documentation" type: actually it is @c int, but in API it
  28. * denotes a type, whose only values are ::BROTLI_TRUE and ::BROTLI_FALSE.
  29. *
  30. * ::BROTLI_BOOL values passed to Brotli should either be ::BROTLI_TRUE or
  31. * ::BROTLI_FALSE, or be a result of ::TO_BROTLI_BOOL macros.
  32. *
  33. * ::BROTLI_BOOL values returned by Brotli should not be tested for equality
  34. * with @c true, @c false, ::BROTLI_TRUE, ::BROTLI_FALSE, but rather should be
  35. * evaluated, for example: @code{.cpp}
  36. * if (SomeBrotliFunction(encoder, BROTLI_TRUE) &&
  37. * !OtherBrotliFunction(decoder, BROTLI_FALSE)) {
  38. * bool x = !!YetAnotherBrotliFunction(encoder, TO_BROLTI_BOOL(2 * 2 == 4));
  39. * DoSomething(x);
  40. * }
  41. * @endcode
  42. */
  43. #define BROTLI_BOOL int
  44. /** Portable @c true replacement. */
  45. #define BROTLI_TRUE 1
  46. /** Portable @c false replacement. */
  47. #define BROTLI_FALSE 0
  48. /** @c bool to ::BROTLI_BOOL conversion macros. */
  49. #define TO_BROTLI_BOOL(X) (!!(X) ? BROTLI_TRUE : BROTLI_FALSE)
  50. #define BROTLI_MAKE_UINT64_T(high, low) ((((uint64_t)(high)) << 32) | low)
  51. #define BROTLI_UINT32_MAX (~((uint32_t)0))
  52. #define BROTLI_SIZE_MAX (~((size_t)0))
  53. /**
  54. * Allocating function pointer type.
  55. *
  56. * @param opaque custom memory manager handle provided by client
  57. * @param size requested memory region size; can not be @c 0
  58. * @returns @c 0 in the case of failure
  59. * @returns a valid pointer to a memory region of at least @p size bytes
  60. * long otherwise
  61. */
  62. typedef void* (*brotli_alloc_func)(void* opaque, size_t size);
  63. /**
  64. * Deallocating function pointer type.
  65. *
  66. * This function @b SHOULD do nothing if @p address is @c 0.
  67. *
  68. * @param opaque custom memory manager handle provided by client
  69. * @param address memory region pointer returned by ::brotli_alloc_func, or @c 0
  70. */
  71. typedef void (*brotli_free_func)(void* opaque, void* address);
  72. #endif /* BROTLI_COMMON_TYPES_H_ */