MySQL 8.0.40
Source Code Documentation
config_reader.h
Go to the documentation of this file.
1/* Copyright (c) 2021, 2024, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is designed to work with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#ifndef CONFIG_READER_INCLUDED
25#define CONFIG_READER_INCLUDED
26
27#include <string>
28
29#define RAPIDJSON_HAS_STDSTRING 1
30
31#include "my_rapidjson_size_t.h"
32
33#include <rapidjson/document.h>
34
35namespace keyring_common {
36namespace config {
37
39 public:
40 /**
41 Constructor
42
43 Reads JSON from config file and stores it in memory.
44
45 @param [in] config_file_path Full path to configuration file
46 */
47 explicit Config_reader(const std::string config_file_path);
48
49 /**
50 Get an element value from JSON document.
51 Assumption: Type is compatible with Get() function and
52 type of element is matching with template argument.
53
54 @param [in] element_name Name of the element being searched
55 @param [out] element_value Value of the element
56
57 @returns status of search operation
58 @retval false Element found. Refer to element_value
59 @retval true Element missing.
60 */
61 template <typename T>
62 bool get_element(const std::string element_name, T &element_value) {
63 if (!valid_ || !data_.HasMember(element_name)) return true;
64 element_value = data_[element_name].Get<T>();
65 return false;
66 }
67
68 private:
69 /** Configuration file path */
70 std::string config_file_path_;
71 /** Configuration data in JSON */
72 rapidjson::Document data_;
73 /** Validity of configuration data */
74 bool valid_;
75};
76
77} // namespace config
78} // namespace keyring_common
79
80#endif // !CONFIG_READER_INCLUDED
Definition: config_reader.h:38
rapidjson::Document data_
Configuration data in JSON.
Definition: config_reader.h:72
Config_reader(const std::string config_file_path)
Constructor.
Definition: config_reader.cc:34
bool get_element(const std::string element_name, T &element_value)
Get an element value from JSON document.
Definition: config_reader.h:62
bool valid_
Validity of configuration data.
Definition: config_reader.h:74
std::string config_file_path_
Configuration file path.
Definition: config_reader.h:70
Define rapidjson::SizeType to be std::size_t.
Definition: keyring_encryption_service_definition.h:32