Menu

[r223]: / trunk / boost / network / uri / basic_uri.hpp  Maximize  Restore  History

Download this file

132 lines (103 with data), 3.7 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#ifndef BOOST_NETWORK_URL_BASIC_URL_
#define BOOST_NETWORK_URL_BASIC_URL_
// Copyright 2009 Dean Michael Berris.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#include <boost/spirit/home/qi.hpp>
#include <boost/fusion/adapted/std_pair.hpp>
#include <boost/spirit/home/phoenix.hpp>
#include <boost/range.hpp>
#include <boost/network/tags.hpp>
#include <boost/network/uri/basic_uri_fwd.hpp>
#include <boost/network/uri/detail/parse_uri.hpp>
#include <boost/network/uri/uri_concept.hpp>
namespace boost { namespace network { namespace uri {
template <class Tag>
struct uri_base {
typedef typename string<Tag>::type string_type;
uri_base(string_type const & uri = string_type())
:
raw_(uri),
parts_(),
valid_(parse_uri(raw_, parts_))
{ }
uri_base(const uri_base & other)
:
raw_(other.raw_),
parts_(other.parts_),
valid_(other.valid_)
{ }
uri_base & operator=(uri_base other) {
other.swap(*this);
return *this;
}
uri_base & operator=(string_type const & uri) {
return *this = uri_base(uri);
}
void swap(uri_base & other) {
using std::swap;
swap(other.raw_, raw_);
swap(other.parts_, parts_);
swap(other.valid_, valid_);
}
string_type protocol() const {
return parts_.scheme;
}
string_type rest() const {
return parts_.scheme_specific_part;
}
bool valid() const {
return valid_;
}
bool operator==(uri_base const & other) const {
return (raw_ == other.raw_) && (parts_ == other.parts_) && (valid_ == other.valid_);
}
bool operator!=(uri_base const & other) const {
return !(*this == other);
}
protected:
string_type raw_;
detail::uri_parts<Tag> parts_;
bool valid_;
};
template <class Tag>
struct basic_uri : uri_base<Tag> {
using uri_base<Tag>::operator=;
using uri_base<Tag>::string_type;
using uri_base<Tag>::operator==;
using uri_base<Tag>::operator!=;
basic_uri() : uri_base<Tag>() {}
basic_uri(typename uri_base<Tag>::string_type const & uri) : uri_base<Tag>(uri) {}
};
template <class Tag>
inline
void
swap(basic_uri<Tag> & left, basic_uri<Tag> & right) {
right.swap(left);
}
template <class Tag>
inline
typename string<Tag>::type
protocol(basic_uri<Tag> const & uri) {
return uri.protocol();
}
template <class Tag>
inline
typename string<Tag>::type
rest(basic_uri<Tag> const & uri) {
return uri.rest();
}
template <class Tag>
inline
bool
valid(basic_uri<Tag> const & uri) {
return uri.valid();
}
// Check that the URI concept is met by the basic_uri type.
BOOST_CONCEPT_ASSERT((URI<basic_uri<boost::network::tags::default_string> >));
BOOST_CONCEPT_ASSERT((URI<basic_uri<boost::network::tags::default_wstring> >));
} // namespace uri
} // namespace network
} // namespace boost
#endif