6#include <unordered_map>
8#include "../_cexports/c_core.h"
9#include "../_cexports/c_img.h"
11#include "../_decl/decl_plane_enumerator.hpp"
13#include "../exception.hpp"
14#include "../global.hpp"
15#include "../image.hpp"
16#include "../buffer.hpp"
17#include "../pfnc_buffer.hpp"
18#include "../compressed_pfnc_buffer.hpp"
19#include "../handle_only.hpp"
20#include "../shims/stdvariant.hpp"
32 inline HandleGuard<Composite>::HandleGuard(
void *handle) noexcept
33 : HandleGuard<Composite>(handle, [](
void *handle) { CVB_CALL_CAPI(
ReleaseObject(handle)); })
49 using GuardType = HandleGuard<Composite>;
59 return Internal::DoHandleCallObjectOut<class Composite>(
60 CVB_CALL_CAPI(CVCCreateComposite(
static_cast<CExports::CVCCompositePurpose
>(purpose))));
64 template <
class OTHER>
70 explicit Composite(HandleGuard<Composite> &&guard)
71 : handle_(std::move(guard))
73 if (!CVB_CALL_CAPI(CVCIsComposite(
Handle())))
77 static HandleGuard<Composite> MakeShared(
void *handle)
noexcept
80 return HandleGuard<Composite>{handle};
93 return handle_.Handle();
133 CExports::CVCCompositePurpose purpose = CExports::CVCCompositePurpose::CVCCP_Custom;
134 CVB_CALL_CAPI(CVCCompositeGetPurpose(
Handle(), purpose));
135 return static_cast<CompositePurpose
>(purpose);
144 const auto itemHandle = HandleOf(item);
146 for (
auto i =
ItemCount() - 1; i >= 0; --i)
148 if (itemHandle == HandleOf(
ItemAt(i)))
161 CExports::cvbdim_t numElements = 0;
162 CVB_CALL_CAPI(CVCCompositeGetCount(
Handle(), numElements));
163 return static_cast<int>(numElements);
174 const auto handle = HandleOf(item);
176 [
this, index, handle]() {
return CVB_CALL_CAPI(CVCCompositeInsertAt(
Handle(), index, handle)); });
179 const auto pos = itemCache_.find(handle);
180 if (pos == itemCache_.end())
181 itemCache_.emplace_hint(pos, handle, item);
202 auto item = MakeWrapperFrom(index);
203 const auto handle = HandleOf(item);
206 const auto pos = itemCache_.find(handle);
207 if (pos != itemCache_.end())
210 itemCache_.emplace_hint(pos, handle, item);
221 const auto item = MakeWrapperFrom(index);
223 Internal::DoResCall([&]() {
return CVB_CALL_CAPI(CVCCompositeRemoveAt(
Handle(), index)); });
228 itemCache_.erase(HandleOf(item));
235 return Cvb::visit([](
const auto &obj) {
return obj->Handle(); }, item);
241 HandleGuard<Composite> handle_;
242 mutable std::mutex cacheMtx_;
243 mutable std::unordered_map<void *, CompositeVariant> itemCache_;
44 class Composite final {
…};
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:142
void PushBackItem(const CompositeVariant &item)
Appends a composite item.
Definition decl_composite.hpp:189
void RemoveItemAt(int index)
Remove a composite item specified by its index.
Definition decl_composite.hpp:219
static std::unique_ptr< Composite > Create(CompositePurpose purpose=CompositePurpose::Custom)
Creates a composite with the given optional parameter.
Definition decl_composite.hpp:57
CompositeVariant ItemAt(int index) const
Access to a composite item specified by its index.
Definition decl_composite.hpp:200
int ItemCount() const noexcept
Number of variants in the composite.
Definition decl_composite.hpp:159
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:131
void InsertItemAt(int index, const CompositeVariant &item)
Insert a composite item specified at given index.
Definition decl_composite.hpp:172
MultiPart image class.
Definition multi_part_image.hpp:23
This class is a replacement for C++17 std::variant.
Definition variant.hpp:49
cvbbool_t ShareObject(OBJ Object)
cvbbool_t ReleaseObject(OBJ &Object)
Namespace for driver or device related operations.
Definition decl_composite.hpp:27
Root namespace for the Image Manager interface.
Definition c_bayer_to_rgb.h:17
Cvb::variant< ImagePtr, PlanePtr, PlaneEnumeratorPtr, BufferPtr, PFNCBufferPtr, CompressedPFNCBufferPtr, HandleOnlyPtr > CompositeVariant
Variant that can contain the different types of composite items.
Definition decl_composite.hpp:38
auto visit(VISITOR &&visitor, VARIANT &&var) -> decltype(visitor(get< 0 >(var)))
Visits the given Shims::variant var. Cvb::Shims::visit can only visit one variant (not multiple like ...
Definition variant.hpp:622
std::shared_ptr< Composite > CompositePtr
Convenience shared pointer for Composite.
Definition global.hpp:102