blob: c0023f8228ec3c9b7e73bab8fa16581ed57143ec [file] [log] [blame]
Jonas Orelanded99dae2022-03-09 08:28:101/*
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 Chapovalov385b6c52022-04-08 14:01:5014#include <functional>
Jonas Orelanded99dae2022-03-09 08:28:1015#include <map>
16#include <memory>
17#include <string>
18
19#include "absl/strings/string_view.h"
Emil Lundmark1c8103d2022-09-21 13:20:2220#include "api/field_trials_registry.h"
Jonas Orelanded99dae2022-03-09 08:28:1021#include "test/field_trial.h"
22
23namespace webrtc {
24namespace test {
25
Emil Lundmark1c8103d2022-09-21 13:20:2226class ScopedKeyValueConfig : public FieldTrialsRegistry {
Jonas Orelanded99dae2022-03-09 08:28:1027 public:
28 virtual ~ScopedKeyValueConfig();
29 ScopedKeyValueConfig();
Danil Chapovalov385b6c52022-04-08 14:01:5030 explicit ScopedKeyValueConfig(absl::string_view s);
31 ScopedKeyValueConfig(ScopedKeyValueConfig& parent, absl::string_view s);
Jonas Orelanded99dae2022-03-09 08:28:1032
Jonas Orelanded99dae2022-03-09 08:28:1033 private:
Danil Chapovalov385b6c52022-04-08 14:01:5034 ScopedKeyValueConfig(ScopedKeyValueConfig* parent, absl::string_view s);
Jonas Orelanded99dae2022-03-09 08:28:1035 ScopedKeyValueConfig* GetRoot(ScopedKeyValueConfig* n);
Emil Lundmark1c8103d2022-09-21 13:20:2236 std::string GetValue(absl::string_view key) const override;
Jonas Orelanded99dae2022-03-09 08:28:1037 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
Danil Chapovalov385b6c52022-04-08 14:01:5045 // Unlike std::less<std::string>, std::less<> is transparent and allows
46 // heterogeneous lookup directly with absl::string_view.
47 std::map<std::string, std::string, std::less<>> key_value_map_;
Jonas Orelanded99dae2022-03-09 08:28:1048 std::unique_ptr<ScopedFieldTrials> scoped_field_trials_;
49};
50
51} // namespace test
52} // namespace webrtc
53
54#endif // TEST_SCOPED_KEY_VALUE_CONFIG_H_