Compute Library  18.05
IArray.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016-2018 ARM Limited.
3  *
4  * SPDX-License-Identifier: MIT
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to
8  * deal in the Software without restriction, including without limitation the
9  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10  * sell copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in all
14  * copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 #ifndef __ARM_COMPUTE_IARRAY_H__
25 #define __ARM_COMPUTE_IARRAY_H__
26 
27 #include "arm_compute/core/Error.h"
28 #include <cstddef>
29 #include <cstdint>
30 
31 namespace arm_compute
32 {
33 struct KeyPoint;
34 struct Coordinates2D;
35 struct DetectionWindow;
36 class Size2D;
37 struct ROI;
38 
40 template <class T>
41 class IArray
42 {
43 public:
46  : _num_values(0), _max_size(0) {};
52  : _num_values(0), _max_size(max_num_values)
53  {
54  }
59  size_t max_num_values() const
60  {
61  return _max_size;
62  }
64  virtual ~IArray() = default;
69  size_t num_values() const
70  {
71  return _num_values;
72  }
79  bool push_back(const T &val)
80  {
81  ARM_COMPUTE_ERROR_ON(0 == _max_size);
82  if(_num_values >= max_num_values())
83  {
84  _num_values = max_num_values() + 1;
85  return false;
86  }
87  at(_num_values) = val;
88  _num_values++;
89  return true;
90  }
92  void clear()
93  {
94  _num_values = 0;
95  }
101  bool overflow() const
102  {
103  return _num_values > max_num_values();
104  }
111  virtual T *buffer() const = 0;
118  virtual T &at(size_t index) const
119  {
120  ARM_COMPUTE_ERROR_ON(buffer() == nullptr);
122  return buffer()[index];
123  }
129  void resize(size_t num)
130  {
132  _num_values = num;
133  };
134 
135 private:
136  size_t _num_values;
137  size_t _max_size;
138 };
161 }
162 #endif /* __ARM_COMPUTE_IARRAY_H__ */
void clear()
Clear all the points from the array.
Definition: IArray.h:92
Detection window struct.
Definition: types.h:47
bool overflow() const
Did we lose some values because the array is too small?
Definition: IArray.h:101
2D Coordinates structure
Definition: types.h:28
Array of type T.
Definition: IArray.h:41
void resize(size_t num)
Resizes the array to contain "num" elements.
Definition: IArray.h:129
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:328
This file contains all available output stages for GEMMLowp on OpenCL.
IArray()
Default constructor.
Definition: IArray.h:45
virtual T * buffer() const =0
Pointer to the first element of the array.
IArray(size_t max_num_values)
Constructor: initializes an array which can contain up to max_num_points values.
Definition: IArray.h:51
size_t max_num_values() const
Maximum number of values which can be stored in this array.
Definition: IArray.h:59
size_t num_values() const
Number of values currently stored in the array.
Definition: IArray.h:69
virtual T & at(size_t index) const
Reference to the element of the array located at the given index.
Definition: IArray.h:118
bool push_back(const T &val)
Append the passed argument to the end of the array if there is room.
Definition: IArray.h:79
virtual ~IArray()=default
Default virtual destructor.