blob: 0ecbddcfbf690b44285fd9d2c11405fede474618 [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
14#include <map>
15#include <memory>
16#include <string>
17
18#include "absl/strings/string_view.h"
Jonas Orelande62c2f22022-03-29 09:04:4819#include "api/field_trials_view.h"
Jonas Orelanded99dae2022-03-09 08:28:1020#include "test/field_trial.h"
21
22namespace webrtc {
23namespace test {
24
Jonas Orelande62c2f22022-03-29 09:04:4825class ScopedKeyValueConfig : public FieldTrialsView {
Jonas Orelanded99dae2022-03-09 08:28:1026 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_