Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit84e46e6

Browse files
committed
Initial value semantics support for request.
In this commit we implement some support for partial value semantics.This is important so that we can put the request objects into acontainer and compare two requests whether they are semantically equalvalue-wise.
1 parente7e7df6 commit84e46e6

File tree

5 files changed

+65
-3
lines changed

5 files changed

+65
-3
lines changed

‎boost/network/protocol/http/request/request.hpp‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,14 @@ namespace boost { namespace network { namespace http {
1818
structrequest_pimpl;
1919

2020
structrequest : request_base {
21-
// FIXME Implement all these!
22-
2321
// We support full value semantics.
2422
request();
2523
explicitrequest(std::stringconst & url);
2624
explicitrequest(uri::uriconst & url);
2725
request(requestconst &);
2826
request&operator=(request);
2927
voidswap(request & other);
28+
boolequals(requestconst &other)const;
3029

3130
// From message_base...
3231
// Mutators
@@ -82,6 +81,14 @@ inline void swap(request &l, request &r) {
8281
l.swap(r);
8382
}
8483

84+
inlinebooloperator==(requestconst &l, requestconst &r) {
85+
return l.equals(r);
86+
}
87+
88+
inlinebooloperator!=(requestconst &l, requestconst &r) {
89+
return !l.equals(r);
90+
}
91+
8592
}// namespace http
8693

8794
}// namespace network

‎boost/network/protocol/http/request/request.ipp‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ struct request_pimpl {
2727
, headers_()
2828
{}
2929

30-
request_pimpl*clone() {
30+
request_pimpl*clone()const{
3131
returnnew (std::nothrow)request_pimpl(*this);
3232
}
3333

@@ -94,6 +94,13 @@ struct request_pimpl {
9494
read_offset_ += bytes;
9595
}
9696

97+
boolequals(request_pimplconst &other)const {
98+
return uri_ == other.uri_ &&
99+
read_offset_ == other.read_offset_ &&
100+
source_ == other.source_ &&
101+
headers_ == other.headers_;
102+
}
103+
97104
private:
98105
typedef std::multimap<std::string, std::string> headers_type;
99106

@@ -130,6 +137,11 @@ request& request::operator=(request rhs) {
130137
rhs.swap(*this);
131138
}
132139

140+
boolrequest::equals(requestconst &other)const {
141+
return pimpl_->equals(*other.pimpl_) &&
142+
request_storage_base::equals(other);
143+
}
144+
133145
voidrequest::swap(request & other) {
134146
std::swap(this->pimpl_, other.pimpl_);
135147
}

‎boost/network/protocol/http/request/request_base.hpp‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ struct request_storage_base {
3131
virtualsize_tread(char *destination,size_t offset,size_t size)const;
3232
virtualvoidflatten(std::string &destination)const;
3333
virtualvoidclear();
34+
virtualboolequals(request_storage_baseconst &other)const;
3435
virtual~request_storage_base();
3536

3637
private:

‎boost/network/protocol/http/request/request_base.ipp‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ struct request_storage_base_pimpl {
2424
size_tread(char *destination,size_t offset,size_t size)const;
2525
voidflatten(std::string &destination)const;
2626
voidclear();
27+
boolequals(request_storage_base_pimplconst &other)const;
2728
~request_storage_base_pimpl();
2829

2930
private:
@@ -63,6 +64,10 @@ void request_storage_base::clear() {
6364
pimpl_->clear();
6465
}
6566

67+
boolrequest_storage_base::equals(request_storage_baseconst &other)const {
68+
return pimpl_->equals(*other.pimpl_);
69+
}
70+
6671
request_storage_base_pimpl::request_storage_base_pimpl(size_t chunk_size)
6772
: chunk_size_(chunk_size)
6873
, chunks_()
@@ -154,6 +159,19 @@ void request_storage_base_pimpl::clear() {
154159
chunks_vector().swap(chunks_);
155160
}
156161

162+
boolrequest_storage_base_pimpl::equals(request_storage_base_pimplconst &other)const {
163+
if (other.chunk_size_ != chunk_size_)returnfalse;
164+
if (other.chunks_.size() != chunks_.size())returnfalse;
165+
chunks_vector::const_iterator chunk_iterator = chunks_.begin();
166+
chunks_vector::const_iterator other_iterator = other.chunks_.begin();
167+
for (; chunk_iterator != chunks_.begin() && other_iterator != other.chunks_.end();
168+
++chunk_iterator, ++other_iterator) {
169+
if (chunk_iterator->second != other_iterator->second)returnfalse;
170+
if (strncmp(chunk_iterator->first, other_iterator->first, chunk_iterator->second))returnfalse;
171+
}
172+
returntrue;
173+
}
174+
157175
request_storage_base_pimpl::~request_storage_base_pimpl() {
158176
clear();
159177
}

‎libs/network/test/http/request_test.cpp‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,30 @@ BOOST_AUTO_TEST_CASE(request_construction) {
1818
http::requestother(request);
1919
}
2020

21+
BOOST_AUTO_TEST_CASE(request_value_semantics) {
22+
// First let's default construct a request.
23+
http::request original;
24+
// Next let's copy the request.
25+
http::requestcopy(original);
26+
// Next let's compare the requests.
27+
BOOST_CHECK(original == copy);
28+
// Next let's assign the original to another request.
29+
http::request assigned;
30+
assigned = original;
31+
// Next we modify the assigned object and make sure it's not the same as the
32+
// original.
33+
assigned.set_uri("http://www.google.com/");
34+
std::string original_uri, assigned_uri;
35+
original.get_uri(original_uri);
36+
assigned.get_uri(assigned_uri);
37+
BOOST_CHECK_NE(original_uri, assigned_uri);
38+
BOOST_CHECK(original != assigned);
39+
// Next we swap the assigned and copy.
40+
std::swap(assigned, copy);
41+
BOOST_CHECK(copy != assigned);
42+
BOOST_CHECK(assigned == original);
43+
}
44+
2145
BOOST_AUTO_TEST_CASE(request_uri_test) {
2246
http::request request;
2347
request.set_uri("http://www.google.com/");

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp