Moritz Pflanzer | 09e4f98 | 2017-08-30 12:47:06 +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_MEASUREMENT |
| 25 | #define ARM_COMPUTE_TEST_MEASUREMENT |
| 26 | |
| 27 | #include "../Utils.h" |
| 28 | |
| 29 | #include <ostream> |
| 30 | #include <string> |
| 31 | |
| 32 | namespace arm_compute |
| 33 | { |
| 34 | namespace test |
| 35 | { |
| 36 | namespace framework |
| 37 | { |
| 38 | /** Abstract measurement. |
| 39 | * |
| 40 | * Every measurement needs to define it's unit. |
| 41 | */ |
| 42 | struct IMeasurement |
| 43 | { |
| 44 | /** Constructor. |
| 45 | * |
| 46 | * @param[in] unit Unit of the measurement. |
| 47 | */ |
| 48 | explicit IMeasurement(std::string unit) |
| 49 | : unit{ std::move(unit) } |
| 50 | { |
| 51 | } |
| 52 | |
| 53 | const std::string unit; |
| 54 | }; |
| 55 | |
| 56 | /** Meaurement of a specific type. */ |
| 57 | template <typename T> |
| 58 | struct TypedMeasurement : public IMeasurement |
| 59 | { |
| 60 | /** Constructor. |
| 61 | * |
| 62 | * @param[in] value Measured value. |
| 63 | * @param[in] unit Unit of the Measurement. |
| 64 | */ |
| 65 | TypedMeasurement(T value, std::string unit) |
| 66 | : IMeasurement(std::move(unit)), value{ value } |
| 67 | { |
| 68 | } |
| 69 | |
| 70 | T value; |
| 71 | }; |
| 72 | |
| 73 | /** Stream output operator to print the measurement. |
| 74 | * |
| 75 | * Prints value and unit. |
| 76 | */ |
| 77 | template <typename T> |
| 78 | inline std::ostream &operator<<(std::ostream &os, const TypedMeasurement<T> &measurement) |
| 79 | { |
| 80 | os << measurement.value << measurement.unit; |
| 81 | return os; |
| 82 | } |
| 83 | |
| 84 | /** Generic measurement that stores values as double. */ |
| 85 | struct Measurement : public TypedMeasurement<double> |
| 86 | { |
| 87 | using TypedMeasurement::TypedMeasurement; |
| 88 | |
| 89 | /** Conversion constructor. |
| 90 | * |
| 91 | * @param[in] measurement Typed measurement. |
| 92 | */ |
| 93 | template <typename T> |
| 94 | Measurement(TypedMeasurement<T> measurement) |
| 95 | : Measurement(measurement.value, measurement.unit) |
| 96 | { |
| 97 | } |
| 98 | }; |
| 99 | } // namespace framework |
| 100 | } // namespace test |
| 101 | } // namespace arm_compute |
| 102 | #endif /* ARM_COMPUTE_TEST_MEASUREMENT */ |