use std::tuple to return multiple return values, hope for copy elision. Also, removes two cases of parameter reassignment
This commit is contained in:
parent
fb3bc22c64
commit
9dfe6d1e85
@ -67,9 +67,8 @@ void Connection::handle_read(const boost::system::error_code &error, std::size_t
|
||||
// no error detected, let's parse the request
|
||||
CompressionType compression_type(noCompression);
|
||||
osrm::tribool result;
|
||||
std::tie(result, std::ignore) =
|
||||
RequestParser().Parse(request, incoming_data_buffer.data(),
|
||||
incoming_data_buffer.data() + bytes_transferred, compression_type);
|
||||
std::tie(result, compression_type) = RequestParser().Parse(
|
||||
request, incoming_data_buffer.data(), incoming_data_buffer.data() + bytes_transferred);
|
||||
|
||||
// the request has been parsed
|
||||
if (result == osrm::tribool::yes)
|
||||
|
@ -28,7 +28,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#ifndef CONNECTION_H
|
||||
#define CONNECTION_H
|
||||
|
||||
// #include "RequestParser.h"
|
||||
#include "Http/CompressionType.h"
|
||||
#include "Http/Reply.h"
|
||||
#include "Http/Request.h"
|
||||
@ -38,30 +37,21 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/version.hpp>
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
//workaround for incomplete std::shared_ptr compatibility in old boost versions
|
||||
// workaround for incomplete std::shared_ptr compatibility in old boost versions
|
||||
#if BOOST_VERSION < 105300 || defined BOOST_NO_CXX11_SMART_PTR
|
||||
|
||||
namespace boost {
|
||||
template<class T>
|
||||
const T* get_pointer(std::shared_ptr<T> const& p)
|
||||
namespace boost
|
||||
{
|
||||
return p.get();
|
||||
}
|
||||
template <class T> const T *get_pointer(std::shared_ptr<T> const &p) { return p.get(); }
|
||||
|
||||
template<class T>
|
||||
T* get_pointer(std::shared_ptr<T>& p)
|
||||
{
|
||||
return p.get();
|
||||
}
|
||||
template <class T> T *get_pointer(std::shared_ptr<T> &p) { return p.get(); }
|
||||
} // namespace boost
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
class RequestHandler;
|
||||
|
||||
namespace http
|
||||
|
@ -36,23 +36,22 @@ RequestParser::RequestParser() : state_(method_start), header({"", ""}) {}
|
||||
|
||||
void RequestParser::Reset() { state_ = method_start; }
|
||||
|
||||
std::tuple<osrm::tribool, char *>
|
||||
RequestParser::Parse(Request &req, char *begin, char *end, http::CompressionType &compression_type)
|
||||
std::tuple<osrm::tribool, CompressionType>
|
||||
RequestParser::Parse(Request &req, char *begin, char *end)
|
||||
{
|
||||
while (begin != end)
|
||||
{
|
||||
osrm::tribool result = consume(req, *begin++, compression_type);
|
||||
osrm::tribool result = consume(req, *begin++);
|
||||
if (result == osrm::tribool::yes || result == osrm::tribool::no)
|
||||
{
|
||||
return std::make_tuple(result, begin);
|
||||
return std::make_tuple(result, compression_type);
|
||||
}
|
||||
}
|
||||
osrm::tribool result = osrm::tribool::indeterminate;
|
||||
return std::make_tuple(result, begin);
|
||||
return std::make_tuple(result, compression_type);
|
||||
}
|
||||
|
||||
osrm::tribool
|
||||
RequestParser::consume(Request &req, char input, http::CompressionType &compression_type)
|
||||
osrm::tribool RequestParser::consume(Request &req, char input)
|
||||
{
|
||||
switch (state_)
|
||||
{
|
||||
|
@ -48,11 +48,10 @@ class RequestParser
|
||||
RequestParser();
|
||||
void Reset();
|
||||
|
||||
std::tuple<osrm::tribool, char *>
|
||||
Parse(Request &req, char *begin, char *end, CompressionType &compression_type);
|
||||
std::tuple<osrm::tribool, CompressionType> Parse(Request &req, char *begin, char *end);
|
||||
|
||||
private:
|
||||
osrm::tribool consume(Request &req, char input, CompressionType &compression_type);
|
||||
osrm::tribool consume(Request &req, char input);
|
||||
|
||||
inline bool isChar(int c);
|
||||
|
||||
@ -88,6 +87,7 @@ class RequestParser
|
||||
} state_;
|
||||
|
||||
Header header;
|
||||
CompressionType compression_type;
|
||||
};
|
||||
|
||||
} // namespace http
|
||||
|
Loading…
Reference in New Issue
Block a user