CVB++ 15.0
image_stream.hpp
1#pragma once
2
3#include <memory>
4
5#include "composite_stream_base.hpp"
6#include "multi_part_image.hpp"
7
8namespace Cvb
9{
10
11CVB_BEGIN_INLINE_NS
12
13namespace Driver
14{
15
17
19 : public CompositeStreamBase
20{
21 public:
22
23 using GuardType = HandleGuard<CompositeStreamBase>;
24
25 ImageStream(HandleGuard<CompositeStreamBase>&& guard, PrivateTag, const DevicePtr& device)
26 : CompositeStreamBase(device, std::move(guard))
27 {
28 }
29
31
37 template<class Rep, class Period>
39 {
40 return CreateWaitResult(InternalWaitFor<Image>(timeSpan, token));
41 }
42
44
49 template<class Rep, class Period>
51 {
52 return CreateWaitResult(InternalWaitFor<Image>(timeSpan));
53 }
54
56
62 {
63 return CreateWaitResult(InternalWait<Image>(token));
64 }
65
67
72 {
73 return CreateWaitResult(InternalWait<Image>());
74 }
75
76 private:
77
78 WaitResultTuple<MultiPartImage> CreateWaitResult(WaitResultBase<Image>&& waitResultBase)
79 {
80 HandleGuard<Image> guard(nullptr);
81 WaitStatus waitStatus = WaitStatus::Ok;
82 std::tie(guard, waitStatus) = std::move(waitResultBase);
83 if (!guard.Handle())
84 return std::make_tuple(MultiPartImagePtr(), waitStatus, NodeMapEnumerator());
85 else
86 {
87 if (!CVB_CALL_CAPI(IsImage(guard.Handle())))
88 throw std::runtime_error("acquired composite is not an image");
89 MultiPartImagePtr image = Image::FromHandle<MultiPartImage>(std::move(guard));
90 return std::make_tuple(image, waitStatus, NodeMapEnumerator::FromObject(*image));
91 }
92 }
93};
94
95}
96
97using Driver::ImageStream;
98
99CVB_END_INLINE_NS
100
101}
102
A token to enable cancellation on wait operations.
Definition: cancellation_token.hpp:20
Base class of all composite based streams.
Definition: decl_composite_stream_base.hpp:32
Streams images.
Definition: image_stream.hpp:20
WaitResultTuple< MultiPartImage > WaitFor(const std::chrono::duration< Rep, Period > &timeSpan, CancellationToken &token)
Waits for the given time span for the next acquired image.
Definition: image_stream.hpp:38
WaitResultTuple< MultiPartImage > Wait(const CancellationToken &token)
Waits for ever for the next acquired image.
Definition: image_stream.hpp:61
WaitResultTuple< MultiPartImage > Wait()
Waits for ever for the next acquired image.
Definition: image_stream.hpp:71
WaitResultTuple< MultiPartImage > WaitFor(const std::chrono::duration< Rep, Period > &timeSpan)
Waits for the given time span for the next acquired image.
Definition: image_stream.hpp:50
Lazy enumeration of node maps.
Definition: node_map_enumerator.hpp:31
static NodeMapEnumerator FromObject(const T &object)
Create a node map enumerator for a given object.
Definition: node_map_enumerator.hpp:88
std::shared_ptr< MultiPartImage > MultiPartImagePtr
Convenience shared pointer for StreamImage.
Definition: driver.hpp:88
Root namespace for the Image Manager interface.
Definition: c_barcode.h:24
WaitStatus
Status after waiting for an image to be returned.
Definition: global.hpp:376
@ Ok
Everything is fine, a new image arrived.