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