Skip to content

Commit 3d25ece

Browse files
committed
Refactored URI tests. Big changes ahead.
1 parent f347a5f commit 3d25ece

File tree

14 files changed

+781
-605
lines changed

14 files changed

+781
-605
lines changed

boost/network/uri/basic_uri.hpp

Lines changed: 181 additions & 168 deletions
Original file line numberDiff line numberDiff line change
@@ -2,186 +2,199 @@
22
#define BOOST_NETWORK_URL_BASIC_URL_
33

44
// Copyright 2009 Dean Michael Berris, Jeroen Habraken.
5+
// Copyright 2010 Glyn Matthews.
56
// Distributed under the Boost Software License, Version 1.0.
67
// (See accompanying file LICENSE_1_0.txt or copy at
78
// http://www.boost.org/LICENSE_1_0.txt)
89

9-
#include <boost/range.hpp>
1010

11-
#include <boost/network/tags.hpp>
1211
#include <boost/network/uri/basic_uri_fwd.hpp>
1312
#include <boost/network/uri/detail/parse_uri.hpp>
14-
#include <boost/network/uri/uri_concept.hpp>
1513

16-
namespace boost { namespace network { namespace uri {
1714

18-
template <class Tag>
19-
struct uri_base {
20-
typedef typename string<Tag>::type string_type;
21-
22-
uri_base(string_type const & uri = string_type())
23-
:
24-
raw_(uri),
25-
parts_(),
26-
valid_(parse_uri(raw_, parts_))
27-
{ }
28-
29-
uri_base(const uri_base & other)
30-
:
31-
raw_(other.raw_),
32-
parts_(other.parts_),
33-
valid_(other.valid_)
34-
{ }
35-
36-
uri_base & operator=(uri_base other) {
37-
other.swap(*this);
38-
return *this;
39-
}
40-
41-
uri_base & operator=(string_type const & uri) {
42-
return *this = uri_base(uri);
43-
}
44-
45-
void swap(uri_base & other) {
46-
using std::swap;
47-
48-
swap(other.raw_, raw_);
49-
swap(other.parts_, parts_);
50-
swap(other.valid_, valid_);
51-
}
52-
53-
string_type scheme() const {
54-
return parts_.scheme;
55-
}
56-
57-
string_type user_info() const {
58-
return parts_.user_info ? *parts_.user_info : string_type();
59-
}
60-
61-
string_type host() const {
62-
return parts_.host ? *parts_.host : string_type();
63-
}
64-
65-
uint16_t port() const {
66-
return parts_.port ? *parts_.port : 0;
67-
}
68-
69-
string_type path() const {
70-
return parts_.path;
71-
}
72-
73-
string_type query() const {
74-
return parts_.query ? *parts_.query : string_type();
75-
}
76-
77-
string_type fragment() const {
78-
return parts_.fragment ? *parts_.fragment : string_type();
79-
}
80-
81-
string_type raw() const {
82-
return raw_;
83-
}
84-
85-
bool valid() const {
86-
return valid_;
87-
}
88-
89-
bool operator==(uri_base const & other) const {
90-
return (raw_ == other.raw_) && (parts_ == other.parts_) && (valid_ == other.valid_);
91-
}
92-
93-
bool operator!=(uri_base const & other) const {
94-
return !(*this == other);
95-
}
96-
97-
protected:
98-
99-
string_type raw_;
100-
detail::uri_parts<Tag> parts_;
101-
bool valid_;
102-
};
103-
104-
template <class Tag>
105-
struct basic_uri : uri_base<Tag> {
106-
using uri_base<Tag>::operator=;
107-
using typename uri_base<Tag>::string_type;
108-
using uri_base<Tag>::operator==;
109-
using uri_base<Tag>::operator!=;
110-
basic_uri() : uri_base<Tag>() {}
111-
basic_uri(typename uri_base<Tag>::string_type const & uri) : uri_base<Tag>(uri) {}
112-
};
113-
114-
template <class Tag>
115-
inline
116-
void
117-
swap(basic_uri<Tag> & left, basic_uri<Tag> & right) {
118-
right.swap(left);
119-
}
120-
121-
template <class Tag>
122-
inline
123-
typename string<Tag>::type
124-
scheme(basic_uri<Tag> const & uri) {
125-
return uri.scheme();
126-
}
127-
128-
template <class Tag>
129-
inline
130-
typename string<Tag>::type
131-
user_info(basic_uri<Tag> const & uri) {
132-
return uri.user_info();
133-
}
134-
135-
template <class Tag>
136-
inline
137-
typename string<Tag>::type
138-
host(basic_uri<Tag> const & uri) {
139-
return uri.host();
140-
}
141-
142-
template <class Tag>
143-
inline
144-
uint16_t
145-
port(basic_uri<Tag> const & uri) {
146-
return uri.port();
147-
}
148-
149-
template <class Tag>
150-
inline
151-
typename string<Tag>::type
152-
path(basic_uri<Tag> const & uri) {
153-
return uri.path();
154-
}
155-
156-
template <class Tag>
157-
inline
158-
typename string<Tag>::type
159-
query(basic_uri<Tag> const & uri) {
160-
return uri.query();
161-
}
162-
163-
template <class Tag>
164-
inline
165-
typename string<Tag>::type
166-
fragment(basic_uri<Tag> const & uri) {
167-
return uri.fragment();
168-
}
169-
170-
template <class Tag>
171-
inline
172-
bool
173-
valid(basic_uri<Tag> const & uri) {
174-
return uri.valid();
175-
}
176-
177-
// Check that the URI concept is met by the basic_uri type.
178-
BOOST_CONCEPT_ASSERT((URI<basic_uri<boost::network::tags::default_string> >));
179-
BOOST_CONCEPT_ASSERT((URI<basic_uri<boost::network::tags::default_wstring> >));
15+
namespace boost { namespace network { namespace uri {
18016

17+
template <class Tag>
18+
struct uri_base {
19+
typedef typename string<Tag>::type string_type;
20+
21+
uri_base(string_type const & uri = string_type())
22+
:
23+
raw_(uri),
24+
parts_(),
25+
valid_(parse_uri(raw_, parts_))
26+
{ }
27+
28+
uri_base(const uri_base & other)
29+
:
30+
raw_(other.raw_),
31+
parts_(other.parts_),
32+
valid_(other.valid_)
33+
{ }
34+
35+
uri_base & operator=(uri_base other) {
36+
other.swap(*this);
37+
return *this;
38+
}
39+
40+
uri_base & operator=(string_type const & uri) {
41+
return *this = uri_base(uri);
42+
}
43+
44+
void swap(uri_base & other) {
45+
using std::swap;
46+
47+
swap(other.raw_, raw_);
48+
swap(other.parts_, parts_);
49+
swap(other.valid_, valid_);
50+
}
51+
52+
string_type scheme() const {
53+
return parts_.scheme;
54+
}
55+
56+
string_type user_info() const {
57+
return parts_.user_info ? *parts_.user_info : string_type();
58+
}
59+
60+
string_type host() const {
61+
return parts_.host ? *parts_.host : string_type();
62+
}
63+
64+
// uint16_t port() const {
65+
string_type port() const {
66+
return parts_.port ? *parts_.port : 0;
67+
}
68+
69+
string_type path() const {
70+
return parts_.path;
71+
}
72+
73+
string_type query() const {
74+
return parts_.query ? *parts_.query : string_type();
75+
}
76+
77+
string_type fragment() const {
78+
return parts_.fragment ? *parts_.fragment : string_type();
79+
}
80+
81+
string_type raw() const {
82+
return string();
83+
}
84+
85+
string_type string() const {
86+
return raw_;
87+
}
88+
89+
bool valid() const {
90+
return is_valid();
91+
}
92+
93+
bool is_valid() const {
94+
return valid_;
95+
}
96+
97+
bool operator == (uri_base const & other) const {
98+
return (raw_ == other.raw_) && (parts_ == other.parts_) && (valid_ == other.valid_);
99+
}
100+
101+
bool operator != (uri_base const & other) const {
102+
return !(*this == other);
103+
}
104+
105+
protected:
106+
107+
string_type raw_;
108+
detail::uri_parts<Tag> parts_;
109+
bool valid_;
110+
};
111+
112+
template <class Tag>
113+
struct basic_uri : uri_base<Tag> {
114+
// using uri_base<Tag>::operator=;
115+
// using typename uri_base<Tag>::string_type;
116+
// using uri_base<Tag>::operator==;
117+
// using uri_base<Tag>::operator!=;
118+
basic_uri() : uri_base<Tag>() {}
119+
basic_uri(typename uri_base<Tag>::string_type const & uri) : uri_base<Tag>(uri) {}
120+
};
121+
122+
template <class Tag>
123+
inline
124+
void swap(basic_uri<Tag> & left, basic_uri<Tag> & right) {
125+
right.swap(left);
126+
}
127+
128+
template <class Tag>
129+
inline
130+
typename string<Tag>::type
131+
scheme(basic_uri<Tag> const & uri) {
132+
return uri.scheme();
133+
}
134+
135+
template <class Tag>
136+
inline
137+
typename string<Tag>::type
138+
hier_part(basic_uri<Tag> const & uri) {
139+
return uri.hier_part();
140+
}
141+
142+
template <class Tag>
143+
inline
144+
typename string<Tag>::type
145+
user_info(basic_uri<Tag> const & uri) {
146+
return uri.user_info();
147+
}
148+
149+
template <class Tag>
150+
inline
151+
typename string<Tag>::type
152+
host(basic_uri<Tag> const & uri) {
153+
return uri.host();
154+
}
155+
156+
template <class Tag>
157+
inline
158+
// uint16_t
159+
typename string<Tag>::type
160+
port(basic_uri<Tag> const & uri) {
161+
return uri.port();
162+
}
163+
164+
template <class Tag>
165+
inline
166+
typename string<Tag>::type
167+
path(basic_uri<Tag> const & uri) {
168+
return uri.path();
169+
}
170+
171+
template <class Tag>
172+
inline
173+
typename string<Tag>::type
174+
query(basic_uri<Tag> const & uri) {
175+
return uri.query();
176+
}
177+
178+
template <class Tag>
179+
inline
180+
typename string<Tag>::type
181+
fragment(basic_uri<Tag> const & uri) {
182+
return uri.fragment();
183+
}
184+
185+
template <class Tag>
186+
inline
187+
bool
188+
is_valid(basic_uri<Tag> const & uri) {
189+
return uri.is_valid();
190+
}
191+
//
192+
// // Check that the URI concept is met by the basic_uri type.
193+
// BOOST_CONCEPT_ASSERT((URI<basic_uri<boost::network::tags::default_string> >));
194+
// BOOST_CONCEPT_ASSERT((URI<basic_uri<boost::network::tags::default_wstring> >));
195+
//
181196
} // namespace uri
182-
183197
} // namespace network
184-
185198
} // namespace boost
186199

187200
#endif

0 commit comments

Comments
 (0)