31#ifndef MYSQLX_DEVAPI_SETTINGS_H
32#define MYSQLX_DEVAPI_SETTINGS_H
40#include "detail/settings.h"
64#define SESS_OPT_ENUM_any(X,N) X = N,
65#define SESS_OPT_ENUM_bool(X,N) X = N,
66#define SESS_OPT_ENUM_num(X,N) X = N,
67#define SESS_OPT_ENUM_str(X,N) X = N,
68#define SESS_OPT_ENUM_bool(X,N) X = N,
75 SESSION_OPTION_LIST(SESS_OPT_ENUM)
88 return m_opt == other.m_opt;
91 bool operator==(Enum opt)
const
96 bool operator!=(Enum opt)
const
119#define CLIENT_OPT_ENUM_any(X,N) X = -N,
120#define CLIENT_OPT_ENUM_bool(X,N) X = -N,
121#define CLIENT_OPT_ENUM_num(X,N) X = -N,
122#define CLIENT_OPT_ENUM_str(X,N) X = -N,
127 using SessionEnum = SessionOption::Enum;
132 CLIENT_OPTION_LIST(CLIENT_OPT_ENUM)
147 ClientOption(SessionEnum opt)
151 bool operator==(
Enum opt)
const
156 bool operator==(SessionEnum opt)
const
158 return SessionOption::operator==(opt);
161 bool operator!=(
Enum opt)
const
166 bool operator!=(SessionEnum opt)
const
168 return SessionOption::operator!=(opt);
171 inline operator int()
173 return SessionOption::operator int();
183std::string OptionName(ClientOption opt)
185#define CLT_OPT_NAME_any(X,N) case ClientOption::X: return #X;
186#define CLT_OPT_NAME_bool(X,N) CLT_OPT_NAME_any(X,N)
187#define CLT_OPT_NAME_num(X,N) CLT_OPT_NAME_any(X,N)
188#define CLT_OPT_NAME_str(X,N) CLT_OPT_NAME_any(X,N)
190#define SESS_OPT_NAME_any(X,N) case SessionOption::X: return #X;
191#define SESS_OPT_NAME_bool(X,N) SESS_OPT_NAME_any(X,N)
192#define SESS_OPT_NAME_num(X,N) SESS_OPT_NAME_any(X,N)
193#define SESS_OPT_NAME_str(X,N) SESS_OPT_NAME_any(X,N)
194#define SESS_OPT_NAME_bool(X,N) SESS_OPT_NAME_any(X,N)
199 CLIENT_OPTION_LIST(CLT_OPT_NAME)
200 SESSION_OPTION_LIST(SESS_OPT_NAME)
203 throw_error(
"Unexpected Option");
return "";
210inline std::string ClientOptionName(ClientOption opt)
212 return OptionName(opt);
215inline std::string SessionOptionName(SessionOption opt)
217 return OptionName(opt);
228#define SSL_ENUM(X,N) X = N,
230 SSL_MODE_LIST(SSL_ENUM)
237std::string SSLModeName(SSLMode m)
239#define MODE_NAME(X,N) case SSLMode::X: return #X;
243 SSL_MODE_LIST(MODE_NAME)
246 std::ostringstream buf;
247 buf <<
"<UKNOWN (" << unsigned(m) <<
")>" << std::ends;
263#define AUTH_ENUM(X,N) X=N,
265 AUTH_METHOD_LIST(AUTH_ENUM)
272std::string AuthMethodName(AuthMethod m)
274#define AUTH_NAME(X,N) case AuthMethod::X: return #X;
278 AUTH_METHOD_LIST(AUTH_NAME)
281 std::ostringstream buf;
282 buf <<
"<UKNOWN (" << unsigned(m) <<
")>" << std::ends;
295enum_class CompressionMode
297#define COMPRESSION_ENUM(X,N) X = N,
299 COMPRESSION_MODE_LIST(COMPRESSION_ENUM)
305std::string CompressionModeName(CompressionMode m)
307#define COMPRESSION_NAME(X,N) case CompressionMode::X: return #X;
311 COMPRESSION_MODE_LIST(COMPRESSION_NAME)
314 std::ostringstream buf;
315 buf <<
"<UKNOWN (" << unsigned(m) <<
")>" << std::ends;
332struct Settings_traits
336 using SSLMode = mysqlx::SSLMode;
337 using AuthMethod = mysqlx::AuthMethod;
338 using CompressionMode = mysqlx::CompressionMode;
340 static std::string get_mode_name(SSLMode mode)
342 return SSLModeName(mode);
345 static std::string get_option_name(COptions opt)
347 return ClientOptionName(opt);
350 static std::string get_auth_name(AuthMethod m)
352 return AuthMethodName(m);
360internal::Settings_detail<internal::Settings_traits>::
361do_set(session_opt_list_t &&opts);
364template<
typename Option,
typename base_iterator>
368 std::pair<Option, mysqlx::Value> m_pair;
371 using iterator_category = std::input_iterator_tag;
372 using value_type = std::pair<Option, mysqlx::Value>;
374 iterator(
const base_iterator &init) : m_it(init) {}
376 iterator(
const iterator &init) : m_it(init.m_it) {}
378 std::pair<Option, mysqlx::Value> &operator*() {
380 m_pair.first =
static_cast<typename Option::Enum
>(el.first);
381 m_pair.second = el.second;
385 std::pair<ClientOption, mysqlx::Value>* operator->()
390 iterator& operator++()
396 iterator& operator--()
402 bool operator !=(
const iterator &other)
404 return m_it != other.m_it;
452 :
private internal::Settings_detail<internal::Settings_traits>
525 Settings_detail::set_from_uri(uri);
539 const std::string &host,
unsigned port,
541 const char *pwd = NULL,
542 const string &db =
string()
546 SessionOption::HOST, host,
547 SessionOption::PORT, port,
548 SessionOption::USER, user
552 set(SessionOption::PWD, std::string(pwd));
555 set(SessionOption::DB, db);
559 const std::string &host,
unsigned port,
561 const std::string &pwd,
562 const string &db =
string()
575 const std::string &host,
577 const char *pwd = NULL,
578 const string &db =
string()
584 const std::string &host,
586 const std::string &pwd,
587 const string &db =
string()
602 const char *pwd = NULL,
603 const string &db =
string()
611 const std::string &pwd,
612 const string &db =
string()
630 typename std::enable_if<
631 std::is_constructible<
SessionSettings, HOST, PORT, USER,
const char*, T...>::value
634 SessionSettings(HOST h, PORT p, USER u,
long, T... args)
635 : SessionSettings(h, p, u, nullptr, args...)
643 typename std::enable_if<
644 std::is_constructible<SessionSettings, PORT, USER,
const char*, T...>::value
647 SessionSettings(PORT p, USER u,
long, T... args)
648 : SessionSettings(p, u, nullptr, args...)
671 template <
typename... R>
672 SessionSettings(SessionOption::Enum opt, R&&...rest)
676 Settings_detail::set<true>(opt, std::forward<R>(rest)...);
684 using iterator = internal::iterator<SessionOption, Settings_detail::iterator>;
689 return Settings_detail::begin();
701 return Settings_detail::end();
716 Value
find(SessionOption opt)
719 return Settings_detail::get(opt);
739 template<
typename... R>
740 void set(SessionOption opt, R&&... rest)
744 Settings_detail::set<true>(opt, std::forward<R>(rest)...);
756 Settings_detail::clear();
768 void erase(SessionOption opt)
771 Settings_detail::erase(
static_cast<int>(opt));
784 return Settings_detail::has_option(opt);
807 :
private internal::Settings_detail<internal::Settings_traits>
812 using Base = internal::Settings_detail<internal::Settings_traits>;
819 using iterator = internal::iterator<ClientOption, Settings_detail::iterator>;
824 return Settings_detail::begin();
836 return Settings_detail::end();
850 Settings_detail::set_from_uri(uri);
864 Settings_detail::set_from_uri(uri);
865 Settings_detail::set_client_opts(opts);
906 Settings_detail::set_from_uri(uri);
907 std::stringstream str_opts;
909 Settings_detail::set_client_opts(str_opts.str());
950 Settings_detail::set_from_uri(uri);
951 Settings_detail::set_client_opts(options);
980 template<
typename...R>
986 Settings_detail::set<false>(opt, std::forward<R>(rest)...);
991 template <
typename... R>
996 Settings_detail::set<false>(opt, std::forward<R>(rest)...);
1011 return Settings_detail::get(opt);
1032 template<
typename OPT,
typename... R>
1033 void set(OPT opt, R&&... rest)
1037 Settings_detail::set<false>(opt, std::forward<R>(rest)...);
1050 Settings_detail::clear();
1062 Settings_detail::erase(
static_cast<int>(opt));
1075 return Settings_detail::has_option(opt);
1087 return Settings_detail::has_option(opt);
Client creation options.
Definition: settings.h:117
void set(OPT opt, R &&... rest)
Set client and session options.
Definition: settings.h:1030
bool has_option(ClientOption::Enum opt)
Check if option opt was defined.
Definition: settings.h:1069
void erase(mysqlx::ClientOption opt)
Remove the given option opt.
Definition: settings.h:1056
Value find(mysqlx::ClientOption opt)
Find the specified option opt and returns its Value.
Definition: settings.h:1005
ClientSettings(const string &uri)
Create client settings from a connection string.
Definition: settings.h:844
void clear()
Clear all settings specified so far.
Definition: settings.h:1044
Session creation options.
Definition: settings.h:63
Enum
Possible session creation options.
Definition: settings.h:74
bool has_option(SessionOption opt)
Check if option opt was defined.
Definition: settings.h:778
Value find(SessionOption opt)
Find the specified option opt and returns its Value.
Definition: settings.h:713
SessionSettings(const string &uri)
Create session settings from a connection string.
Definition: settings.h:519
void erase(SessionOption opt)
Remove all settings for the given option opt.
Definition: settings.h:765
void set(SessionOption opt, R &&... rest)
Set session options.
Definition: settings.h:737
void clear()
Clear all settings specified so far.
Definition: settings.h:750
Value object can store value of scalar type, string, array or document.
Definition: document.h:230
SSLMode
Modes to be used with SSL_MODE option .
Definition: settings.h:227