Jonas Oreland | ed99dae | 2022-03-09 09:28:10 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2020 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
| 11 | #ifndef TEST_SCOPED_KEY_VALUE_CONFIG_H_ |
| 12 | #define TEST_SCOPED_KEY_VALUE_CONFIG_H_ |
| 13 | |
Danil Chapovalov | 385b6c5 | 2022-04-08 16:01:50 +0200 | [diff] [blame] | 14 | #include <functional> |
Jonas Oreland | ed99dae | 2022-03-09 09:28:10 +0100 | [diff] [blame] | 15 | #include <map> |
| 16 | #include <memory> |
| 17 | #include <string> |
| 18 | |
| 19 | #include "absl/strings/string_view.h" |
Jonas Oreland | e62c2f2 | 2022-03-29 11:04:48 +0200 | [diff] [blame] | 20 | #include "api/field_trials_view.h" |
Jonas Oreland | ed99dae | 2022-03-09 09:28:10 +0100 | [diff] [blame] | 21 | #include "test/field_trial.h" |
| 22 | |
| 23 | namespace webrtc { |
| 24 | namespace test { |
| 25 | |
Jonas Oreland | e62c2f2 | 2022-03-29 11:04:48 +0200 | [diff] [blame] | 26 | class ScopedKeyValueConfig : public FieldTrialsView { |
Jonas Oreland | ed99dae | 2022-03-09 09:28:10 +0100 | [diff] [blame] | 27 | public: |
| 28 | virtual ~ScopedKeyValueConfig(); |
| 29 | ScopedKeyValueConfig(); |
Danil Chapovalov | 385b6c5 | 2022-04-08 16:01:50 +0200 | [diff] [blame] | 30 | explicit ScopedKeyValueConfig(absl::string_view s); |
| 31 | ScopedKeyValueConfig(ScopedKeyValueConfig& parent, absl::string_view s); |
Jonas Oreland | ed99dae | 2022-03-09 09:28:10 +0100 | [diff] [blame] | 32 | |
| 33 | std::string Lookup(absl::string_view key) const override; |
| 34 | |
| 35 | private: |
Danil Chapovalov | 385b6c5 | 2022-04-08 16:01:50 +0200 | [diff] [blame] | 36 | ScopedKeyValueConfig(ScopedKeyValueConfig* parent, absl::string_view s); |
Jonas Oreland | ed99dae | 2022-03-09 09:28:10 +0100 | [diff] [blame] | 37 | ScopedKeyValueConfig* GetRoot(ScopedKeyValueConfig* n); |
| 38 | std::string LookupRecurse(absl::string_view key) const; |
| 39 | |
| 40 | ScopedKeyValueConfig* const parent_; |
| 41 | |
| 42 | // The leaf in a list of stacked ScopedKeyValueConfig. |
| 43 | // Only set on root (e.g with parent_ == nullptr). |
| 44 | const ScopedKeyValueConfig* leaf_; |
| 45 | |
Danil Chapovalov | 385b6c5 | 2022-04-08 16:01:50 +0200 | [diff] [blame] | 46 | // Unlike std::less<std::string>, std::less<> is transparent and allows |
| 47 | // heterogeneous lookup directly with absl::string_view. |
| 48 | std::map<std::string, std::string, std::less<>> key_value_map_; |
Jonas Oreland | ed99dae | 2022-03-09 09:28:10 +0100 | [diff] [blame] | 49 | std::unique_ptr<ScopedFieldTrials> scoped_field_trials_; |
| 50 | }; |
| 51 | |
| 52 | } // namespace test |
| 53 | } // namespace webrtc |
| 54 | |
| 55 | #endif // TEST_SCOPED_KEY_VALUE_CONFIG_H_ |