7#include <unordered_map>
9#include "../_cexports/c_core.h"
10#include "../_cexports/c_img.h"
12#include "../_decl/decl_plane_enumerator.hpp"
14#include "../exception.hpp"
15#include "../global.hpp"
16#include "../image.hpp"
17#include "../buffer.hpp"
18#include "../pfnc_buffer.hpp"
19#include "../handle_only.hpp"
20#include "../shims/stdvariant.hpp"
33 inline HandleGuard<Composite>::HandleGuard(
void* handle) noexcept
34 : HandleGuard<Composite>(handle, [](
void* handle) { CVB_CALL_CAPI(ReleaseObject(handle)); })
58 return Internal::DoHandleCallObjectOut<class Composite>(CVB_CALL_CAPI(CVCCreateComposite(
static_cast<CExports::CVCCompositePurpose
>(purpose))));
63 template <
class OTHER>
69 explicit Composite(HandleGuard<Composite>&& guard)
70 : handle_(std::move(guard))
72 if (!CVB_CALL_CAPI(CVCIsComposite(
Handle())))
76 static HandleGuard<Composite> MakeShared(
void* handle)
noexcept
78 CVB_CALL_CAPI(ShareObject(handle));
79 return HandleGuard<Composite>{handle};
93 return handle_.Handle();
126 CExports::CVCCompositePurpose purpose = CExports::CVCCompositePurpose::CVCCP_Custom;
127 CVB_CALL_CAPI(CVCCompositeGetPurpose(
Handle(), purpose));
128 return static_cast<CompositePurpose
>(purpose);
137 const auto itemHandle = HandleOf(item);
139 for (
auto i =
ItemCount() - 1; i >= 0; --i)
141 if (itemHandle == HandleOf(
ItemAt(i)))
154 CExports::cvbdim_t numElements = 0;
155 CVB_CALL_CAPI(CVCCompositeGetCount(
Handle(), numElements));
156 return static_cast<int>(numElements);
167 const auto handle = HandleOf(item);
168 Internal::DoResCall([
this, index, handle]() {
return CVB_CALL_CAPI(CVCCompositeInsertAt(
Handle(), index, handle)); });
171 const auto pos = itemCache_.find(handle);
172 if (pos == itemCache_.end())
173 itemCache_.emplace_hint(pos, handle, item);
194 auto item = MakeWrapperFrom(index);
195 const auto handle = HandleOf(item);
198 const auto pos = itemCache_.find(handle);
199 if (pos != itemCache_.end())
202 itemCache_.emplace_hint(pos, handle, item);
213 const auto item = MakeWrapperFrom(index);
215 Internal::DoResCall([&]() {
return CVB_CALL_CAPI(CVCCompositeRemoveAt(
Handle(), index)); });
220 itemCache_.erase(HandleOf(item));
228 return Cvb::visit([](
const auto& obj) {
return obj->Handle(); }, item);
235 HandleGuard<Composite> handle_;
Component class is a container for CVB objects.
Definition: decl_composite.hpp:45
static CompositePtr FromObject(std::shared_ptr< T > object)
Returns a composite object from the given composite compatible object.
bool ContainsItem(const CompositeVariant &item) const
Checks whether item is in this Composite.
Definition: decl_composite.hpp:135
void PushBackItem(const CompositeVariant &item)
Appends a composite item.
Definition: decl_composite.hpp:181
void RemoveItemAt(int index)
Remove a composite item specified by its index.
Definition: decl_composite.hpp:211
static std::unique_ptr< Composite > Create(CompositePurpose purpose=CompositePurpose::Custom)
Creates a composite with the given optional parameter.
Definition: decl_composite.hpp:56
CompositeVariant ItemAt(int index) const
Access to a composite item specified by its index.
Definition: decl_composite.hpp:192
int ItemCount() const noexcept
Number of variants in the composite.
Definition: decl_composite.hpp:152
static std::unique_ptr< Composite > FromHandle(HandleGuard< Composite > &&guard)
Creates a composite from a classic API handle.
Definition: decl_composite.hpp:104
void * Handle() const noexcept
Classic API node handle.
Definition: decl_composite.hpp:91
CompositePurpose Purpose() const noexcept
Gets the purpose of this Composite.
Definition: decl_composite.hpp:124
void InsertItemAt(int index, const CompositeVariant &item)
Insert a composite item specified at given index.
Definition: decl_composite.hpp:165
MultiPart image class.
Definition: multi_part_image.hpp:23
This class is a replacement for C++17 std::variant.
Definition: variant.hpp:49
Root namespace for the Image Manager interface.
Definition: c_barcode.h:24
Cvb::variant< ImagePtr, PlanePtr, PlaneEnumeratorPtr, BufferPtr, PFNCBufferPtr, HandleOnlyPtr > CompositeVariant
Variant that can contain the different types of composite items.
Definition: decl_composite.hpp:39