Skip to content

Commit 67d339e

Browse files
C++ client: string_t to string (#8063)
1 parent 659981e commit 67d339e

File tree

70 files changed

+815
-835
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+815
-835
lines changed

src/SignalR/clients/cpp/include/signalrclient/connection.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ namespace signalr
1919
class connection
2020
{
2121
public:
22-
typedef std::function<void __cdecl(const utility::string_t&)> message_received_handler;
22+
typedef std::function<void __cdecl(const std::string&)> message_received_handler;
2323

24-
SIGNALRCLIENT_API explicit connection(const utility::string_t& url, trace_level trace_level = trace_level::all, std::shared_ptr<log_writer> log_writer = nullptr);
24+
SIGNALRCLIENT_API explicit connection(const std::string& url, trace_level trace_level = trace_level::all, std::shared_ptr<log_writer> log_writer = nullptr);
2525

2626
SIGNALRCLIENT_API ~connection();
2727

@@ -31,7 +31,7 @@ namespace signalr
3131

3232
SIGNALRCLIENT_API pplx::task<void> __cdecl start();
3333

34-
SIGNALRCLIENT_API pplx::task<void> __cdecl send(const utility::string_t& data);
34+
SIGNALRCLIENT_API pplx::task<void> __cdecl send(const std::string& data);
3535

3636
SIGNALRCLIENT_API void __cdecl set_message_received(const message_received_handler& message_received_callback);
3737
SIGNALRCLIENT_API void __cdecl set_disconnected(const std::function<void __cdecl()>& disconnected_callback);
@@ -41,7 +41,7 @@ namespace signalr
4141
SIGNALRCLIENT_API pplx::task<void> __cdecl stop();
4242

4343
SIGNALRCLIENT_API connection_state __cdecl get_connection_state() const noexcept;
44-
SIGNALRCLIENT_API utility::string_t __cdecl get_connection_id() const;
44+
SIGNALRCLIENT_API std::string __cdecl get_connection_id() const;
4545

4646
private:
4747
// The recommended smart pointer to use when doing pImpl is the `std::unique_ptr`. However

src/SignalR/clients/cpp/include/signalrclient/hub_connection.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ namespace signalr
2222
public:
2323
typedef std::function<void __cdecl (const web::json::value&)> method_invoked_handler;
2424

25-
SIGNALRCLIENT_API explicit hub_connection(const utility::string_t& url, trace_level trace_level = trace_level::all,
25+
SIGNALRCLIENT_API explicit hub_connection(const std::string& url, trace_level trace_level = trace_level::all,
2626
std::shared_ptr<log_writer> log_writer = nullptr);
2727

2828
SIGNALRCLIENT_API ~hub_connection();
@@ -35,17 +35,17 @@ namespace signalr
3535
SIGNALRCLIENT_API pplx::task<void> __cdecl stop();
3636

3737
SIGNALRCLIENT_API connection_state __cdecl get_connection_state() const;
38-
SIGNALRCLIENT_API utility::string_t __cdecl get_connection_id() const;
38+
SIGNALRCLIENT_API std::string __cdecl get_connection_id() const;
3939

4040
SIGNALRCLIENT_API void __cdecl set_disconnected(const std::function<void __cdecl()>& disconnected_callback);
4141

4242
SIGNALRCLIENT_API void __cdecl set_client_config(const signalr_client_config& config);
4343

44-
SIGNALRCLIENT_API void __cdecl on(const utility::string_t& event_name, const method_invoked_handler& handler);
44+
SIGNALRCLIENT_API void __cdecl on(const std::string& event_name, const method_invoked_handler& handler);
4545

46-
SIGNALRCLIENT_API pplx::task<web::json::value> invoke(const utility::string_t& method_name, const web::json::value& arguments = web::json::value::array());
46+
SIGNALRCLIENT_API pplx::task<web::json::value> invoke(const std::string& method_name, const web::json::value& arguments = web::json::value::array());
4747

48-
SIGNALRCLIENT_API pplx::task<void> send(const utility::string_t& method_name, const web::json::value& arguments = web::json::value::array());
48+
SIGNALRCLIENT_API pplx::task<void> send(const std::string& method_name, const web::json::value& arguments = web::json::value::array());
4949

5050
private:
5151
std::shared_ptr<hub_connection_impl> m_pImpl;

src/SignalR/clients/cpp/include/signalrclient/hub_exception.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@
55

66
#include <stdexcept>
77
#include "signalr_exception.h"
8-
#include "cpprest/details/basic_types.h"
98

109
namespace signalr
1110
{
1211
class hub_exception : public signalr_exception
1312
{
1413
public:
15-
hub_exception(const utility::string_t &what)
14+
hub_exception(const std::string &what)
1615
: signalr_exception(what)
1716
{}
1817
};

src/SignalR/clients/cpp/include/signalrclient/log_writer.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@
33

44
#pragma once
55

6-
#include "cpprest/details/basic_types.h"
7-
86
namespace signalr
97
{
108
class log_writer
119
{
1210
public:
1311
// NOTE: the caller does not enforce thread safety of this call
14-
virtual void __cdecl write(const utility::string_t &entry) = 0;
12+
virtual void __cdecl write(const std::string &entry) = 0;
1513
};
16-
}
14+
}

src/SignalR/clients/cpp/include/signalrclient/signalr_exception.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,14 @@
44
#pragma once
55

66
#include <stdexcept>
7-
#include "cpprest/details/basic_types.h"
8-
#include "cpprest/asyncrt_utils.h"
97

108
namespace signalr
119
{
1210
class signalr_exception : public std::runtime_error
1311
{
1412
public:
15-
explicit signalr_exception(const utility::string_t &what)
16-
: runtime_error(utility::conversions::to_utf8string(what))
13+
explicit signalr_exception(const std::string &what)
14+
: runtime_error(what)
1715
{}
1816
};
1917
}

src/SignalR/clients/cpp/include/signalrclient/web_exception.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,14 @@
44
#pragma once
55

66
#include <stdexcept>
7-
#include "cpprest/details/basic_types.h"
8-
#include "cpprest/asyncrt_utils.h"
97

108
namespace signalr
119
{
1210
class web_exception : public std::runtime_error
1311
{
1412
public:
15-
web_exception(const utility::string_t &what, unsigned short status_code)
16-
: runtime_error(utility::conversions::to_utf8string(what)), m_status_code(status_code)
13+
web_exception(const std::string &what, unsigned short status_code)
14+
: runtime_error(what), m_status_code(status_code)
1715
{}
1816

1917
unsigned short status_code() const noexcept

src/SignalR/clients/cpp/samples/HubConnectionSample/HubConnectionSample.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,20 @@
1111
class logger : public signalr::log_writer
1212
{
1313
// Inherited via log_writer
14-
virtual void __cdecl write(const utility::string_t & entry) override
14+
virtual void __cdecl write(const std::string & entry) override
1515
{
1616
//std::cout << utility::conversions::to_utf8string(entry) << std::endl;
1717
}
1818
};
1919

20-
void send_message(signalr::hub_connection& connection, const utility::string_t& name, const utility::string_t& message)
20+
void send_message(signalr::hub_connection& connection, const std::string& name, const std::string& message)
2121
{
2222
web::json::value args{};
23-
args[0] = web::json::value::string(name);
24-
args[1] = web::json::value(message);
23+
args[0] = web::json::value::string(utility::conversions::to_string_t(name));
24+
args[1] = web::json::value(utility::conversions::to_string_t(message));
2525

2626
// if you get an internal compiler error uncomment the lambda below or install VS Update 4
27-
connection.invoke(U("Invoke"), args/*, [](const web::json::value&){}*/)
27+
connection.invoke("Invoke", args/*, [](const web::json::value&){}*/)
2828
.then([](pplx::task<web::json::value> invoke_task) // fire and forget but we need to observe exceptions
2929
{
3030
try
@@ -39,10 +39,10 @@ void send_message(signalr::hub_connection& connection, const utility::string_t&
3939
});
4040
}
4141

42-
void chat(const utility::string_t& name)
42+
void chat(const std::string& name)
4343
{
44-
signalr::hub_connection connection(U("http://localhost:5000/default"), signalr::trace_level::all, std::make_shared<logger>());
45-
connection.on(U("Send"), [](const web::json::value& m)
44+
signalr::hub_connection connection("http://localhost:5000/default", signalr::trace_level::all, std::make_shared<logger>());
45+
connection.on("Send", [](const web::json::value& m)
4646
{
4747
ucout << std::endl << m.at(0).as_string() << /*U(" wrote:") << m.at(1).as_string() <<*/ std::endl << U("Enter your message: ");
4848
});
@@ -53,10 +53,10 @@ void chat(const utility::string_t& name)
5353
ucout << U("Enter your message:");
5454
for (;;)
5555
{
56-
utility::string_t message;
57-
std::getline(ucin, message);
56+
std::string message;
57+
std::getline(std::cin, message);
5858

59-
if (message == U(":q"))
59+
if (message == ":q")
6060
{
6161
break;
6262
}
@@ -85,8 +85,8 @@ void chat(const utility::string_t& name)
8585
int main()
8686
{
8787
ucout << U("Enter your name: ");
88-
utility::string_t name;
89-
std::getline(ucin, name);
88+
std::string name;
89+
std::getline(std::cin, name);
9090

9191
chat(name);
9292

src/SignalR/clients/cpp/src/signalrclient/callback_manager.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace signalr
1818
}
1919

2020
// note: callback must not throw except for the `on_progress` callback which will never be invoked from the dtor
21-
utility::string_t callback_manager::register_callback(const std::function<void(const web::json::value&)>& callback)
21+
std::string callback_manager::register_callback(const std::function<void(const web::json::value&)>& callback)
2222
{
2323
auto callback_id = get_callback_id();
2424

@@ -33,7 +33,7 @@ namespace signalr
3333

3434

3535
// invokes a callback and stops tracking it if remove callback set to true
36-
bool callback_manager::invoke_callback(const utility::string_t& callback_id, const web::json::value& arguments, bool remove_callback)
36+
bool callback_manager::invoke_callback(const std::string& callback_id, const web::json::value& arguments, bool remove_callback)
3737
{
3838
std::function<void(const web::json::value& arguments)> callback;
3939

@@ -58,7 +58,7 @@ namespace signalr
5858
return true;
5959
}
6060

61-
bool callback_manager::remove_callback(const utility::string_t& callback_id)
61+
bool callback_manager::remove_callback(const std::string& callback_id)
6262
{
6363
{
6464
std::lock_guard<std::mutex> lock(m_map_lock);
@@ -81,10 +81,10 @@ namespace signalr
8181
}
8282
}
8383

84-
utility::string_t callback_manager::get_callback_id()
84+
std::string callback_manager::get_callback_id()
8585
{
8686
const auto callback_id = m_id++;
87-
utility::stringstream_t ss;
87+
std::stringstream ss;
8888
ss << callback_id;
8989
return ss.str();
9090
}

src/SignalR/clients/cpp/src/signalrclient/callback_manager.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,17 @@ namespace signalr
2020
callback_manager(const callback_manager&) = delete;
2121
callback_manager& operator=(const callback_manager&) = delete;
2222

23-
utility::string_t register_callback(const std::function<void(const web::json::value&)>& callback);
24-
bool invoke_callback(const utility::string_t& callback_id, const web::json::value& arguments, bool remove_callback);
25-
bool remove_callback(const utility::string_t& callback_id);
23+
std::string register_callback(const std::function<void(const web::json::value&)>& callback);
24+
bool invoke_callback(const std::string& callback_id, const web::json::value& arguments, bool remove_callback);
25+
bool remove_callback(const std::string& callback_id);
2626
void clear(const web::json::value& arguments);
2727

2828
private:
2929
std::atomic<int> m_id { 0 };
30-
std::unordered_map<utility::string_t, std::function<void(const web::json::value&)>> m_callbacks;
30+
std::unordered_map<std::string, std::function<void(const web::json::value&)>> m_callbacks;
3131
std::mutex m_map_lock;
3232
const web::json::value m_dtor_clear_arguments;
3333

34-
utility::string_t get_callback_id();
34+
std::string get_callback_id();
3535
};
3636
}

src/SignalR/clients/cpp/src/signalrclient/case_insensitive_comparison_utils.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ namespace signalr
1212
// Note: These functions are not pretending to be all-purpose helpers for case insensitive string comparison. Rather
1313
// we use them to compare hub and hub method names which are expected to be almost exclusively ASCII and this is the
1414
// simplest thing that would work without having to take dependencies on third party libraries.
15-
struct case_insensitive_equals : std::binary_function<utility::string_t, utility::string_t, bool>
15+
struct case_insensitive_equals : std::binary_function<std::string, std::string, bool>
1616
{
17-
bool operator()(const utility::string_t& s1, const utility::string_t& s2) const
17+
bool operator()(const std::string& s1, const std::string& s2) const
1818
{
1919
if (s1.length() != s2.length())
2020
{
@@ -33,9 +33,9 @@ namespace signalr
3333
}
3434
};
3535

36-
struct case_insensitive_hash : std::unary_function<utility::string_t, std::size_t>
36+
struct case_insensitive_hash : std::unary_function<std::string, std::size_t>
3737
{
38-
std::size_t operator()(const utility::string_t& s) const noexcept
38+
std::size_t operator()(const std::string& s) const noexcept
3939
{
4040
size_t hash = 0;
4141
std::hash<size_t> hasher;

src/SignalR/clients/cpp/src/signalrclient/connection.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
namespace signalr
1010
{
11-
connection::connection(const utility::string_t& url, trace_level trace_level, std::shared_ptr<log_writer> log_writer)
11+
connection::connection(const std::string& url, trace_level trace_level, std::shared_ptr<log_writer> log_writer)
1212
: m_pImpl(connection_impl::create(url, trace_level, std::move(log_writer)))
1313
{}
1414

@@ -21,7 +21,7 @@ namespace signalr
2121
return m_pImpl->start();
2222
}
2323

24-
pplx::task<void> connection::send(const utility::string_t& data)
24+
pplx::task<void> connection::send(const std::string& data)
2525
{
2626
return m_pImpl->send(data);
2727
}
@@ -51,7 +51,7 @@ namespace signalr
5151
return m_pImpl->get_connection_state();
5252
}
5353

54-
utility::string_t connection::get_connection_id() const
54+
std::string connection::get_connection_id() const
5555
{
5656
return m_pImpl->get_connection_id();
5757
}

0 commit comments

Comments
 (0)