Imported Upstream version 0.9.0
[platform/upstream/libjxl.git] / lib / include / jxl / resizable_parallel_runner_cxx.h
1 // Copyright (c) the JPEG XL Project Authors. All rights reserved.
2 //
3 // Use of this source code is governed by a BSD-style
4 // license that can be found in the LICENSE file.
5
6 /// @addtogroup libjxl_cpp
7 /// @{
8 ///
9 /// @file resizable_parallel_runner_cxx.h
10 /// @ingroup libjxl_threads
11 /// @brief C++ header-only helper for @ref resizable_parallel_runner.h.
12 ///
13 /// There's no binary library associated with the header since this is a header
14 /// only library.
15
16 #ifndef JXL_RESIZABLE_PARALLEL_RUNNER_CXX_H_
17 #define JXL_RESIZABLE_PARALLEL_RUNNER_CXX_H_
18
19 #include <jxl/resizable_parallel_runner.h>
20
21 #include <memory>
22
23 #if !(defined(__cplusplus) || defined(c_plusplus))
24 #error \
25     "This a C++ only header. Use jxl/jxl_resizable_parallel_runner.h from C" \
26     "sources."
27 #endif
28
29 /// Struct to call JxlResizableParallelRunnerDestroy from the
30 /// JxlResizableParallelRunnerPtr unique_ptr.
31 struct JxlResizableParallelRunnerDestroyStruct {
32   /// Calls @ref JxlResizableParallelRunnerDestroy() on the passed runner.
33   void operator()(void* runner) { JxlResizableParallelRunnerDestroy(runner); }
34 };
35
36 /// std::unique_ptr<> type that calls JxlResizableParallelRunnerDestroy() when
37 /// releasing the runner.
38 ///
39 /// Use this helper type from C++ sources to ensure the runner is destroyed and
40 /// their internal resources released.
41 typedef std::unique_ptr<void, JxlResizableParallelRunnerDestroyStruct>
42     JxlResizableParallelRunnerPtr;
43
44 /// Creates an instance of JxlResizableParallelRunner into a
45 /// JxlResizableParallelRunnerPtr and initializes it.
46 ///
47 /// This function returns a unique_ptr that will call
48 /// JxlResizableParallelRunnerDestroy() when releasing the pointer. See @ref
49 /// JxlResizableParallelRunnerCreate for details on the instance creation.
50 ///
51 /// @param memory_manager custom allocator function. It may be NULL. The memory
52 ///        manager will be copied internally.
53 /// @return a @c NULL JxlResizableParallelRunnerPtr if the instance can not be
54 /// allocated or initialized
55 /// @return initialized JxlResizableParallelRunnerPtr instance otherwise.
56 static inline JxlResizableParallelRunnerPtr JxlResizableParallelRunnerMake(
57     const JxlMemoryManager* memory_manager) {
58   return JxlResizableParallelRunnerPtr(
59       JxlResizableParallelRunnerCreate(memory_manager));
60 }
61
62 #endif  // JXL_RESIZABLE_PARALLEL_RUNNER_CXX_H_
63
64 /// @}