]> git.proxmox.com Git - ceph.git/blame - ceph/src/rocksdb/options/configurable_test.h
import quincy beta 17.1.0
[ceph.git] / ceph / src / rocksdb / options / configurable_test.h
CommitLineData
20effc67
TL
1// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
2// This source code is licensed under both the GPLv2 (found in the
3// COPYING file in the root directory) and Apache 2.0 License
4// (found in the LICENSE.Apache file in the root directory).
5//
6// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
7// Use of this source code is governed by a BSD-style license that can be
8// found in the LICENSE file. See the AUTHORS file for names of contributors.
9
10#pragma once
11#include <algorithm>
12#include <memory>
13#include <unordered_map>
14
15#include "options/configurable_helper.h"
16#include "rocksdb/configurable.h"
17#include "rocksdb/utilities/options_type.h"
18
19namespace ROCKSDB_NAMESPACE {
20struct ColumnFamilyOptions;
21struct DBOptions;
22
23namespace test {
24enum TestEnum { kTestA, kTestB };
25
26static const std::unordered_map<std::string, int> test_enum_map = {
27 {"A", TestEnum::kTestA},
28 {"B", TestEnum::kTestB},
29};
30
31struct TestOptions {
32 int i = 0;
33 bool b = false;
34 bool d = true;
35 TestEnum e = TestEnum::kTestA;
36 std::string s = "";
37 std::string u = "";
38};
39
40static std::unordered_map<std::string, OptionTypeInfo> simple_option_info = {
41#ifndef ROCKSDB_LITE
42 {"int",
43 {offsetof(struct TestOptions, i), OptionType::kInt,
44 OptionVerificationType::kNormal, OptionTypeFlags::kMutable}},
45 {"bool",
46 {offsetof(struct TestOptions, b), OptionType::kBoolean,
47 OptionVerificationType::kNormal, OptionTypeFlags::kNone}},
48 {"string",
49 {offsetof(struct TestOptions, s), OptionType::kString,
50 OptionVerificationType::kNormal, OptionTypeFlags::kNone}},
51#endif // ROCKSDB_LITE
52};
53
54static std::unordered_map<std::string, OptionTypeInfo> enum_option_info = {
55#ifndef ROCKSDB_LITE
56 {"enum",
57 OptionTypeInfo::Enum(offsetof(struct TestOptions, e), &test_enum_map)}
58#endif
59};
60
61static std::unordered_map<std::string, OptionTypeInfo> unique_option_info = {
62#ifndef ROCKSDB_LITE
63 {"unique",
64 {0, OptionType::kConfigurable, OptionVerificationType::kNormal,
65 (OptionTypeFlags::kUnique | OptionTypeFlags::kMutable)}},
66#endif // ROCKSDB_LITE
67};
68
69static std::unordered_map<std::string, OptionTypeInfo> shared_option_info = {
70#ifndef ROCKSDB_LITE
71 {"shared",
72 {0, OptionType::kConfigurable, OptionVerificationType::kNormal,
73 (OptionTypeFlags::kShared)}},
74#endif // ROCKSDB_LITE
75};
76static std::unordered_map<std::string, OptionTypeInfo> pointer_option_info = {
77#ifndef ROCKSDB_LITE
78 {"pointer",
79 {0, OptionType::kConfigurable, OptionVerificationType::kNormal,
80 OptionTypeFlags::kRawPointer}},
81#endif // ROCKSDB_LITE
82};
83
84enum TestConfigMode {
85 kEmptyMode = 0x0, // Don't register anything
86 kMutableMode = 0x01, // Configuration is mutable
87 kSimpleMode = 0x02, // Use the simple options
88 kEnumMode = 0x04, // Use the enum options
89 kDefaultMode = kSimpleMode, // Use no inner nested configurations
90 kSharedMode = 0x10, // Use shared configuration
91 kUniqueMode = 0x20, // Use unique configuration
92 kRawPtrMode = 0x40, // Use pointer configuration
93 kNestedMode = (kSharedMode | kUniqueMode | kRawPtrMode),
94 kAllOptMode = (kNestedMode | kEnumMode | kSimpleMode),
95};
96
97template <typename T>
98class TestConfigurable : public Configurable {
99 protected:
100 std::string name_;
101 std::string prefix_;
102 TestOptions options_;
103
104 public:
105 std::unique_ptr<T> unique_;
106 std::shared_ptr<T> shared_;
107 T* pointer_;
108
109 TestConfigurable(const std::string& name, int mode,
110 const std::unordered_map<std::string, OptionTypeInfo>* map =
111 &simple_option_info)
112 : name_(name), pointer_(nullptr) {
113 prefix_ = "test." + name + ".";
114 if ((mode & TestConfigMode::kSimpleMode) != 0) {
115 ConfigurableHelper::RegisterOptions(*this, name_, &options_, map);
116 }
117 if ((mode & TestConfigMode::kEnumMode) != 0) {
118 ConfigurableHelper::RegisterOptions(*this, name_ + "Enum", &options_,
119 &enum_option_info);
120 }
121 }
122
123 ~TestConfigurable() override { delete pointer_; }
124};
125
126} // namespace test
127} // namespace ROCKSDB_NAMESPACE