Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / include / details / ie_blob_iterator.hpp
1 // Copyright (C) 2018-2019 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
3 //
4
5 /**
6  * @brief A header file for the BlobIterator class
7  * @file ie_blob_iterator.hpp
8  */
9
10 #include "ie_locked_memory.hpp"
11 #include <utility>
12
13 namespace InferenceEngine {
14 namespace details {
15 /**
16  * @brief This class provides range loops support for TBlob objects
17  */
18 template<class T>
19 class BlobIterator {
20     LockedMemory<T> _mem;
21     size_t _offset;
22
23 public:
24     /**
25      * @brief A move constructor to create a BlobIterator instance from a LockedMemory instance.
26      * Explicitly rejects implicit conversions.
27      * @param lk Rvalue of the memory instance to move from
28      * @param offset Size of offset in memory
29      */
30     explicit BlobIterator(LockedMemory<T> &&lk, size_t offset = 0)
31             : _mem(std::move(lk)), _offset(offset) {
32     }
33
34     /**
35      * @brief Increments an offset of the current BlobIterator instance
36      * @return The current BlobIterator instance
37      */
38     BlobIterator &operator++() {
39         _offset++;
40         return *this;
41     }
42
43     /**
44      * @brief An overloaded postfix incrementation operator
45      * Implementation does not follow std interface since only move semantics is used
46      */
47     void operator++(int) {
48         _offset++;
49     }
50
51     /**
52      * @brief Checks if the given iterator is not equal to the current one
53      * @param that Iterator to compare with
54      * @return true if the given iterator is not equal to the current one, false - otherwise
55      */
56     bool operator!=(const BlobIterator &that) const {
57         return !operator==(that);
58     }
59
60     /**
61      * @brief Gets a value by the pointer to the current iterator
62      * @return The value stored in memory for the current offset value
63      */
64     const T &operator*() const {
65         return *(_mem.template as<const T *>() + _offset);
66     }
67
68     /**
69      * @brief Gets a value by the pointer to the current iterator
70      * @return The value stored in memory for the current offset value
71      */
72     T &operator*() {
73         return *(_mem.template as<T *>() + _offset);
74     }
75     /**
76      * @brief Compares the given iterator with the current one
77      * @param that Iterator to compare with
78      * @return true if the given iterator is equal to the current one, false - otherwise
79      */
80     bool operator==(const BlobIterator &that) const {
81         return &operator*() == &that.operator*();
82     }
83 };
84 }  // namespace details
85 }  // namespace InferenceEngine