mirror of
https://github.com/KingDuckZ/dindexer.git
synced 2025-02-17 11:45:50 +00:00
Add move semantics.
This commit is contained in:
parent
6edfb08383
commit
f82659e370
2 changed files with 32 additions and 7 deletions
|
@ -32,6 +32,8 @@ namespace pq {
|
|||
class Connection {
|
||||
public:
|
||||
Connection ( std::string&& parUsername, std::string&& parPasswd, std::string&& parDatabase, std::string&& parAddress, uint16_t parPort );
|
||||
Connection ( Connection&& );
|
||||
Connection ( const Connection& ) = delete;
|
||||
~Connection ( void ) noexcept;
|
||||
|
||||
std::string error_message ( void ) const;
|
||||
|
@ -46,6 +48,9 @@ namespace pq {
|
|||
template <typename... Args>
|
||||
ResultSet query ( const std::string& parQuery, Args&&... parArgs );
|
||||
|
||||
Connection& operator= ( Connection&& );
|
||||
Connection& operator= ( const Connection& ) = delete;
|
||||
|
||||
private:
|
||||
struct LocalData;
|
||||
using PGParams = std::unique_ptr<::PGparam, void(*)(::PGparam*)>;
|
||||
|
@ -53,12 +58,12 @@ namespace pq {
|
|||
ResultSet query_params ( const std::string& parQuery, PGParams& parParams );
|
||||
PGParams make_params ( const std::string* parTypes, ... );
|
||||
|
||||
const std::string m_username;
|
||||
const std::string m_passwd;
|
||||
const std::string m_database;
|
||||
const std::string m_address;
|
||||
const uint16_t m_port;
|
||||
std::unique_ptr<LocalData> m_localData;
|
||||
std::string m_username;
|
||||
std::string m_passwd;
|
||||
std::string m_database;
|
||||
std::string m_address;
|
||||
uint16_t m_port;
|
||||
};
|
||||
|
||||
template <typename... Args>
|
||||
|
|
|
@ -78,20 +78,40 @@ namespace pq {
|
|||
};
|
||||
|
||||
Connection::Connection (std::string&& parUsername, std::string&& parPasswd, std::string&& parDatabase, std::string&& parAddress, uint16_t parPort) :
|
||||
m_localData(new LocalData),
|
||||
m_username(std::move(parUsername)),
|
||||
m_passwd(std::move(parPasswd)),
|
||||
m_database(std::move(parDatabase)),
|
||||
m_address(std::move(parAddress)),
|
||||
m_port(parPort),
|
||||
m_localData(new LocalData)
|
||||
m_port(parPort)
|
||||
{
|
||||
m_localData->connection = nullptr;
|
||||
}
|
||||
|
||||
Connection::Connection (Connection&& parOther) :
|
||||
m_localData(std::move(parOther.m_localData)),
|
||||
m_username(std::move(parOther.m_username)),
|
||||
m_passwd(std::move(parOther.m_passwd)),
|
||||
m_database(std::move(parOther.m_database)),
|
||||
m_address(std::move(parOther.m_address)),
|
||||
m_port(parOther.m_port)
|
||||
{
|
||||
}
|
||||
|
||||
Connection::~Connection() noexcept {
|
||||
disconnect();
|
||||
}
|
||||
|
||||
Connection& Connection::operator= (Connection&& parOther) {
|
||||
m_localData = std::move(parOther.m_localData);
|
||||
m_username = std::move(parOther.m_username);
|
||||
m_passwd = std::move(parOther.m_passwd);
|
||||
m_database = std::move(parOther.m_database);
|
||||
m_address = std::move(parOther.m_address);
|
||||
m_port = parOther.m_port;
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool Connection::is_connected() const noexcept {
|
||||
return m_localData->connection != nullptr;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue