1 // Copyright (c) the JPEG XL Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style
4 // license that can be found in the LICENSE file.
6 /// @addtogroup libjxl_cpp
9 /// @file resizable_parallel_runner_cxx.h
10 /// @ingroup libjxl_threads
11 /// @brief C++ header-only helper for @ref resizable_parallel_runner.h.
13 /// There's no binary library associated with the header since this is a header
16 #ifndef JXL_RESIZABLE_PARALLEL_RUNNER_CXX_H_
17 #define JXL_RESIZABLE_PARALLEL_RUNNER_CXX_H_
19 #include <jxl/resizable_parallel_runner.h>
23 #if !(defined(__cplusplus) || defined(c_plusplus))
25 "This a C++ only header. Use jxl/jxl_resizable_parallel_runner.h from C" \
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); }
36 /// std::unique_ptr<> type that calls JxlResizableParallelRunnerDestroy() when
37 /// releasing the runner.
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;
44 /// Creates an instance of JxlResizableParallelRunner into a
45 /// JxlResizableParallelRunnerPtr and initializes it.
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.
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));
62 #endif // JXL_RESIZABLE_PARALLEL_RUNNER_CXX_H_