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 "../driver/gendc_descriptor.hpp"
14#include "../exception.hpp"
15#include "../global.hpp"
16#include "../image.hpp"
17#include "../buffer.hpp"
18#include "../pfnc_buffer.hpp"
19#include "../compressed_pfnc_buffer.hpp"
20#include "../handle_only.hpp"
21#include "../shims/stdvariant.hpp"
33 inline HandleGuard<Composite>::HandleGuard(
void *handle) noexcept
34 : HandleGuard<Composite>(handle, [](
void *handle) { CVB_CALL_CAPI(
ReleaseObject(handle)); })
54 using GuardType = HandleGuard<Composite>;
64 return Internal::DoHandleCallObjectOut<class Composite>(
65 CVB_CALL_CAPI(CVCCreateComposite(
static_cast<CExports::CVCCompositePurpose
>(purpose))));
69 template <
class OTHER>
75 explicit Composite(HandleGuard<Composite> &&guard)
76 : handle_(std::move(guard))
78 if (!CVB_CALL_CAPI(CVCIsComposite(
Handle())))
82 static HandleGuard<Composite> MakeShared(
void *handle)
noexcept
85 return HandleGuard<Composite>{handle};
98 return handle_.Handle();
138 CExports::CVCCompositePurpose purpose = CExports::CVCCompositePurpose::CVCCP_Custom;
139 CVB_CALL_CAPI(CVCCompositeGetPurpose(
Handle(), purpose));
140 return static_cast<CompositePurpose
>(purpose);
150 if (!CExports::CVDCanGenDCDescriptorProvider(
Handle()))
153 return Internal::DoResCallObjectOut<Driver::GenDcDescriptor>([
this](CExports::CVDGNDCDESCRIPTOR &handle) {
154 return CVB_CALL_CAPI(CVDGNDCPGetDescriptor(
Handle(), handle));
164 const auto itemHandle = HandleOf(item);
166 for (
auto i =
ItemCount() - 1; i >= 0; --i)
168 if (itemHandle == HandleOf(
ItemAt(i)))
181 CExports::cvbdim_t numElements = 0;
182 CVB_CALL_CAPI(CVCCompositeGetCount(
Handle(), numElements));
183 return static_cast<int>(numElements);
194 const auto handle = HandleOf(item);
196 [
this, index, handle]() {
return CVB_CALL_CAPI(CVCCompositeInsertAt(
Handle(), index, handle)); });
199 const auto pos = itemCache_.find(handle);
200 if (pos == itemCache_.end())
201 itemCache_.emplace_hint(pos, handle, item);
222 auto item = MakeWrapperFrom(index);
223 const auto handle = HandleOf(item);
226 const auto pos = itemCache_.find(handle);
227 if (pos != itemCache_.end())
230 itemCache_.emplace_hint(pos, handle, item);
241 const auto item = MakeWrapperFrom(index);
243 Internal::DoResCall([&]() {
return CVB_CALL_CAPI(CVCCompositeRemoveAt(
Handle(), index)); });
248 itemCache_.erase(HandleOf(item));
255 return Cvb::visit([](
const auto &obj) {
return obj->Handle(); }, item);
261 HandleGuard<Composite> handle_;
262 mutable std::mutex cacheMtx_;
263 mutable std::unordered_map<void *, CompositeVariant> itemCache_;
49 class Composite final {
…};
Component class is a container for CVB objects.
Definition decl_composite.hpp:50
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:162
void PushBackItem(const CompositeVariant &item)
Appends a composite item.
Definition decl_composite.hpp:209
void RemoveItemAt(int index)
Remove a composite item specified by its index.
Definition decl_composite.hpp:239
static std::unique_ptr< Composite > Create(CompositePurpose purpose=CompositePurpose::Custom)
Creates a composite with the given optional parameter.
Definition decl_composite.hpp:62
CompositeVariant ItemAt(int index) const
Access to a composite item specified by its index.
Definition decl_composite.hpp:220
int ItemCount() const noexcept
Number of variants in the composite.
Definition decl_composite.hpp:179
static std::unique_ptr< Composite > FromHandle(HandleGuard< Composite > &&guard)
Creates a composite from a classic API handle.
Definition decl_composite.hpp:109
void * Handle() const noexcept
Classic API node handle.
Definition decl_composite.hpp:96
std::unique_ptr< Driver::GenDcDescriptor > GenDCFinalDescriptor() const
If this Composite represents a GenDC container, returns the GenDC final descriptor.
Definition decl_composite.hpp:148
CompositePurpose Purpose() const noexcept
Gets the purpose of this Composite.
Definition decl_composite.hpp:136
void InsertItemAt(int index, const CompositeVariant &item)
Insert a composite item specified at given index.
Definition decl_composite.hpp:192
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:28
Root namespace for the Image Manager interface.
Definition c_bayer_to_rgb.h:17
std::shared_ptr< HandleOnly > HandleOnlyPtr
Convenience shared pointer for HandleOnly.
Definition global.hpp:106
std::shared_ptr< PFNCBuffer > PFNCBufferPtr
Convenience shared pointer for PFNCBuffer.
Definition global.hpp:70
std::shared_ptr< Buffer > BufferPtr
Convenience shared pointer for Buffer.
Definition global.hpp:62
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< Image > ImagePtr
Convenience shared pointer for Image.
Definition global.hpp:86
std::shared_ptr< PlaneEnumerator > PlaneEnumeratorPtr
Convenience shared pointer for PlaneEnumerator.
Definition global.hpp:82
Cvb::variant< ImagePtr, PlanePtr, PlaneEnumeratorPtr, BufferPtr, PFNCBufferPtr, CompressedPFNCBufferPtr, HandleOnlyPtr > CompositeVariant
Variant that can contain the different types of composite items.
Definition decl_composite.hpp:39
std::shared_ptr< CompressedPFNCBuffer > CompressedPFNCBufferPtr
Convenience shared pointer for a compressed PFNCBuffer.
Definition global.hpp:74
std::shared_ptr< Composite > CompositePtr
Convenience shared pointer for Composite.
Definition global.hpp:102
std::shared_ptr< Plane > PlanePtr
Convenience shared pointer for Plane.
Definition global.hpp:78