Skip to content

Commit b202e02

Browse files
committed
boost::shared_ptr -> std::shared_ptr
1 parent 53bd1dc commit b202e02

File tree

5 files changed

+35
-36
lines changed

5 files changed

+35
-36
lines changed

postgres_asio/postgres_asio.cpp

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ static int64_t now() {
2121
}
2222

2323
namespace postgres_asio {
24-
inline static boost::shared_ptr<PGresult> make_shared(PGresult* p) { return boost::shared_ptr<PGresult>(p, PQclear); }
24+
inline static std::shared_ptr<PGresult> make_shared(PGresult* p) { return std::shared_ptr<PGresult>(p, PQclear); }
2525

2626
connection::connection(boost::asio::io_service& fg, boost::asio::io_service& bg, std::string trace_id) :
2727
_fg_ios(fg),
@@ -85,7 +85,7 @@ namespace postgres_asio {
8585
}
8686

8787
// connect syncrounous and run callcack from fg thread event loop
88-
void connection::_bg_connect(boost::shared_ptr<connection> self, std::string connect_string, on_connect_callback cb) {
88+
void connection::_bg_connect(std::shared_ptr<connection> self, std::string connect_string, on_connect_callback cb) {
8989
_start_ts = now();
9090
_pg_conn = PQconnectdb(connect_string.c_str());
9191
auto status = PQstatus(_pg_conn); //
@@ -119,18 +119,18 @@ namespace postgres_asio {
119119
}
120120

121121

122-
std::pair<int, boost::shared_ptr<PGresult>> connection::exec(std::string statement) {
123-
std::promise<std::pair<int, boost::shared_ptr<PGresult>>> p;
124-
std::future<std::pair<int, boost::shared_ptr<PGresult>>> f = p.get_future();
125-
exec(statement, [&p](int ec, boost::shared_ptr<PGresult> res) {
126-
std::pair<int, boost::shared_ptr<PGresult>> val(ec, res);
122+
std::pair<int, std::shared_ptr<PGresult>> connection::exec(std::string statement) {
123+
std::promise<std::pair<int, std::shared_ptr<PGresult>>> p;
124+
std::future<std::pair<int, std::shared_ptr<PGresult>>> f = p.get_future();
125+
exec(statement, [&p](int ec, std::shared_ptr<PGresult> res) {
126+
std::pair<int, std::shared_ptr<PGresult>> val(ec, res);
127127
p.set_value(val);
128128
});
129129
f.wait();
130130
return f.get();
131131
}
132132

133-
void connection::_fg_socket_rx_cb(const boost::system::error_code& ec, boost::shared_ptr<connection> self, on_query_callback cb) {
133+
void connection::_fg_socket_rx_cb(const boost::system::error_code& ec, std::shared_ptr<connection> self, on_query_callback cb) {
134134
BOOST_LOG_TRIVIAL(trace) << _trace_id << ", " << BOOST_CURRENT_FUNCTION;
135135
if(ec) {
136136
BOOST_LOG_TRIVIAL(warning) << _trace_id << ", postgres::exec asio ec:" << ec.message();
@@ -162,7 +162,6 @@ namespace postgres_asio {
162162
_results.push_back(r);
163163
}
164164

165-
166165
int32_t duration = (int32_t) (now() - _start_ts);
167166

168167
// if we got a NULL here then we are ready to issue another async exec....
@@ -173,7 +172,7 @@ namespace postgres_asio {
173172
return;
174173
}
175174

176-
boost::shared_ptr<PGresult> last_result = *_results.rbegin();
175+
std::shared_ptr<PGresult> last_result = *_results.rbegin();
177176
_results.clear();
178177

179178
int status = PQresultStatus(last_result.get());
@@ -210,9 +209,9 @@ namespace postgres_asio {
210209
//}
211210

212211
////TBD reuse connections.
213-
//boost::shared_ptr<postgres_asio::connection> connection_pool::create()
212+
//std::shared_ptr<postgres_asio::connection> connection_pool::create()
214213
//{
215-
// return boost::make_shared<postgres_asio::connection>(_fg_ios, _bg_ios);
214+
// return std::make_shared<postgres_asio::connection>(_fg_ios, _bg_ios);
216215
//}
217216
//
218217
//// TBD

postgres_asio/postgres_asio.h

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#pragma once
2+
#include <memory>
23
#include <utility>
34
#include <boost/asio.hpp>
45
#include <boost/function.hpp>
56
#include <boost/chrono/system_clocks.hpp>
6-
#include <boost/enable_shared_from_this.hpp>
77
#include <deque>
88

99
#ifdef WIN32
@@ -22,10 +22,10 @@
2222
//https://github.com/brianc/node-libpq
2323

2424
namespace postgres_asio {
25-
class connection : public boost::enable_shared_from_this<connection> {
25+
class connection : public std::enable_shared_from_this<connection> {
2626
public:
27-
typedef boost::function<void(int ec)> on_connect_callback;
28-
typedef boost::function<void(int ec, boost::shared_ptr<PGresult>)> on_query_callback;
27+
typedef boost::function<void(int ec)> on_connect_callback;
28+
typedef boost::function<void(int ec, std::shared_ptr<PGresult>)> on_query_callback;
2929

3030
connection(boost::asio::io_service& fg, boost::asio::io_service& bg, std::string trace_id = "");
3131
~connection();
@@ -67,22 +67,22 @@ namespace postgres_asio {
6767
//async exec
6868
void exec(std::string statement, on_query_callback cb);
6969
//sync exec
70-
std::pair<int, boost::shared_ptr<PGresult>> exec(std::string statement);
70+
std::pair<int, std::shared_ptr<PGresult>> exec(std::string statement);
7171
private:
7272
int socket() const;
7373

74-
void _bg_connect(boost::shared_ptr<connection> self, std::string connect_string, on_connect_callback cb);
75-
void _fg_socket_rx_cb(const boost::system::error_code& e, boost::shared_ptr<connection>, on_query_callback cb);
74+
void _bg_connect(std::shared_ptr<connection> self, std::string connect_string, on_connect_callback cb);
75+
void _fg_socket_rx_cb(const boost::system::error_code& e, std::shared_ptr<connection>, on_query_callback cb);
7676

77-
boost::asio::io_service& _fg_ios;
78-
boost::asio::io_service& _bg_ios;
79-
boost::asio::ip::tcp::socket _socket;
80-
PGconn* _pg_conn;
81-
std::string _trace_id;
82-
int64_t _start_ts;
83-
int32_t _warn_timeout;
84-
std::string _current_statement;
85-
std::deque<boost::shared_ptr<PGresult>> _results;
77+
boost::asio::io_service& _fg_ios;
78+
boost::asio::io_service& _bg_ios;
79+
boost::asio::ip::tcp::socket _socket;
80+
PGconn* _pg_conn;
81+
std::string _trace_id;
82+
int64_t _start_ts;
83+
int32_t _warn_timeout;
84+
std::string _current_statement;
85+
std::deque<std::shared_ptr<PGresult>> _results;
8686
};
8787

8888
/* class connection_pool

samples/cursor_sample/cursor_sample.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include <boost/log/expressions.hpp>
99

1010

11-
void handle_fetch1000(boost::shared_ptr<postgres_asio::connection> connection, size_t total_count, int ec, boost::shared_ptr<PGresult> res) {
11+
void handle_fetch1000(boost::shared_ptr<postgres_asio::connection> connection, size_t total_count, int ec, std::shared_ptr<PGresult> res) {
1212
if(ec)
1313
return;
1414

@@ -17,13 +17,13 @@ void handle_fetch1000(boost::shared_ptr<postgres_asio::connection> connection, s
1717
BOOST_LOG_TRIVIAL(info) << "got " << tuples_in_batch << ", total: " << total_count;
1818
if(tuples_in_batch == 0) {
1919
BOOST_LOG_TRIVIAL(info) << "calling async_exec CLOSE mycursor; COMMIT....";
20-
connection->exec("CLOSE mycursor; COMMIT", [connection](int ec, boost::shared_ptr<PGresult> res) {
20+
connection->exec("CLOSE mycursor; COMMIT", [connection](int ec, std::shared_ptr<PGresult> res) {
2121
BOOST_LOG_TRIVIAL(info) << "async processing done";
2222
});
2323
return;
2424
}
2525
BOOST_LOG_TRIVIAL(info) << "calling async_exec FETCH 1000 in mycursor....";
26-
connection->exec("FETCH 1000 in mycursor", [connection, total_count](int ec, boost::shared_ptr<PGresult> res) { handle_fetch1000(connection, total_count, ec, std::move(res)); });
26+
connection->exec("FETCH 1000 in mycursor", [connection, total_count](int ec, std::shared_ptr<PGresult> res) { handle_fetch1000(connection, total_count, ec, std::move(res)); });
2727
}
2828

2929
int main(int argc, char *argv[]) {
@@ -47,19 +47,19 @@ int main(int argc, char *argv[]) {
4747
connection->connect(connect_string, [connection](int ec) {
4848
if(!ec) {
4949
BOOST_LOG_TRIVIAL(info) << "calling async_exec BEGIN";
50-
connection->exec("BEGIN", [connection](int ec, boost::shared_ptr<PGresult> res) {
50+
connection->exec("BEGIN", [connection](int ec, std::shared_ptr<PGresult> res) {
5151
if(ec) {
5252
BOOST_LOG_TRIVIAL(error) << "BEGIN failed ec:" << ec << " last_error: " << connection->last_error();
5353
return;
5454
}
5555
BOOST_LOG_TRIVIAL(info) << "calling async_exec DECLARE mycursor....";
56-
connection->exec("DECLARE mycursor CURSOR FOR SELECT * from postgres_asio_sample", [connection](int ec, boost::shared_ptr<PGresult> res) {
56+
connection->exec("DECLARE mycursor CURSOR FOR SELECT * from postgres_asio_sample", [connection](int ec, std::shared_ptr<PGresult> res) {
5757
if(ec) {
5858
BOOST_LOG_TRIVIAL(error) << "DECLARE mycursor... failed ec:" << ec << " last_error: " << connection->last_error();
5959
return;
6060
}
6161
BOOST_LOG_TRIVIAL(info) << "calling async_exec FETCH 1000 in mycursor....";
62-
connection->exec("FETCH 1000 in mycursor", [connection](int ec, boost::shared_ptr<PGresult> res) { handle_fetch1000(connection, 0, ec, std::move(res)); });
62+
connection->exec("FETCH 1000 in mycursor", [connection](int ec, std::shared_ptr<PGresult> res) { handle_fetch1000(connection, 0, ec, std::move(res)); });
6363
});
6464
});
6565
}

samples/insert_sample/insert_sample.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ int main(int argc, char *argv[]) {
4242
}
4343

4444
BOOST_LOG_TRIVIAL(info) << "async_insert";
45-
connection->exec(statement, [connection](int ec, boost::shared_ptr<PGresult> res) {
45+
connection->exec(statement, [connection](int ec, std::shared_ptr<PGresult> res) {
4646
if(ec) {
4747
BOOST_LOG_TRIVIAL(error) << " insert failed ec:" << ec << " last_error:" << connection->last_error();
4848
return;

samples/query_sample/query_sample.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ int main(int argc, char *argv[]) {
2727
BOOST_LOG_TRIVIAL(info) << "connect_async ec : " << ec;
2828
if(!ec) {
2929
BOOST_LOG_TRIVIAL(info) << "calling select_async";
30-
connection->exec("select * from postgres_asio_sample;", [connection](int ec, boost::shared_ptr<PGresult> res) {
30+
connection->exec("select * from postgres_asio_sample;", [connection](int ec, std::shared_ptr<PGresult> res) {
3131
if(ec) {
3232
BOOST_LOG_TRIVIAL(error) << "select failed, ec: " << ec;
3333
return;

0 commit comments

Comments
 (0)