OpenTREP Logo  0.6.0
C++ Open Travel Request Parsing Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
DBParams.hpp
Go to the documentation of this file.
1 #ifndef __OPENTREP_DBPARAMS_HPP
2 #define __OPENTREP_DBPARAMS_HPP
3 
4 // //////////////////////////////////////////////////////////////////////
5 // Import section
6 // //////////////////////////////////////////////////////////////////////
7 // STL
8 #include <sstream>
9 #include <string>
10 // OpenTrep
13 
14 namespace OPENTREP {
15 
19  typedef std::list<std::string> DBParamsNameList_T;
20 
21 
25  struct DBParams : public OPENTREP_Abstract {
26  public:
27  // ///////////////////// Getters //////////////////////
31  std::string getUser() const {
32  return _user;
33  }
34 
38  std::string getPassword() const {
39  return _passwd;
40  }
41 
45  std::string getHost() const {
46  return _host;
47  }
48 
52  std::string getPort() const {
53  return _port;
54  }
55 
59  std::string getDBName() const {
60  return _dbname;
61  }
62 
63 
64  public:
65  // /////////////////////// Setters ///////////////////////
69  void setUser (const std::string& iUser) {
70  _user = iUser;
71  }
72 
76  void setPassword (const std::string& iPasswd) {
77  _passwd = iPasswd;
78  }
79 
83  void setHost (const std::string& iHost) {
84  _host = iHost;
85  }
86 
90  void setPort (const std::string& iPort) {
91  _port = iPort;
92  }
93 
97  void setDBName (const std::string& iDBName) {
98  _dbname = iDBName;
99  }
100 
101 
102  public:
103  // ///////////////////// Busines methods ////////////////////
107  bool checkSQLite () const {
108  if (_dbname.empty() == true) {
109  return false;
110  }
111  return true;
112  }
113 
117  bool checkMySQL () const {
118  if (_user.empty() == true || _passwd.empty() == true
119  || _host.empty() == true || _port.empty()
120  || _dbname.empty() == true) {
121  return false;
122  }
123  return true;
124  }
125 
126  public:
127  // //////////////////// Display methods //////////////////////
133  void toStream (std::ostream& ioOut) const {
134  ioOut << toString();
135  }
136 
141  void fromStream (std::istream&) {
142  }
143 
147  std::string toShortString() const {
148  std::ostringstream oStr;
149  oStr << _dbname << "." << _user << "@" << _host << ":" << _port;
150  return oStr.str();
151  }
152 
156  std::string toString() const {
157  std::ostringstream oStr;
158  oStr << _dbname << "." << _user << "@" << _host << ":" << _port;
159  return oStr.str();
160  }
161 
165  std::string toMySQLConnectionString() const {
166  std::ostringstream oStr;
167  oStr << "db=" << _dbname << " user=" << _user << " password=" << _passwd
168  << " port=" << _port << " host=" << _host;
169  return oStr.str();
170  }
171 
175  std::string toSQLiteConnectionString() const {
176  std::ostringstream oStr;
177  oStr << "db=" << _dbname;
178  return oStr.str();
179  }
180 
181 
182  public:
183  // /////////////// Constructors and Destructors ///////////////////
187  DBParams (const std::string& iDBUser, const std::string& iDBPasswd,
188  const std::string& iDBHost, const std::string& iDBPort,
189  const std::string& iDBName)
190  : _user (iDBUser), _passwd (iDBPasswd), _host (iDBHost), _port (iDBPort),
191  _dbname (iDBName) {
192  }
193  DBParams (const std::string& iDBName) : _dbname (iDBName) {
194  }
195 
199  // DBParams();
203  // DBParams (const DBParams&);
204 
208  virtual ~DBParams() {}
209 
210 
211  private:
212  // ///////////////////////// Attributes ////////////////////////
216  std::string _user;
220  std::string _passwd;
224  std::string _host;
228  std::string _port;
232  std::string _dbname;
233  };
234 
235 }
236 #endif // __OPENTREP_DBPARAMS_HPP
void setHost(const std::string &iHost)
Definition: DBParams.hpp:83
void setUser(const std::string &iUser)
Definition: DBParams.hpp:69
std::string getPort() const
Definition: DBParams.hpp:52
virtual ~DBParams()
Definition: DBParams.hpp:208
std::string getDBName() const
Definition: DBParams.hpp:59
std::list< std::string > DBParamsNameList_T
Definition: DBParams.hpp:19
void fromStream(std::istream &)
Definition: DBParams.hpp:141
std::string getUser() const
Definition: DBParams.hpp:31
std::string toShortString() const
Definition: DBParams.hpp:147
std::string toString() const
Definition: DBParams.hpp:156
bool checkSQLite() const
Definition: DBParams.hpp:107
void setPort(const std::string &iPort)
Definition: DBParams.hpp:90
DBParams(const std::string &iDBUser, const std::string &iDBPasswd, const std::string &iDBHost, const std::string &iDBPort, const std::string &iDBName)
Definition: DBParams.hpp:187
Structure modelling a database parameters.
Definition: DBParams.hpp:25
std::string getHost() const
Definition: DBParams.hpp:45
DBParams(const std::string &iDBName)
Definition: DBParams.hpp:193
bool checkMySQL() const
Definition: DBParams.hpp:117
std::string toMySQLConnectionString() const
Definition: DBParams.hpp:165
std::string getPassword() const
Definition: DBParams.hpp:38
void setPassword(const std::string &iPasswd)
Definition: DBParams.hpp:76
void toStream(std::ostream &ioOut) const
Definition: DBParams.hpp:133
void setDBName(const std::string &iDBName)
Definition: DBParams.hpp:97
std::string toSQLiteConnectionString() const
Definition: DBParams.hpp:175