Jonas Oreland | ed99dae | 2022-03-09 08:28:10 | [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 | |
| 14 | #include <map> |
| 15 | #include <memory> |
| 16 | #include <string> |
| 17 | |
| 18 | #include "absl/strings/string_view.h" |
Jonas Oreland | e62c2f2 | 2022-03-29 09:04:48 | [diff] [blame] | 19 | #include "api/field_trials_view.h" |
Jonas Oreland | ed99dae | 2022-03-09 08:28:10 | [diff] [blame] | 20 | #include "test/field_trial.h" |
| 21 | |
| 22 | namespace webrtc { |
| 23 | namespace test { |
| 24 | |
Jonas Oreland | e62c2f2 | 2022-03-29 09:04:48 | [diff] [blame] | 25 | class ScopedKeyValueConfig : public FieldTrialsView { |
Jonas Oreland | ed99dae | 2022-03-09 08:28:10 | [diff] [blame] | 26 | public: |
| 27 | virtual ~ScopedKeyValueConfig(); |
| 28 | ScopedKeyValueConfig(); |
| 29 | explicit ScopedKeyValueConfig(const std::string& s); |
| 30 | ScopedKeyValueConfig(ScopedKeyValueConfig& parent, const std::string& s); |
| 31 | |
| 32 | std::string Lookup(absl::string_view key) const override; |
| 33 | |
| 34 | private: |
| 35 | ScopedKeyValueConfig(ScopedKeyValueConfig* parent, const std::string& s); |
| 36 | ScopedKeyValueConfig* GetRoot(ScopedKeyValueConfig* n); |
| 37 | std::string LookupRecurse(absl::string_view key) const; |
| 38 | |
| 39 | ScopedKeyValueConfig* const parent_; |
| 40 | |
| 41 | // The leaf in a list of stacked ScopedKeyValueConfig. |
| 42 | // Only set on root (e.g with parent_ == nullptr). |
| 43 | const ScopedKeyValueConfig* leaf_; |
| 44 | |
| 45 | std::map<std::string, std::string> key_value_map_; |
| 46 | std::unique_ptr<ScopedFieldTrials> scoped_field_trials_; |
| 47 | }; |
| 48 | |
| 49 | } // namespace test |
| 50 | } // namespace webrtc |
| 51 | |
| 52 | #endif // TEST_SCOPED_KEY_VALUE_CONFIG_H_ |