ie_blob_iterator.hpp
Go to the documentation of this file.
1 // Copyright (C) 2018-2020 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
3 //
4 
5 /**
6  * @brief A header file for the BlobIterator class
7  *
8  * @file ie_blob_iterator.hpp
9  */
10 
11 #include <utility>
12 
13 #include "ie_locked_memory.hpp"
14 
15 namespace InferenceEngine {
16 namespace details {
17 /**
18  * @brief This class provides range loops support for TBlob objects
19  */
20 template <class T>
21 class BlobIterator {
22  LockedMemory<T> _mem;
23  size_t _offset;
24 
25 public:
26  /**
27  * @brief A move constructor to create a BlobIterator instance from a LockedMemory instance.
28  * Explicitly rejects implicit conversions.
29  * @param lk Rvalue of the memory instance to move from
30  * @param offset Size of offset in memory
31  */
32  explicit BlobIterator(LockedMemory<T>&& lk, size_t offset = 0): _mem(std::move(lk)), _offset(offset) {}
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
Inference Engine API.
Definition: ie_argmax_layer.hpp:15
A header file for generic LockedMemory<> and different variations of locks.