Craig Hesling | 240147a | 2019-07-22 13:17:33 -0700 | [diff] [blame] | 1 | // Copyright 2019 The Chromium OS Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef BIOD_UTILS_H_ |
| 6 | #define BIOD_UTILS_H_ |
| 7 | |
Craig Hesling | dedf722 | 2021-04-08 13:08:34 -0700 | [diff] [blame] | 8 | #include <string> |
Craig Hesling | 240147a | 2019-07-22 13:17:33 -0700 | [diff] [blame] | 9 | #include <type_traits> |
| 10 | |
| 11 | namespace biod { |
| 12 | |
| 13 | // This function can be used to fetch the value of an enum |
| 14 | // typecasted to it's base type (int if none specified). |
| 15 | // |
| 16 | // enum class FlockSize : uint8_t { |
| 17 | // kOne = 1, |
| 18 | // kTwo, |
| 19 | // ... |
| 20 | // }; |
| 21 | // |
| 22 | // uint8_t total_animals = to_utype(FlockSize::kTwo); |
| 23 | template <typename E> |
| 24 | constexpr auto to_utype(E enumerator) noexcept { |
| 25 | return static_cast<std::underlying_type_t<E>>(enumerator); |
| 26 | } |
| 27 | |
Craig Hesling | dedf722 | 2021-04-08 13:08:34 -0700 | [diff] [blame] | 28 | /** |
| 29 | * @brief Convert id to a privacy preserving identifier string. |
| 30 | * |
| 31 | * Log files are uploaded via crash reports and feedback reports. |
| 32 | * This function helps ensure that the IDs logged are only unique within |
| 33 | * a single crash/feedback report and not across many different reports. |
| 34 | * Only use this string for logging purposes. |
| 35 | * |
| 36 | * @param id A plain text string id. |
| 37 | * @return std::string The mutated loggable id string. |
| 38 | */ |
| 39 | std::string LogSafeID(const std::string& id); |
| 40 | |
Craig Hesling | 240147a | 2019-07-22 13:17:33 -0700 | [diff] [blame] | 41 | } // namespace biod |
| 42 | |
| 43 | #endif // BIOD_UTILS_H_ |