move casts from/to string into static class

This commit is contained in:
Dennis Luxen
2014-10-08 14:47:22 +02:00
parent ec8f977ebe
commit 57fab61789
9 changed files with 229 additions and 39 deletions
+3 -3
View File
@@ -27,7 +27,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <osrm/Reply.h>
#include "../../Util/StringUtil.h"
#include "../../Util/cast.hpp"
namespace http
{
@@ -38,7 +38,7 @@ void Reply::SetSize(const unsigned size)
{
if ("Content-Length" == h.name)
{
h.value = IntegralToString(size);
h.value = cast::integral_to_string(size);
}
}
}
@@ -87,7 +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", IntegralToString(reply.content.size()));
reply.headers.emplace_back("Content-Length", cast::integral_to_string(reply.content.size()));
reply.headers.emplace_back("Content-Type", "text/html");
return reply;
}
+3 -3
View File
@@ -88,11 +88,11 @@ void RequestHandler::handle_request(const http::Request &req, http::Reply &reply
{
reply = http::Reply::StockReply(http::Reply::badRequest);
reply.content.clear();
const unsigned position = static_cast<unsigned>(std::distance(request.begin(), iter));
const auto position = std::distance(request.begin(), iter);
JSON::Object json_result;
json_result.values["status"] = 400;
std::string message = "Query string malformed close to position ";
message += IntegralToString(position);
message += cast::integral_to_string(position);
json_result.values["status_message"] = message;
JSON::render(reply.content, json_result);
return;
@@ -113,7 +113,7 @@ void RequestHandler::handle_request(const http::Request &req, http::Reply &reply
}
// set headers
reply.headers.emplace_back("Content-Length", IntegralToString(reply.content.size()));
reply.headers.emplace_back("Content-Length", cast::integral_to_string(reply.content.size()));
if ("gpx" == route_parameters.output_format)
{ // gpx file
reply.headers.emplace_back("Content-Type", "application/gpx+xml; charset=UTF-8");
+6 -6
View File
@@ -31,9 +31,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "Connection.h"
#include "RequestHandler.h"
#include "../Util/cast.hpp"
#include "../Util/make_unique.hpp"
#include "../Util/SimpleLogger.h"
#include "../Util/StringUtil.h"
#include <boost/asio.hpp>
#include <boost/bind.hpp>
@@ -60,9 +60,9 @@ class Server
explicit Server(const std::string &address, const int port, const unsigned thread_pool_size)
: thread_pool_size(thread_pool_size), acceptor(io_service),
new_connection(new http::Connection(io_service, request_handler)), request_handler()
new_connection(std::make_shared<http::Connection>(io_service, request_handler)), request_handler()
{
const std::string port_string = IntegralToString(port);
const std::string port_string = cast::integral_to_string(port);
boost::asio::ip::tcp::resolver resolver(io_service);
boost::asio::ip::tcp::resolver::query query(address, port_string);
@@ -86,9 +86,9 @@ class Server
boost::bind(&boost::asio::io_service::run, &io_service));
threads.push_back(thread);
}
for (unsigned i = 0; i < threads.size(); ++i)
for (auto thread : threads)
{
threads[i]->join();
thread->join();
}
}
@@ -102,7 +102,7 @@ class Server
if (!e)
{
new_connection->start();
new_connection.reset(new http::Connection(io_service, request_handler));
new_connection = std::make_shared<http::Connection>(io_service, request_handler);
acceptor.async_accept(
new_connection->socket(),
boost::bind(&Server::HandleAccept, this, boost::asio::placeholders::error));