0.08.01
C++ Open Travel Request Parsing Library
Toggle main menu visibility
Loading...
Searching...
No Matches
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
11
#include <
opentrep/OPENTREP_Types.hpp
>
12
#include <
opentrep/OPENTREP_Abstract.hpp
>
13
#include <
opentrep/DBType.hpp
>
14
15
namespace
OPENTREP
{
16
20
typedef
std::list<std::string>
DBParamsNameList_T
;
21
22
26
struct
DBParams
:
public
OPENTREP_Abstract
{
27
public
:
28
// ///////////////////// Getters //////////////////////
32
const
DBType
&
getType
()
const
{
33
return
_dbtype;
34
}
35
39
const
std::string&
getUser
()
const
{
40
return
_user;
41
}
42
46
const
std::string&
getPassword
()
const
{
47
return
_passwd;
48
}
49
53
const
std::string&
getHost
()
const
{
54
return
_host;
55
}
56
60
const
std::string&
getPort
()
const
{
61
return
_port;
62
}
63
67
const
std::string&
getDBName
()
const
{
68
return
_dbname;
69
}
70
71
72
public
:
73
// /////////////////////// Setters ///////////////////////
77
void
setType
(
const
DBType
& iType) {
78
_dbtype = iType;
79
}
80
84
void
setUser
(
const
std::string& iUser) {
85
_user = iUser;
86
}
87
91
void
setPassword
(
const
std::string& iPasswd) {
92
_passwd = iPasswd;
93
}
94
98
void
setHost
(
const
std::string& iHost) {
99
_host = iHost;
100
}
101
105
void
setPort
(
const
std::string& iPort) {
106
_port = iPort;
107
}
108
112
void
setDBName
(
const
std::string& iDBName) {
113
_dbname = iDBName;
114
}
115
116
117
public
:
118
// ///////////////////// Busines methods ////////////////////
122
bool
checkSQLite
()
const
{
123
if
(_dbname.empty() ==
true
) {
124
return
false
;
125
}
126
return
true
;
127
}
128
132
bool
checkMySQL
()
const
{
133
if
(_user.empty() ==
true
|| _passwd.empty() ==
true
134
|| _host.empty() ==
true
|| _port.empty()
135
|| _dbname.empty() ==
true
) {
136
return
false
;
137
}
138
return
true
;
139
}
140
144
bool
checkPG
()
const
{
145
if
(_user.empty() ==
true
|| _passwd.empty() ==
true
146
|| _dbname.empty() ==
true
) {
147
return
false
;
148
}
149
return
true
;
150
}
151
152
public
:
153
// //////////////////// Display methods //////////////////////
159
void
toStream
(std::ostream& ioOut)
const
{
160
ioOut <<
toString
();
161
}
162
167
void
fromStream
(std::istream&) {
168
}
169
173
std::string
toShortString
()
const
{
174
std::ostringstream oStr;
175
oStr << _dbname <<
"."
<< _user <<
"@"
<< _host <<
":"
<< _port;
176
return
oStr.str();
177
}
178
182
std::string
toString
()
const
{
183
std::ostringstream oStr;
184
oStr << _dbname <<
"."
<< _user <<
"@"
<< _host <<
":"
<< _port;
185
return
oStr.str();
186
}
187
191
std::string
toMySQLConnectionString
()
const
{
192
std::ostringstream oStr;
193
oStr <<
"db="
<< _dbname <<
" user="
<< _user <<
" password="
<< _passwd
194
<<
" port="
<< _port <<
" host="
<< _host;
195
return
oStr.str();
196
}
197
201
std::string
toPGConnectionString
()
const
{
202
std::ostringstream oStr;
203
oStr <<
"dbname="
<< _dbname <<
" user="
<< _user
204
<<
" password="
<< _passwd;
205
if
(!_host.empty()) {
206
oStr <<
" host="
<< _host;
207
}
208
if
(!_port.empty()) {
209
oStr <<
" port="
<< _port;
210
}
211
return
oStr.str();
212
}
213
217
std::string
toSQLiteConnectionString
()
const
{
218
std::ostringstream oStr;
219
oStr <<
"db="
<< _dbname;
220
return
oStr.str();
221
}
222
223
224
public
:
225
// /////////////// Constructors and Destructors ///////////////////
229
DBParams
(
const
DBType
& iDBType,
230
const
std::string& iDBUser,
const
std::string& iDBPasswd,
231
const
std::string& iDBHost,
const
std::string& iDBPort,
232
const
std::string& iDBName)
233
: _dbtype (iDBType), _user (iDBUser), _passwd (iDBPasswd),
234
_host (iDBHost), _port (iDBPort), _dbname (iDBName) {
235
}
236
DBParams
(
const
DBType
& iDBType,
const
std::string& iDBName)
237
: _dbtype (iDBType), _dbname (iDBName) {
238
}
239
243
// DBParams();
247
// DBParams (const DBParams&);
248
252
virtual
~DBParams
() {}
253
254
255
private
:
256
// ///////////////////////// Attributes ////////////////////////
260
DBType
_dbtype;
261
265
std::string _user;
266
270
std::string _passwd;
271
275
std::string _host;
276
280
std::string _port;
281
285
std::string _dbname;
286
};
287
288
}
289
#endif
// __OPENTREP_DBPARAMS_HPP
DBType.hpp
OPENTREP_Abstract.hpp
OPENTREP_Types.hpp
OPENTREP
Definition
BasChronometer.cpp:10
OPENTREP::DBParamsNameList_T
std::list< std::string > DBParamsNameList_T
Definition
DBParams.hpp:20
OPENTREP::DBParams::getUser
const std::string & getUser() const
Definition
DBParams.hpp:39
OPENTREP::DBParams::getPort
const std::string & getPort() const
Definition
DBParams.hpp:60
OPENTREP::DBParams::~DBParams
virtual ~DBParams()
Definition
DBParams.hpp:252
OPENTREP::DBParams::getDBName
const std::string & getDBName() const
Definition
DBParams.hpp:67
OPENTREP::DBParams::setPassword
void setPassword(const std::string &iPasswd)
Definition
DBParams.hpp:91
OPENTREP::DBParams::DBParams
DBParams(const DBType &iDBType, const std::string &iDBUser, const std::string &iDBPasswd, const std::string &iDBHost, const std::string &iDBPort, const std::string &iDBName)
Definition
DBParams.hpp:229
OPENTREP::DBParams::checkSQLite
bool checkSQLite() const
Definition
DBParams.hpp:122
OPENTREP::DBParams::toShortString
std::string toShortString() const
Definition
DBParams.hpp:173
OPENTREP::DBParams::toStream
void toStream(std::ostream &ioOut) const
Definition
DBParams.hpp:159
OPENTREP::DBParams::fromStream
void fromStream(std::istream &)
Definition
DBParams.hpp:167
OPENTREP::DBParams::getType
const DBType & getType() const
Definition
DBParams.hpp:32
OPENTREP::DBParams::setUser
void setUser(const std::string &iUser)
Definition
DBParams.hpp:84
OPENTREP::DBParams::getPassword
const std::string & getPassword() const
Definition
DBParams.hpp:46
OPENTREP::DBParams::toString
std::string toString() const
Definition
DBParams.hpp:182
OPENTREP::DBParams::toMySQLConnectionString
std::string toMySQLConnectionString() const
Definition
DBParams.hpp:191
OPENTREP::DBParams::checkMySQL
bool checkMySQL() const
Definition
DBParams.hpp:132
OPENTREP::DBParams::setType
void setType(const DBType &iType)
Definition
DBParams.hpp:77
OPENTREP::DBParams::setDBName
void setDBName(const std::string &iDBName)
Definition
DBParams.hpp:112
OPENTREP::DBParams::toPGConnectionString
std::string toPGConnectionString() const
Definition
DBParams.hpp:201
OPENTREP::DBParams::toSQLiteConnectionString
std::string toSQLiteConnectionString() const
Definition
DBParams.hpp:217
OPENTREP::DBParams::setPort
void setPort(const std::string &iPort)
Definition
DBParams.hpp:105
OPENTREP::DBParams::checkPG
bool checkPG() const
Definition
DBParams.hpp:144
OPENTREP::DBParams::DBParams
DBParams(const DBType &iDBType, const std::string &iDBName)
Definition
DBParams.hpp:236
OPENTREP::DBParams::setHost
void setHost(const std::string &iHost)
Definition
DBParams.hpp:98
OPENTREP::DBParams::getHost
const std::string & getHost() const
Definition
DBParams.hpp:53
OPENTREP::DBType
Enumeration of database types.
Definition
DBType.hpp:17
OPENTREP::OPENTREP_Abstract::OPENTREP_Abstract
OPENTREP_Abstract()
Definition
OPENTREP_Abstract.hpp:43
Generated on
for OpenTREP by
1.17.0