Permalink
Browse files

using make_shared<>() instead of shared_ptr<>()

  • Loading branch information...
1 parent 33c9e2a commit ee0f4d1f0e38345ee490c46b0eca3bc154bfa15f @JunTaoLuo JunTaoLuo committed Jul 25, 2013
@@ -33,8 +33,8 @@ static void RunStreamingSample()
if (key == U("1") || key == U("2"))
{
- auto connection = shared_ptr<MicrosoftAspNetSignalRClientCpp::Connection>(new MicrosoftAspNetSignalRClientCpp::Connection(U("http://localhost:40476/raw-connection")));
-
+ auto connection = make_shared<MicrosoftAspNetSignalRClientCpp::Connection>(U("http://localhost:40476/raw-connection"));
+
connection->SetReceivedCallback([](string_t message)
{
wcout << message << endl;
@@ -192,7 +192,7 @@ void AsyncStreamReader::Abort()
// returns a task that reads the incoming stream and stored the messages into a buffer
pplx::task<unsigned int> AsyncStreamReader::AsyncReadIntoBuffer(streams::basic_istream<uint8_t> stream)
{
- auto inStringBuffer = shared_ptr<streams::container_buffer<string>>(new streams::container_buffer<string>());
+ auto inStringBuffer = make_shared<streams::container_buffer<string>>();
pplx::task_options readTaskOptions(mReadCts.get_token());
return stream.read(*(inStringBuffer.get()), 4096).then([inStringBuffer, this](size_t bytesRead)
{
@@ -202,7 +202,7 @@ pplx::task<void> Connection::Negotiate(shared_ptr<IClientTransport> transport)
// If we have a keep alive
if (response->mKeepAliveTimeout != 0)
{
- pKeepAliveData = shared_ptr<KeepAliveData>(new KeepAliveData(response->mKeepAliveTimeout));
+ pKeepAliveData = make_shared<KeepAliveData>(response->mKeepAliveTimeout);
}
return StartTransport();
@@ -39,15 +39,15 @@ task<http_response> DefaultHttpClient::Get(string_t uri, function<void(shared_pt
throw exception("ArgumentNullException: prepareRequest");
}
- auto cts = shared_ptr<cancellation_token_source>(new cancellation_token_source());
+ auto cts = make_shared<cancellation_token_source>();
auto requestMessage = http_request(methods::GET);
requestMessage.set_request_uri(uri);
- auto request = shared_ptr<HttpRequestWrapper>(new HttpRequestWrapper(requestMessage, [cts]()
+ auto request = make_shared<HttpRequestWrapper>(requestMessage, [cts]()
{
cts->cancel();
- }));
+ });
prepareRequest(request);
pplx::task_options readTaskOptions(cts->get_token());
@@ -78,16 +78,16 @@ task<http_response> DefaultHttpClient::Post(string_t uri, function<void(shared_p
{
throw exception("ArgumentNullException: prepareRequest");
}
- auto cts = shared_ptr<cancellation_token_source>(new cancellation_token_source());
+ auto cts = make_shared<cancellation_token_source>();
auto requestMessage = http_request(methods::POST);
requestMessage.set_request_uri(uri);
requestMessage.set_body(postData);
- auto request = shared_ptr<HttpRequestWrapper>(new HttpRequestWrapper(requestMessage, [cts]()
+ auto request = make_shared<HttpRequestWrapper>(requestMessage, [cts]()
{
cts->cancel();
- }));
+ });
prepareRequest(request);
pplx::task_options readTaskOptions(cts->get_token());
@@ -19,10 +19,10 @@ HttpBasedTransport::HttpBasedTransport(shared_ptr<IHttpClient> httpClient, strin
pHttpClient = httpClient;
mTransportName = transport;
- pAbortHandler = shared_ptr<TransportAbortHandler>(new TransportAbortHandler(httpClient, transport, [this]()
+ pAbortHandler = make_shared<TransportAbortHandler>(httpClient, transport, [this]()
{
OnAbort();
- }));
+ });
}
HttpBasedTransport::~HttpBasedTransport(void)
@@ -56,7 +56,7 @@ pplx::task<void> HttpBasedTransport::Start(shared_ptr<Connection> connection, st
throw exception("ArgumentNullException: connection");
}
- auto initializeHandler = shared_ptr<TransportInitializationHandler>(new TransportInitializationHandler(connection->GetTransportConnectTimeout(), disconnectToken));
+ auto initializeHandler = make_shared<TransportInitializationHandler>(connection->GetTransportConnectTimeout(), disconnectToken);
OnStart(connection, data, disconnectToken, initializeHandler);
@@ -89,7 +89,7 @@ pplx::task<void> HttpBasedTransport::Send(shared_ptr<Connection> connection, str
{
if (response.headers().content_length() != 0)
{
- auto inStringBuffer = shared_ptr<streams::container_buffer<string>>(new streams::container_buffer<string>());
+ auto inStringBuffer = make_shared<streams::container_buffer<string>>();
response.body().read_to_end(*(inStringBuffer.get())).then([connection, inStringBuffer](size_t bytesRead)
{
string &text = inStringBuffer->collection();
@@ -49,13 +49,13 @@ bool SseEvent::TryParse(string_t line, shared_ptr<SseEvent>* sseEvent)
if (StringHelper::BeginsWithIgnoreCase(line, string_t(U("data:"))))
{
string_t data = StringHelper::Trim(line.substr(string_t(U("data:")).length(), line.length() - string_t(U("data:")).length()));
- *sseEvent = shared_ptr<SseEvent>(new SseEvent(EventType::Data, data));
+ *sseEvent = make_shared<SseEvent>(EventType::Data, data);
return true;
}
else if (StringHelper::BeginsWithIgnoreCase(line, string_t(U("id:"))))
{
string_t data = StringHelper::Trim(line.substr(string_t(U("id:")).length(), line.length() - string_t(U("id:")).length()));
- *sseEvent = shared_ptr<SseEvent>(new SseEvent(EventType::Id, data));
+ *sseEvent = make_shared<SseEvent>(EventType::Id, data);
return true;
}
else return false;
@@ -60,7 +60,7 @@ task<shared_ptr<NegotiationResponse>> TransportHelper::GetNegotiationResponse(sh
throw exception("Invalid Operation Exception: Server negotiation failed.");
}
- return shared_ptr<NegotiationResponse>(new NegotiationResponse(raw));
+ return make_shared<NegotiationResponse>(raw);
});
}
@@ -17,8 +17,8 @@ SUITE(ChunkBufferTests)
TEST(ReturnsNullIfNoNewLineIfBuffer)
{
// Arrange
- auto pBuffer = shared_ptr<ChunkBuffer>(new ChunkBuffer());
- auto pData = shared_ptr<char>(new char[4096]);
+ auto pBuffer = make_shared<ChunkBuffer>();
+ auto pData = shared_ptr<char>(new char[4096]);
strcpy(pData.get(), "hello world");
// Act
@@ -31,7 +31,7 @@ SUITE(ChunkBufferTests)
TEST(ReturnsTextUpToNewLine)
{
// Arrange
- auto pBuffer = shared_ptr<ChunkBuffer>(new ChunkBuffer());
+ auto pBuffer = make_shared<ChunkBuffer>();
auto pData = shared_ptr<char>(new char[4096]);
strcpy(pData.get(), "hello world\noy");
@@ -45,7 +45,7 @@ SUITE(ChunkBufferTests)
TEST(CanReadMultipleLines)
{
// Arrange
- auto pBuffer = shared_ptr<ChunkBuffer>(new ChunkBuffer());
+ auto pBuffer = make_shared<ChunkBuffer>();
auto pData = shared_ptr<char>(new char[4096]);
strcpy(pData.get(), "hel\nlo world\noy");
@@ -61,7 +61,7 @@ SUITE(ChunkBufferTests)
TEST(WillCompleteNewLine)
{
// Arrange
- auto pBuffer = shared_ptr<ChunkBuffer>(new ChunkBuffer());
+ auto pBuffer = make_shared<ChunkBuffer>();
auto pData = shared_ptr<char>(new char[4096]);
strcpy(pData.get(), "hello");
pBuffer->Add(pData);
@@ -19,11 +19,11 @@ SUITE(EventSourceStreamReaderTests)
//Arrange
http_response response;
response.set_body("data:somedata\n\n");
- auto pEvent = shared_ptr<Concurrency::event>(new Concurrency::event());
+ auto pEvent = make_shared<Concurrency::event>();
pplx::task_completion_event<string_t> tce;
pplx::task<string_t> task = pplx::create_task(tce);
shared_ptr<Connection> pConnection;
- auto pEventSource = shared_ptr<EventSourceStreamReader>(new EventSourceStreamReader(pConnection, response.body()));
+ auto pEventSource = make_shared<EventSourceStreamReader>(pConnection, response.body());
//Act
pEventSource->SetOpenedCallback([pEvent]()
@@ -25,7 +25,7 @@ SUITE(TransportTests)
for (int i = 0; i < testScenarios; i ++)
{
- auto pConnection = shared_ptr<Connection>(new Connection(U("http://foo.com"), connectionQS[i]));
+ auto pConnection = make_shared<Connection>(U("http://foo.com"), connectionQS[i]);
pConnection->SetConnectionToken(U(""));
// Act
@@ -46,7 +46,7 @@ SUITE(TransportTests)
for (int i = 0; i < testScenarios; i ++)
{
- auto pConnection = shared_ptr<Connection>(new Connection(U("http://foo.com"), connectionQS[i]));
+ auto pConnection = make_shared<Connection>(U("http://foo.com"), connectionQS[i]);
pConnection->SetConnectionToken(U(""));
// Act
@@ -61,7 +61,7 @@ SUITE(TransportTests)
{
// Arrange
bool timedOut, disconnected, triggered = false;
- auto pConnection = shared_ptr<Connection>(new Connection(U("http://foo.com")));
+ auto pConnection = make_shared<Connection>(U("http://foo.com"));
// Act
TransportHelper::ProcessResponse(pConnection, U("{\"S\":1, \"M\":[]}"), &timedOut, &disconnected, [&triggered]()

0 comments on commit ee0f4d1

Please sign in to comment.