Moritz Pflanzer | d03b00a | 2017-07-17 13:50:12 +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_MODES |
| 25 | #define ARM_COMPUTE_TEST_DATASET_MODES |
| 26 | |
| 27 | #include <istream> |
| 28 | #include <ostream> |
| 29 | #include <sstream> |
| 30 | #include <stdexcept> |
| 31 | #include <string> |
| 32 | |
| 33 | namespace arm_compute |
| 34 | { |
| 35 | namespace test |
| 36 | { |
| 37 | namespace framework |
| 38 | { |
| 39 | /** Possible dataset modes. */ |
| 40 | enum class DatasetMode : unsigned int |
| 41 | { |
| 42 | ALL = ~0U, |
| 43 | DISABLED = 0, |
| 44 | PRECOMMIT = 1, |
| 45 | NIGHTLY = 2 |
| 46 | }; |
| 47 | |
| 48 | inline DatasetMode operator&(DatasetMode t1, DatasetMode t2) |
| 49 | { |
| 50 | using type = std::underlying_type<DatasetMode>::type; |
| 51 | return static_cast<DatasetMode>(static_cast<type>(t1) & static_cast<type>(t2)); |
| 52 | } |
| 53 | |
| 54 | inline DatasetMode operator|(DatasetMode t1, DatasetMode t2) |
| 55 | { |
| 56 | using type = std::underlying_type<DatasetMode>::type; |
| 57 | return static_cast<DatasetMode>(static_cast<type>(t1) | static_cast<type>(t2)); |
| 58 | } |
| 59 | |
| 60 | inline DatasetMode &operator|=(DatasetMode &t1, DatasetMode t2) |
| 61 | { |
| 62 | using type = std::underlying_type<DatasetMode>::type; |
| 63 | t1 = static_cast<DatasetMode>(static_cast<type>(t1) | static_cast<type>(t2)); |
| 64 | return t1; |
| 65 | } |
| 66 | |
| 67 | DatasetMode dataset_mode_from_name(const std::string &name); |
| 68 | |
| 69 | inline ::std::istream &operator>>(::std::istream &stream, DatasetMode &mode) |
| 70 | { |
| 71 | std::string value; |
| 72 | stream >> value; |
| 73 | mode = dataset_mode_from_name(value); |
| 74 | return stream; |
| 75 | } |
| 76 | |
| 77 | inline ::std::ostream &operator<<(::std::ostream &stream, DatasetMode mode) |
| 78 | { |
| 79 | switch(mode) |
| 80 | { |
| 81 | case DatasetMode::PRECOMMIT: |
| 82 | stream << "PRECOMMIT"; |
| 83 | break; |
| 84 | case DatasetMode::NIGHTLY: |
| 85 | stream << "NIGHTLY"; |
| 86 | break; |
| 87 | case DatasetMode::ALL: |
| 88 | stream << "ALL"; |
| 89 | break; |
| 90 | default: |
| 91 | throw std::invalid_argument("Unsupported dataset mode"); |
| 92 | } |
| 93 | |
| 94 | return stream; |
| 95 | } |
| 96 | |
| 97 | inline std::string to_string(DatasetMode mode) |
| 98 | { |
| 99 | std::stringstream stream; |
| 100 | stream << mode; |
| 101 | return stream.str(); |
| 102 | } |
| 103 | } // namespace framework |
| 104 | } // namespace test |
| 105 | } // namespace arm_compute |
| 106 | #endif /* ARM_COMPUTE_TEST_DATASET_MODES */ |