ICU4CLibrary.h (1910B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 #ifndef intl_components_ICU4CLibrary_h 6 #define intl_components_ICU4CLibrary_h 7 8 #include "mozilla/intl/ICU4CGlue.h" 9 #include "mozilla/Span.h" 10 11 #include <stddef.h> 12 13 namespace mozilla::intl { 14 /** 15 * Wrapper around non-portable, ICU4C specific functions. 16 */ 17 class ICU4CLibrary final { 18 public: 19 ICU4CLibrary() = delete; 20 21 /** 22 * Initializes the ICU4C library. 23 * 24 * Note: This function should only be called once. 25 */ 26 static ICUResult Initialize(); 27 28 /** 29 * Releases any memory held by ICU. Any open ICU objects and resources are 30 * left in an undefined state after this operation. 31 * 32 * NOTE: This function is not thread-safe. 33 */ 34 static void Cleanup(); 35 36 struct MemoryFunctions { 37 // These are equivalent to ICU's |UMemAllocFn|, |UMemReallocFn|, and 38 // |UMemFreeFn| types. The first argument (called |context| in the ICU 39 // docs) will always be nullptr and should be ignored. 40 using AllocFn = void* (*)(const void*, size_t); 41 using ReallocFn = void* (*)(const void*, void*, size_t); 42 using FreeFn = void (*)(const void*, void*); 43 44 /** 45 * Function called when allocating memory. 46 */ 47 AllocFn mAllocFn = nullptr; 48 49 /** 50 * Function called when reallocating memory. 51 */ 52 ReallocFn mReallocFn = nullptr; 53 54 /** 55 * Function called when freeing memory. 56 */ 57 FreeFn mFreeFn = nullptr; 58 }; 59 60 /** 61 * Sets the ICU memory functions. 62 * 63 * This function can only be called before the initial call to Initialize()! 64 */ 65 static ICUResult SetMemoryFunctions(MemoryFunctions aMemoryFunctions); 66 67 /** 68 * Return the ICU version number. 69 */ 70 static Span<const char> GetVersion(); 71 }; 72 } // namespace mozilla::intl 73 74 #endif