Moved caseless to Plugin API (#1664)
[platform/upstream/dldt.git] / inference-engine / include / ie_compound_blob.h
1 // Copyright (C) 2018-2020 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
3 //
4
5 /**
6  * @brief A header file for CompoundBlob
7  *
8  * @file ie_compound_blob.h
9  */
10 #pragma once
11
12 #include <initializer_list>
13 #include <memory>
14 #include <vector>
15
16 #include "ie_blob.h"
17
18 namespace InferenceEngine {
19 /**
20  * @brief This class represents a blob that contains other blobs
21  *
22  * Compound blob is a wrapper blob over references to underlying blobs. These blobs should share
23  * some properties and can be grouped into a single entity.
24  */
25 class INFERENCE_ENGINE_API_CLASS(CompoundBlob): public Blob {
26 public:
27     /**
28      * @brief A smart pointer to the CompoundBlob object
29      */
30     using Ptr = std::shared_ptr<CompoundBlob>;
31
32     /**
33      * @brief A smart pointer to the const CompoundBlob object
34      */
35     using CPtr = std::shared_ptr<const CompoundBlob>;
36
37     /**
38      * @brief A virtual destructor
39      */
40     virtual ~CompoundBlob() = default;
41
42     /**
43      * @brief A copy constructor
44      */
45     CompoundBlob(const CompoundBlob& blob);
46
47     /**
48      * @brief A copy assignment operator
49      */
50     CompoundBlob& operator=(const CompoundBlob& blob) = default;
51
52     /**
53      * @brief A move constructor
54      */
55     CompoundBlob(CompoundBlob&& blob);
56
57     /**
58      * @brief A move assignment operator
59      */
60     CompoundBlob& operator=(CompoundBlob&& blob) = default;
61
62     /**
63      * @brief Constructs a compound blob from a vector of blobs
64      *
65      * @param blobs A vector of blobs that is copied to this object
66      */
67     explicit CompoundBlob(const std::vector<Blob::Ptr>& blobs);
68
69     /**
70      * @brief Constructs a compound blob from a vector of blobs
71      *
72      * @param blobs A vector of blobs that is moved to this object
73      */
74     explicit CompoundBlob(std::vector<Blob::Ptr>&& blobs);
75
76     /**
77      * @brief Always returns 0
78      */
79     size_t byteSize() const noexcept override;
80
81     /**
82      * @brief Always returns 0
83      */
84     size_t element_size() const noexcept override;
85
86     /**
87      * @brief No operation is performed. Compound blob does not allocate/deallocate any data
88      */
89     void allocate() noexcept override;
90
91     /**
92      * @brief No operation is performed. Compound blob does not allocate/deallocate any data
93      * @return false
94      */
95     bool deallocate() noexcept override;
96
97     /**
98      * @brief Always returns an empty LockedMemory object
99      */
100     LockedMemory<void> buffer() noexcept override;
101
102     /**
103      * @brief Always returns an empty LockedMemory object
104      */
105     LockedMemory<const void> cbuffer() const noexcept override;
106
107     /**
108      * @brief Returns the number of underlying blobs in the compound blob
109      */
110     size_t size() const noexcept override;
111
112     /**
113      * @brief Returns an underlying blob at index i
114      *
115      * @param i the index of the underlying Blob object
116      * @return A smart pointer to the underlying Blob object or nullptr in case of an error
117      */
118     virtual Blob::Ptr getBlob(size_t i) const noexcept;
119
120     Blob::Ptr createROI(const ROI& roi) const override;
121
122 protected:
123     /**
124      * @brief A default constructor
125      */
126     CompoundBlob();
127
128     /**
129      * @brief Compound blob container for underlying blobs
130      */
131     std::vector<Blob::Ptr> _blobs;
132
133     /**
134      * @brief Returns nullptr as CompoundBlob is not allocator-based
135      */
136     const std::shared_ptr<IAllocator>& getAllocator() const noexcept override;
137
138     /**
139      * @brief Returns nullptr as CompoundBlob is not allocator-based
140      */
141     void* getHandle() const noexcept override;
142 };
143
144 /**
145  * @brief Represents a blob that contains two planes (Y and UV) in NV12 color format
146  */
147 class INFERENCE_ENGINE_API_CLASS(NV12Blob): public CompoundBlob {
148 public:
149     /**
150      * @brief A smart pointer to the NV12Blob object
151      */
152     using Ptr = std::shared_ptr<NV12Blob>;
153
154     /**
155      * @brief A smart pointer to the const NV12Blob object
156      */
157     using CPtr = std::shared_ptr<const NV12Blob>;
158
159     /**
160      * @brief A deleted default constructor
161      */
162     NV12Blob() = delete;
163
164     /**
165      * @brief Constructs NV12 blob from two planes Y and UV
166      *
167      * @param y Blob object that represents Y plane in NV12 color format
168      * @param uv Blob object that represents UV plane in NV12 color format
169      */
170     NV12Blob(const Blob::Ptr& y, const Blob::Ptr& uv);
171
172     /**
173      * @brief Constructs NV12 blob from two planes Y and UV
174      *
175      * @param y Blob object that represents Y plane in NV12 color format
176      * @param uv Blob object that represents UV plane in NV12 color format
177      */
178     NV12Blob(Blob::Ptr&& y, Blob::Ptr&& uv);
179
180     /**
181      * @brief A virtual destructor
182      */
183     virtual ~NV12Blob() = default;
184
185     /**
186      * @brief A copy constructor
187      */
188     NV12Blob(const NV12Blob& blob) = default;
189
190     /**
191      * @brief A copy assignment operator
192      */
193     NV12Blob& operator=(const NV12Blob& blob) = default;
194
195     /**
196      * @brief A move constructor
197      */
198     NV12Blob(NV12Blob&& blob) = default;
199
200     /**
201      * @brief A move assignment operator
202      */
203     NV12Blob& operator=(NV12Blob&& blob) = default;
204
205     /**
206      * @brief Returns a shared pointer to Y plane
207      */
208     virtual Blob::Ptr& y() noexcept;
209
210     /**
211      * @brief Returns a shared pointer to Y plane
212      */
213     virtual const Blob::Ptr& y() const noexcept;
214
215     /**
216      * @brief Returns a shared pointer to UV plane
217      */
218     virtual Blob::Ptr& uv() noexcept;
219
220     /**
221      * @brief Returns a shared pointer to UV plane
222      */
223     virtual const Blob::Ptr& uv() const noexcept;
224
225     Blob::Ptr createROI(const ROI& roi) const override;
226 };
227
228 /**
229  * @brief Represents a blob that contains three planes (Y,U and V) in I420 color format
230  */
231 class INFERENCE_ENGINE_API_CLASS(I420Blob) : public CompoundBlob {
232 public:
233     /**
234      * @brief A smart pointer to the I420Blob object
235      */
236     using Ptr = std::shared_ptr<I420Blob>;
237
238     /**
239      * @brief A smart pointer to the const I420Blob object
240      */
241     using CPtr = std::shared_ptr<const I420Blob>;
242
243     /**
244      * @brief A deleted default constructor
245      */
246     I420Blob() = delete;
247
248     /**
249      * @brief Constructs I420 blob from three planes Y, U and V
250      * @param y Blob object that represents Y plane in I420 color format
251      * @param u Blob object that represents U plane in I420 color format
252      * @param v Blob object that represents V plane in I420 color format
253      */
254     I420Blob(const Blob::Ptr& y, const Blob::Ptr& u, const Blob::Ptr& v);
255
256     /**
257      * @brief Constructs I420 blob from three planes Y, U and V
258      * @param y Blob object that represents Y plane in I420 color format
259      * @param u Blob object that represents U plane in I420 color format
260      * @param v Blob object that represents V plane in I420 color format
261      */
262     I420Blob(Blob::Ptr&& y, Blob::Ptr&& u, Blob::Ptr&& v);
263
264     /**
265      * @brief A virtual destructor. It is made out of line for RTTI to
266      * work correctly on some platforms.
267      */
268     virtual ~I420Blob();
269
270     /**
271      * @brief A copy constructor
272      */
273     I420Blob(const I420Blob& blob) = default;
274
275     /**
276      * @brief A copy assignment operator
277      */
278     I420Blob& operator=(const I420Blob& blob) = default;
279
280     /**
281      * @brief A move constructor
282      */
283     I420Blob(I420Blob&& blob) = default;
284
285     /**
286      * @brief A move assignment operator
287      */
288     I420Blob& operator=(I420Blob&& blob) = default;
289
290     /**
291      * @brief Returns a reference to shared pointer to Y plane
292      *
293      * Please note that reference to Blob::Ptr is returned. I.e. the reference will be valid until
294      * the I420Blob object is destroyed.
295      *
296      * @return reference to shared pointer object of Y plane
297      */
298     Blob::Ptr& y() noexcept;
299
300     /**
301      * @brief Returns a constant reference to shared pointer to Y plane
302      *
303      * Please note that reference to Blob::Ptr is returned. I.e. the reference will be valid until
304      * the I420Blob object is destroyed.
305      *
306       * @return constant reference to shared pointer object of Y plane*
307      */
308     const Blob::Ptr& y() const noexcept;
309
310     /**
311      * @brief Returns a reference to shared pointer to U plane
312      *
313      * Please note that reference to Blob::Ptr is returned. I.e. the reference will be valid until
314      * the I420Blob object is destroyed.
315      *
316      * @return reference to shared pointer object of U plane
317      */
318     Blob::Ptr& u() noexcept;
319
320     /**
321      * @brief Returns a constant reference to shared pointer to U plane
322      *
323      * Please note that reference to Blob::Ptr is returned. I.e. the reference will be valid until
324      * the I420Blob object is destroyed.
325      *
326      * @return constant reference to shared pointer object of U plane
327      */
328     const Blob::Ptr& u() const noexcept;
329
330     /**
331      * @brief Returns a reference to shared pointer to V plane
332      *
333      * Please note that reference to Blob::Ptr is returned. I.e. the reference will be valid until
334      * the I420Blob object is destroyed.
335      *
336      * @return reference to shared pointer object of V plane
337      */
338     Blob::Ptr& v() noexcept;
339
340     /**
341      * @brief Returns a constant reference to shared pointer to V plane
342      *
343      * Please note that reference to Blob::Ptr is returned. I.e. the reference will be valid until
344      * the I420Blob object is destroyed.
345      *
346      * @return constant reference to shared pointer object of V plane
347      */
348     const Blob::Ptr& v() const noexcept;
349
350     Blob::Ptr createROI(const ROI& roi) const override;
351 };
352 }  // namespace InferenceEngine