use C++11 type traits to reduce code size in integral->string conversion

This commit is contained in:
Dennis Luxen
2014-10-08 12:40:56 +02:00
parent 4e00ebcd74
commit 8dc85e7641
6 changed files with 29 additions and 35 deletions
+2 -3
View File
@@ -38,7 +38,7 @@ void Reply::SetSize(const unsigned size)
{
if ("Content-Length" == h.name)
{
h.value = UintToString(size);
h.value = IntegralToString(size);
}
}
}
@@ -87,8 +87,7 @@ Reply Reply::StockReply(Reply::status_type status)
const std::string status_string = reply.ToString(status);
reply.content.insert(reply.content.end(), status_string.begin(), status_string.end());
reply.headers.emplace_back("Access-Control-Allow-Origin", "*");
reply.headers.emplace_back("Content-Length",
UintToString(static_cast<unsigned>(reply.content.size())));
reply.headers.emplace_back("Content-Length", IntegralToString(reply.content.size()));
reply.headers.emplace_back("Content-Type", "text/html");
return reply;
}
+2 -3
View File
@@ -92,7 +92,7 @@ void RequestHandler::handle_request(const http::Request &req, http::Reply &reply
JSON::Object json_result;
json_result.values["status"] = 400;
std::string message = "Query string malformed close to position ";
message += UintToString(position);
message += IntegralToString(position);
json_result.values["status_message"] = message;
JSON::render(reply.content, json_result);
return;
@@ -113,8 +113,7 @@ void RequestHandler::handle_request(const http::Request &req, http::Reply &reply
}
// set headers
reply.headers.emplace_back("Content-Length",
UintToString(static_cast<unsigned>(reply.content.size())));
reply.headers.emplace_back("Content-Length", IntegralToString(reply.content.size()));
if ("gpx" == route_parameters.output_format)
{ // gpx file
reply.headers.emplace_back("Content-Type", "application/gpx+xml; charset=UTF-8");
+1 -4
View File
@@ -62,7 +62,7 @@ class Server
: thread_pool_size(thread_pool_size), acceptor(io_service),
new_connection(new http::Connection(io_service, request_handler)), request_handler()
{
const std::string port_string = IntToString(port);
const std::string port_string = IntegralToString(port);
boost::asio::ip::tcp::resolver resolver(io_service);
boost::asio::ip::tcp::resolver::query query(address, port_string);
@@ -77,9 +77,6 @@ class Server
boost::bind(&Server::HandleAccept, this, boost::asio::placeholders::error));
}
// Server() = delete;
// Server(const Server &) = delete;
void Run()
{
std::vector<std::shared_ptr<std::thread>> threads;