Moritz Pflanzer | 69e44dc | 2017-07-05 11:02:14 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017 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_TEST_DATASET_SINGLETON |
| 25 | #define ARM_COMPUTE_TEST_DATASET_SINGLETON |
| 26 | |
| 27 | #include "ContainerDataset.h" |
| 28 | #include "Dataset.h" |
| 29 | #include "support/ToolchainSupport.h" |
| 30 | |
| 31 | #include <string> |
| 32 | #include <tuple> |
| 33 | #include <type_traits> |
| 34 | #include <utility> |
| 35 | |
| 36 | namespace arm_compute |
| 37 | { |
| 38 | namespace test |
| 39 | { |
| 40 | namespace framework |
| 41 | { |
| 42 | namespace dataset |
| 43 | { |
| 44 | /** Implementation of a dataset holding a single value. */ |
| 45 | template <typename T> |
Moritz Pflanzer | b7c2a99 | 2017-07-18 14:37:35 +0100 | [diff] [blame] | 46 | class SingletonDataset : public NamedDataset |
Moritz Pflanzer | 69e44dc | 2017-07-05 11:02:14 +0100 | [diff] [blame] | 47 | { |
| 48 | public: |
| 49 | /** Construct dataset with given name and value. |
| 50 | * |
| 51 | * @param[in] name Description of the value. |
| 52 | * @param[in] value Value for the dataset. |
| 53 | */ |
| 54 | SingletonDataset(std::string name, T &&value) |
| 55 | : NamedDataset{ std::move(name) }, _value{ std::forward<T>(value) } |
| 56 | { |
| 57 | } |
| 58 | |
| 59 | SingletonDataset(SingletonDataset &&) = default; |
| 60 | |
| 61 | /** Type of the dataset. */ |
| 62 | using type = std::tuple<T>; |
| 63 | |
| 64 | /** Iterator for the dataset. */ |
| 65 | struct iterator |
| 66 | { |
| 67 | iterator(std::string name, const T *value) |
| 68 | : _name{ name }, _value{ value } |
| 69 | { |
| 70 | } |
| 71 | |
| 72 | ~iterator() = default; |
| 73 | |
| 74 | iterator(const iterator &) = default; |
| 75 | iterator &operator=(const iterator &) = default; |
| 76 | iterator(iterator &&) = default; |
| 77 | iterator &operator=(iterator &&) = default; |
| 78 | |
| 79 | std::string description() const |
| 80 | { |
| 81 | using support::cpp11::to_string; |
| 82 | return _name + "=" + to_string(*_value); |
| 83 | } |
| 84 | |
| 85 | SingletonDataset::type operator*() const |
| 86 | { |
| 87 | return std::make_tuple(*_value); |
| 88 | } |
| 89 | |
| 90 | iterator &operator++() |
| 91 | { |
| 92 | return *this; |
| 93 | } |
| 94 | |
| 95 | private: |
| 96 | std::string _name; |
| 97 | const T *_value; |
| 98 | }; |
| 99 | |
| 100 | /** Iterator pointing at the begin of the dataset. |
| 101 | * |
| 102 | * @return Iterator for the dataset. |
| 103 | */ |
| 104 | iterator begin() const |
| 105 | { |
| 106 | return iterator(name(), &_value); |
| 107 | } |
| 108 | |
| 109 | /** Size of the dataset. |
| 110 | * |
| 111 | * @return Number of values in the dataset. |
| 112 | */ |
| 113 | int size() const |
| 114 | { |
| 115 | return 1; |
| 116 | } |
| 117 | |
| 118 | private: |
| 119 | T _value; |
| 120 | }; |
| 121 | |
| 122 | /** Helper function to create a @ref SingletonDataset. |
| 123 | * |
| 124 | * @param[in] name Name of the dataset. |
| 125 | * @param[in] value Value. |
| 126 | * |
| 127 | * @return A singleton dataset. |
| 128 | */ |
| 129 | template <typename T> |
| 130 | typename std::enable_if < !is_container<T>::value, SingletonDataset<T >>::type make(std::string name, T &&value) |
| 131 | { |
| 132 | return SingletonDataset<T>(std::move(name), std::forward<T>(value)); |
| 133 | } |
| 134 | } // namespace dataset |
| 135 | } // namespace framework |
| 136 | } // namespace test |
| 137 | } // namespace arm_compute |
| 138 | #endif /* ARM_COMPUTE_TEST_DATASET_SINGLETON */ |