MySQL 9.3.0
Source Code Documentation
variant_pointer.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2022, 2025, Oracle and/or its affiliates.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License, version 2.0,
6 as published by the Free Software Foundation.
7
8 This program is designed to work with certain software (including
9 but not limited to OpenSSL) that is licensed under separate terms,
10 as designated in a particular file or component or in included license
11 documentation. The authors of MySQL hereby grant you an additional
12 permission to link the program and your derivative works with the
13 separately licensed software that they have either included with
14 the program or referenced in the documentation.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24*/
25
26#ifndef ROUTER_SRC_REST_MRS_SRC_HELPER_VARIANT_H_
27#define ROUTER_SRC_REST_MRS_SRC_HELPER_VARIANT_H_
28
29#include <chrono>
30#include <string>
31
32namespace helper {
33
35 public:
38
39 public:
40 VariantPointer(std::string *output) : type_{kTypeString}, ostring_{output} {}
41 VariantPointer(int *output) : type_{kTypeInteger}, ointeger_{output} {}
43 : type_{kTypeInteger}, oseconds_{output} {}
44
45 void operator=(const std::string &v) { set(v); }
46 VariantPointer &operator*() { return *this; }
47
48 void set(const std::string &v) {
49 switch (type_) {
50 case kTypeNone:
51 break;
52 case kTypeString:
53 *ostring_ = v;
54 break;
55 case kTypeInteger:
56 *ointeger_ = atoi(v.c_str());
57 break;
58 case kTypeSeconds:
59 *oseconds_ = seconds(atoi(v.c_str()));
60 break;
61 }
62 }
63
64 template <typename Callback>
66 switch (type_) {
67 case kTypeNone:
68 cb();
69 break;
70 case kTypeString:
71 cb(*ostring_);
72 break;
73 case kTypeInteger:
74 cb(*ointeger_);
75 break;
76 case kTypeSeconds:
77 cb(*oseconds_);
78 break;
79 }
80 }
81
82 private:
84 union {
86 std::string *ostring_;
88 };
89};
90
91} // namespace helper
92
93#endif // ROUTER_SRC_REST_MRS_SRC_HELPER_VARIANT_H_
Class that stores callback function reference as well as the result of the callback function call (in...
Definition: keyring_service.cc:44
Definition: variant_pointer.h:34
int * ointeger_
Definition: variant_pointer.h:87
std::chrono::seconds seconds
Definition: variant_pointer.h:36
seconds * oseconds_
Definition: variant_pointer.h:85
Type type_
Definition: variant_pointer.h:83
VariantPointer(std::chrono::seconds *output)
Definition: variant_pointer.h:42
void operator=(const std::string &v)
Definition: variant_pointer.h:45
VariantPointer & operator*()
Definition: variant_pointer.h:46
void set(const std::string &v)
Definition: variant_pointer.h:48
void dispatch_value(Callback &cb)
Definition: variant_pointer.h:65
Type
Definition: variant_pointer.h:37
@ kTypeSeconds
Definition: variant_pointer.h:37
@ kTypeInteger
Definition: variant_pointer.h:37
@ kTypeNone
Definition: variant_pointer.h:37
@ kTypeString
Definition: variant_pointer.h:37
VariantPointer(int *output)
Definition: variant_pointer.h:41
VariantPointer(std::string *output)
Definition: variant_pointer.h:40
std::string * ostring_
Definition: variant_pointer.h:86
static bool cb(unsigned long long new_value)
Definition: option_usage.cc:45
Definition: cache.h:33
std::chrono::seconds seconds
Definition: authorize_manager.cc:69