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