connection-parameters.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2013 Vadim Zeitlin
3 // Distributed under the Boost Software License, Version 1.0.
4 // (See accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
6 //
7 
8 #ifndef SOCI_CONNECTION_PARAMETERS_H_INCLUDED
9 #define SOCI_CONNECTION_PARAMETERS_H_INCLUDED
10 
11 #include "soci-config.h"
12 
13 #include <map>
14 #include <string>
15 
16 namespace soci
17 {
18 
19 class backend_factory;
20 
21 // Simple container for the information used when opening a session.
23 {
24 public:
26  connection_parameters(backend_factory const & factory, std::string const & connectString);
27  connection_parameters(std::string const & backendName, std::string const & connectString);
28  explicit connection_parameters(std::string const & fullConnectString);
29 
30  // Default copy ctor, assignment operator and dtor are all OK for us.
31 
32 
33  // Retrieve the backend and the connection strings specified in the ctor.
34  backend_factory const * get_factory() const { return factory_; }
35  std::string const & get_connect_string() const { return connectString_; }
36 
37  // Set the value of the given option, overwriting any previous value.
38  void set_option(const char * name, std::string const & value)
39  {
40  options_[name] = value;
41  }
42 
43  // Return true if the option with the given name was found and fill the
44  // provided parameter with its value.
45  bool get_option(const char * name, std::string & value) const
46  {
47  Options::const_iterator const it = options_.find(name);
48  if (it == options_.end())
49  return false;
50 
51  value = it->second;
52 
53  return true;
54  }
55 
56 private:
57  // The backend and connection string specified in our ctor.
59  std::string connectString_;
60 
61  // We store all the values as strings for simplicity.
62  typedef std::map<const char*, std::string> Options;
63  Options options_;
64 };
65 
66 } // namespace soci
67 
68 #endif // SOCI_CONNECTION_PARAMETERS_H_INCLUDED
void set_option(const char *name, std::string const &value)
std::string const & get_connect_string() const
#define SOCI_DECL
Definition: soci-config.h:31
std::string connectString
Definition: test-db2.cpp:21
backend_factory const * factory_
std::map< const char *, std::string > Options
backend_factory const * get_factory() const
bool get_option(const char *name, std::string &value) const


asr_lib_ism
Author(s): Hanselmann Fabian, Heller Florian, Heizmann Heinrich, Kübler Marcel, Mehlhaus Jonas, Meißner Pascal, Qattan Mohamad, Reckling Reno, Stroh Daniel
autogenerated on Wed Jan 8 2020 04:02:40