Skip to content

Commit 3e75772

Browse files
committed
Merge pull request #42 from glynos/master
Added a bunch of documentation and removed the noexcept operator from some accessors.
2 parents 6707b22 + f79b5e3 commit 3e75772

File tree

6 files changed

+150
-61
lines changed

6 files changed

+150
-61
lines changed

src/CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@ set(Uri_SRCS
1414
${CMAKE_CURRENT_SOURCE_DIR}/detail/uri_resolve.cpp
1515
)
1616
if(NOT CPP-NETLIB_BUILD_SINGLE_LIB)
17-
add_library(cppnetlib-uri ${Uri_SRCS})
18-
target_link_libraries(cppnetlib-uri ${Boost_LIBRARIES})
17+
add_library(network-uri ${Uri_SRCS})
18+
target_link_libraries(network-uri ${Boost_LIBRARIES})
1919
if(${CMAKE_CXX_COMPILER_ID} MATCHES Clang)
2020
if (NOT CPP-NETLIB_DISABLE_LIBCXX)
21-
target_link_libraries(cppnetlib-uri "c++")
21+
target_link_libraries(network-uri "c++")
2222
endif()
2323
endif()
2424
install(
2525
TARGETS
26-
cppnetlib-uri
26+
network-uri
2727
DESTINATION ${CMAKE_INSTALL_PREFIX}/lib
2828
)
2929

src/network/uri.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@
1010

1111
/**
1212
* \defgroup uri URI
13+
*
14+
* This module contains a class encapsulating a URI, a URI builder and
15+
* percent encoding and decoding functions.
16+
*
17+
* \file
18+
* \brief Contains the uri, uri_builder classes and functions
19+
* for percent encoding and decoding.
1320
*/
1421

1522
#include <network/uri/uri.hpp>

src/network/uri/uri.hpp

Lines changed: 111 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88
#ifndef NETWORK_URI_INC
99
#define NETWORK_URI_INC
1010

11+
/**
12+
* \file
13+
* \brief Contains the uri the class.
14+
*/
15+
1116
#include <iterator>
1217
#include <algorithm>
1318
#include <functional>
@@ -41,18 +46,53 @@ namespace network {
4146
} // namespace detail
4247
#endif // !defined(DOXYGEN_SHOULD_SKIP_THIS)
4348

49+
/**
50+
* \enum uri_comparison_level
51+
* \brief Defines the steps on the URI comparison ladder.
52+
*/
4453
enum class uri_comparison_level {
4554
string_comparison,
4655
syntax_based,
4756
scheme_based,
4857
};
4958

59+
/**
60+
* \ingroup uri
61+
* \class uri_builder network/uri/uri_builder.hpp network/uri.hpp
62+
* \brief A class that allows complex uri objects to be constructed.
63+
* \sa uri
64+
*/
5065
class uri_builder;
5166

