Skip to content

Commit

Permalink
Move function wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
d-frey committed Nov 17, 2023
1 parent 4b23573 commit 71a6d82
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 22 deletions.
8 changes: 4 additions & 4 deletions include/tao/pq/connection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ namespace tao::pq
};

public:
connection( const private_key /*unused*/, const std::string& connection_info, const std::function< poll::callback >& poll_cb );
connection( const private_key /*unused*/, const std::string& connection_info, std::function< poll::callback > poll_cb );

connection( const connection& ) = delete;
connection( connection&& ) = delete;
Expand All @@ -108,12 +108,12 @@ namespace tao::pq

~connection() = default;

[[nodiscard]] static auto create( const std::string& connection_info, const std::function< poll::callback >& poll_cb = poll::internal::default_poll ) -> std::shared_ptr< connection >;
[[nodiscard]] static auto create( const std::string& connection_info, std::function< poll::callback > poll_cb = poll::internal::default_poll ) -> std::shared_ptr< connection >;

[[nodiscard]] auto error_message() const -> std::string;

[[nodiscard]] auto poll_callback() const -> std::function< poll::callback >;
void set_poll_callback( const std::function< poll::callback >& poll_cb );
[[nodiscard]] auto poll_callback() const noexcept -> const std::function< poll::callback >&;
void set_poll_callback( std::function< poll::callback > poll_cb ) noexcept;
void reset_poll_callback();

[[nodiscard]] auto notification_handler() const -> std::function< void( const notification& ) >;
Expand Down
8 changes: 4 additions & 4 deletions include/tao/pq/connection_pool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ namespace tao::pq
};

public:
connection_pool( const private_key /*unused*/, const std::string_view connection_info, const std::function< poll::callback >& poll_cb );
connection_pool( const private_key /*unused*/, const std::string_view connection_info, std::function< poll::callback > poll_cb );

[[nodiscard]] static auto create( const std::string_view connection_info, const std::function< poll::callback >& poll_cb = poll::internal::default_poll ) -> std::shared_ptr< connection_pool >;
[[nodiscard]] static auto create( const std::string_view connection_info, std::function< poll::callback > poll_cb = poll::internal::default_poll ) -> std::shared_ptr< connection_pool >;

[[nodiscard]] auto timeout() const noexcept -> decltype( auto )
{
Expand All @@ -55,8 +55,8 @@ namespace tao::pq
void set_timeout( const std::chrono::milliseconds timeout ) noexcept;
void reset_timeout() noexcept;

[[nodiscard]] auto poll_callback() const -> std::function< poll::callback >;
void set_poll_callback( const std::function< poll::callback >& poll_cb );
[[nodiscard]] auto poll_callback() const noexcept -> const std::function< poll::callback >&;
void set_poll_callback( std::function< poll::callback > poll_cb ) noexcept;
void reset_poll_callback();

[[nodiscard]] auto connection() -> std::shared_ptr< connection >;
Expand Down
14 changes: 7 additions & 7 deletions src/lib/pq/connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,10 +378,10 @@ namespace tao::pq
}
}

connection::connection( const private_key /*unused*/, const std::string& connection_info, const std::function< poll::callback >& poll_cb )
connection::connection( const private_key /*unused*/, const std::string& connection_info, std::function< poll::callback > poll_cb )
: m_pgconn( PQconnectdb( connection_info.c_str() ), &PQfinish ),
m_current_transaction( nullptr ),
m_poll( poll_cb )
m_poll( std::move( poll_cb ) )
{
if( !is_open() ) {
// note that we can not access the sqlstate after PQconnectdb(),
Expand All @@ -394,24 +394,24 @@ namespace tao::pq
}
}

auto connection::create( const std::string& connection_info, const std::function< poll::callback >& poll_cb ) -> std::shared_ptr< connection >
auto connection::create( const std::string& connection_info, std::function< poll::callback > poll_cb ) -> std::shared_ptr< connection >
{
return std::make_shared< connection >( private_key(), connection_info, poll_cb );
return std::make_shared< connection >( private_key(), connection_info, std::move( poll_cb ) );
}

auto connection::error_message() const -> std::string
{
return PQerrorMessage( m_pgconn.get() );
}

auto connection::poll_callback() const -> std::function< poll::callback >
auto connection::poll_callback() const noexcept -> const std::function< poll::callback >&
{
return m_poll;
}

void connection::set_poll_callback( const std::function< poll::callback >& poll_cb )
void connection::set_poll_callback( std::function< poll::callback > poll_cb ) noexcept
{
m_poll = poll_cb;
m_poll = std::move( poll_cb );
}

void connection::reset_poll_callback()
Expand Down
14 changes: 7 additions & 7 deletions src/lib/pq/connection_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ namespace tao::pq
return std::make_unique< pq::connection >( pq::connection::private_key(), m_connection_info, m_poll );
}

connection_pool::connection_pool( const private_key /*unused*/, const std::string_view connection_info, const std::function< poll::callback >& poll_cb )
connection_pool::connection_pool( const private_key /*unused*/, const std::string_view connection_info, std::function< poll::callback > poll_cb )
: m_connection_info( connection_info ),
m_poll( poll_cb )
m_poll( std::move( poll_cb ) )
{}

auto connection_pool::create( const std::string_view connection_info, const std::function< poll::callback >& poll_cb ) -> std::shared_ptr< connection_pool >
auto connection_pool::create( const std::string_view connection_info, std::function< poll::callback > poll_cb ) -> std::shared_ptr< connection_pool >
{
return std::make_shared< connection_pool >( private_key(), connection_info, poll_cb );
return std::make_shared< connection_pool >( private_key(), connection_info, std::move( poll_cb ) );
}

void connection_pool::set_timeout( const std::chrono::milliseconds timeout ) noexcept
Expand All @@ -31,14 +31,14 @@ namespace tao::pq
m_timeout = std::nullopt;
}

auto connection_pool::poll_callback() const -> std::function< poll::callback >
auto connection_pool::poll_callback() const noexcept -> const std::function< poll::callback >&
{
return m_poll;
}

void connection_pool::set_poll_callback( const std::function< poll::callback >& poll_cb )
void connection_pool::set_poll_callback( std::function< poll::callback > poll_cb ) noexcept
{
m_poll = poll_cb;
m_poll = std::move( poll_cb );
}

void connection_pool::reset_poll_callback()
Expand Down

0 comments on commit 71a6d82

Please sign in to comment.