diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
commit | 6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /intl/components/src/ICU4CLibrary.h | |
parent | Initial commit. (diff) | |
download | thunderbird-upstream.tar.xz thunderbird-upstream.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'intl/components/src/ICU4CLibrary.h')
-rw-r--r-- | intl/components/src/ICU4CLibrary.h | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/intl/components/src/ICU4CLibrary.h b/intl/components/src/ICU4CLibrary.h new file mode 100644 index 0000000000..67cd1e205f --- /dev/null +++ b/intl/components/src/ICU4CLibrary.h @@ -0,0 +1,74 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef intl_components_ICU4CLibrary_h +#define intl_components_ICU4CLibrary_h + +#include "mozilla/intl/ICU4CGlue.h" +#include "mozilla/Span.h" + +#include <stddef.h> + +namespace mozilla::intl { +/** + * Wrapper around non-portable, ICU4C specific functions. + */ +class ICU4CLibrary final { + public: + ICU4CLibrary() = delete; + + /** + * Initializes the ICU4C library. + * + * Note: This function should only be called once. + */ + static ICUResult Initialize(); + + /** + * Releases any memory held by ICU. Any open ICU objects and resources are + * left in an undefined state after this operation. + * + * NOTE: This function is not thread-safe. + */ + static void Cleanup(); + + struct MemoryFunctions { + // These are equivalent to ICU's |UMemAllocFn|, |UMemReallocFn|, and + // |UMemFreeFn| types. The first argument (called |context| in the ICU + // docs) will always be nullptr and should be ignored. + using AllocFn = void* (*)(const void*, size_t); + using ReallocFn = void* (*)(const void*, void*, size_t); + using FreeFn = void (*)(const void*, void*); + + /** + * Function called when allocating memory. + */ + AllocFn mAllocFn = nullptr; + + /** + * Function called when reallocating memory. + */ + ReallocFn mReallocFn = nullptr; + + /** + * Function called when freeing memory. + */ + FreeFn mFreeFn = nullptr; + }; + + /** + * Sets the ICU memory functions. + * + * This function can only be called before the initial call to Initialize()! + */ + static ICUResult SetMemoryFunctions(MemoryFunctions aMemoryFunctions); + + /** + * Return the ICU version number. + */ + static Span<const char> GetVersion(); +}; +} // namespace mozilla::intl + +#endif |