5267
/**
5368
* \ingroup uri
5469
* \class uri network/uri/uri.hpp network/uri.hpp
55-
* \brief A class that parses a URI string into its component parts.
70+
* \brief A class that parses a URI (Uniform Resource Identifier)
71+
* into its component parts.
72+
*
73+
* This class conforms to a URI as defined by RFC 3986, RFC 3987 and
74+
* RFC 2732, including scoped IDs. It provides member functions for
75+
* normalizing, comparing and resolving URIs.
76+
*
77+
* A URI has the syntax:
78+
*
79+
* \code
80+
* [scheme:][user_info@][host][:port][path][?query][#fragment]
81+
* \endcode
82+
*
83+
* Example:
84+
*
85+
* \code
86+
* network::uri instance("http://cpp-netlib.org/");
87+
* assert(instance.is_absolute());
88+
* assert(!instance.is_opaque());
89+
* assert(instance.scheme());
90+
* assert("http" == *instance.scheme());
91+
* assert(instance.host());
92+
* assert("cpp-netlib.org" == *instance.host());
93+
* assert(instance.path());
94+
* assert("/" == *instance.path());
95+
* \endcode
5696
*/
5797
class NETWORK_URI_DECL uri {
5898

@@ -198,33 +238,32 @@ namespace network {
198238
* \brief Returns the URI scheme.
199239
* \return The scheme, if it exists, or boost::none.
200240
*/
201-
boost::optional<string_view> scheme() const NETWORK_URI_NOEXCEPT;
241+
boost::optional<string_view> scheme() const;
202242

203243
/**
204244
* \brief Returns the URI user info.
205245
* \return The user info, if it exists, or boost::none.
206246
*/
207-
boost::optional<string_view> user_info() const NETWORK_URI_NOEXCEPT;
247+
boost::optional<string_view> user_info() const;
208248

209249
/**
210250
* \brief Returns the URI host.
211251
* \return The host, if it exists, or boost::none.
212252
*/
213-
boost::optional<string_view> host() const NETWORK_URI_NOEXCEPT;
253+
boost::optional<string_view> host() const;
214254

215255
/**
216256
* \brief Returns the URI port.
217257
* \return The port, if it exists, or boost::none.
218258
*/
219-
boost::optional<string_view> port() const NETWORK_URI_NOEXCEPT;
259+
boost::optional<string_view> port() const;
220260

221261
/**
222262
* \brief Returns the URI port as an integer.
223263
* \return The port, if it exists, or boost::none.
224264
*/
225265
template <typename IntT>
226-
boost::optional<IntT> port(typename std::is_integral<IntT>::type * =
227-
0) const NETWORK_URI_NOEXCEPT {
266+
boost::optional<IntT> port(typename std::is_integral<IntT>::type * = 0) const {
228267
if (auto p = port()) {
229268
try {
230269
return static_cast<IntT>(
@@ -241,25 +280,25 @@ namespace network {
241280
* \brief Returns the URI path.
242281
* \return The path, if it exists, or boost::none.
243282
*/
244-
boost::optional<string_view> path() const NETWORK_URI_NOEXCEPT;
283+
boost::optional<string_view> path() const;
245284

246285
/**
247286
* \brief Returns the URI query.
248287
* \return The query, if it exists, or boost::none.
249288
*/
250-
boost::optional<string_view> query() const NETWORK_URI_NOEXCEPT;
289+
boost::optional<string_view> query() const;
251290

252291
/**
253292
* \brief Returns the URI fragment.
254293
* \return The fragment, if it exists, or boost::none.
255294
*/
256-
boost::optional<string_view> fragment() const NETWORK_URI_NOEXCEPT;
295+
boost::optional<string_view> fragment() const;
257296

258297
/**
259298
* \brief Returns the URI authority.
260299
* \return The authority, if it exists, or boost::none.
261300
*/
262-
boost::optional<string_view> authority() const NETWORK_URI_NOEXCEPT;
301+
boost::optional<string_view> authority() const;
263302

264303
#if !defined(_MSC_VER)
265304
/**
@@ -332,14 +371,14 @@ namespace network {
332371
* \brief Checks if the uri is absolute, i.e. it has a scheme.
333372
* \returns \c true if it is absolute, \c false if it is relative.
334373
*/
335-
bool is_absolute() const NETWORK_URI_NOEXCEPT;
374+
bool is_absolute() const;
336375

337376
/**
338377
* \brief Checks if the uri is opaque, i.e. if it doesn't have an
339378
* authority.
340379
* \returns \c true if it is opaque, \c false if it is hierarchical.
341380
*/
342-
bool is_opaque() const NETWORK_URI_NOEXCEPT;
381+
bool is_opaque() const;
343382

344383
/**
345384
* \brief Normalizes a uri object at a given level in the
@@ -357,7 +396,7 @@ namespace network {
357396
* \returns A relative reference of this URI against the base.
358397
* \throws std::bad_alloc
359398
*/
360-
uri make_relative(const uri &other) const;
399+
uri make_relative(const uri &base) const;
361400

362401
#if !defined(DOXYGEN_SHOULD_SKIP_THIS)
363402
uri make_reference(const uri &base) const { return make_relative(base); }
@@ -508,39 +547,81 @@ namespace network {
508547
detail::uri_parts<string_type::iterator> uri_parts_;
509548
};
510549

511-
template <class Source>
512-
inline uri make_uri(const Source &source,
513-
std::error_code &ec) NETWORK_URI_NOEXCEPT {
514-
return uri(source, ec);
515-
}
516-
550+
/**
551+
* \brief \c uri factory function.
552+
* \param first The first element in a string sequence.
553+
* \param last The end + 1th element in a string sequence.
554+
* \param ec Error code set if the sequence is not a valid URI.
555+
*/
517556
template <class InputIter>
518557
inline uri make_uri(InputIter first, InputIter last,
519-
std::error_code &ec) NETWORK_URI_NOEXCEPT {
558+
std::error_code &ec) {
520559
return uri(first, last, ec);
521560
}
522561

523-
void swap(uri &lhs, uri &rhs) NETWORK_URI_NOEXCEPT;
562+
/**
563+
* \brief \c uri factory function.
564+
* \param source A source string that is to be parsed as a URI.
565+
* \param ec Error code set if the source is not a valid URI.
566+
*/
567+
template <class Source>
568+
inline uri make_uri(const Source &source,
569+
std::error_code &ec) {
570+
return uri(source, ec);
571+
}
524572

525-
bool operator==(const uri &lhs, const uri &rhs);
573+
/**
574+
* \brief Swaps one uri object with another.
575+
*/
576+
void swap(uri &lhs, uri &rhs) NETWORK_URI_NOEXCEPT;
577+
578+
/**
579+
* \brief Equality operator for the \c uri.
580+
*/
581+
bool operator==(const uri &lhs, const uri &rhs) NETWORK_URI_NOEXCEPT;
526582

527-
bool operator==(const uri &lhs, const char *rhs);
583+
/**
584+
* \brief Equality operator for the \c uri.
585+
*/
586+
bool operator==(const uri &lhs, const char *rhs) NETWORK_URI_NOEXCEPT;
528587

529-
inline bool operator==(const char *lhs, const uri &rhs) { return rhs == lhs; }
588+
/**
589+
* \brief Equality operator for the \c uri.
590+
*/
591+
inline bool operator==(const char *lhs, const uri &rhs) NETWORK_URI_NOEXCEPT {
592+
return rhs == lhs;
593+
}
530594

531-
inline bool operator!=(const uri &lhs, const uri &rhs) {
595+
/**
596+
* \brief Inequality operator for the \c uri.
597+
*/
598+
inline bool operator!=(const uri &lhs, const uri &rhs) NETWORK_URI_NOEXCEPT {
532599
return !(lhs == rhs);
533600
}
534601

535-
bool operator<(const uri &lhs, const uri &rhs);
602+
/**
603+
* \brief Less-than operator for the \c uri.
604+
*/
605+
bool operator<(const uri &lhs, const uri &rhs) NETWORK_URI_NOEXCEPT ;
536606

537-
inline bool operator>(const uri &lhs, const uri &rhs) { return rhs < lhs; }
607+
/**
608+
* \brief Greater-than operator for the \c uri.
609+
*/
610+
inline bool operator>(const uri &lhs, const uri &rhs) NETWORK_URI_NOEXCEPT {
611+
return rhs < lhs;
612+
}
538613

539-
inline bool operator<=(const uri &lhs, const uri &rhs) {
614+
/**
615+
* \brief Less-than-or-equal-to operator for the \c uri.
616+
*/
617+
inline bool operator<=(const uri &lhs, const uri &rhs) NETWORK_URI_NOEXCEPT {
540618
return !(rhs < lhs);
541619
}
542620

543-
inline bool operator>=(const uri &lhs, const uri &rhs) {
621+
/**
622+
* \brief Greater-than-or-equal-to operator for the \c uri.
623+
*/
624+
inline bool operator>=(const uri &lhs, const uri &rhs) NETWORK_URI_NOEXCEPT {
544625
return !(lhs < rhs);
545626
}
546627
} // namespace network

src/network/uri/uri_errors.hpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,19 @@
77
#ifndef NETWORK_URI_ERRORS_INC
88
#define NETWORK_URI_ERRORS_INC
99

10+
/**
11+
* \file
12+
* \brief Contains functions and exceptions for URI error handling.
13+
*/
14+
1015
#include <system_error>
1116
#include <network/uri/config.hpp>
1217

1318
namespace network {
1419

20+
#if !defined(DOXYGEN_SHOULD_SKIP_THIS)
1521
enum class uri_error {
22+
1623
// parser errors
1724
invalid_syntax = 1,
1825

@@ -35,10 +42,12 @@ namespace network {
3542
const std::error_category &uri_category();
3643

3744
std::error_code make_error_code(uri_error e);
45+
#endif // !defined(DOXYGEN_SHOULD_SKIP_THIS)
3846

3947
/**
4048
* \class uri_syntax_error uri.hpp network/uri.hpp
41-
* \brief An exception thrown when a URI cannot be parsed.
49+
* \brief An exception thrown by the \c uri constructor when a URI
50+
* cannot be parsed.
4251
*/
4352
class uri_syntax_error : public std::system_error {
4453

0 commit comments

Comments
 (0)