Commit 3bca295b authored by Joseph Noir's avatar Joseph Noir

Add constructors and assign operators

parent ffb044f1
...@@ -32,16 +32,12 @@ ...@@ -32,16 +32,12 @@
namespace caf { namespace caf {
namespace io { namespace io {
namespace detail {
class uri_private; class uri_private;
void intrusive_ptr_add_ref(uri_private* p); void intrusive_ptr_add_ref(uri_private* p);
void intrusive_ptr_release(uri_private* p); void intrusive_ptr_release(uri_private* p);
} // namespace detail
namespace { namespace {
using str_bounds = std::pair<std::string::iterator, std::string::iterator>; using str_bounds = std::pair<std::string::iterator, std::string::iterator>;
...@@ -72,8 +68,7 @@ public: ...@@ -72,8 +68,7 @@ public:
// treat a NULL string like an empty string // treat a NULL string like an empty string
return (what) ? str().compare(what) : str().compare(""); return (what) ? str().compare(what) : str().compare("");
} }
/// ///
/// @brief Create an empty URI. /// @brief Create an empty URI.
/// ///
...@@ -85,8 +80,30 @@ public: ...@@ -85,8 +80,30 @@ public:
/// @note {@link caf::io::uri uri} is implicit shared, thus copy /// @note {@link caf::io::uri uri} is implicit shared, thus copy
/// operations are very fast and lightweight. /// operations are very fast and lightweight.
/// ///
uri(const uri& other); uri(const uri& other) = default;
///
/// @brief Create this object from @p other.
/// @param other The original {@link caf::io::uri uri} object.
/// @note {@link caf::io::uri uri} is implicit shared, thus copy
/// operations are very fast and lightweight.
///
uri(uri&& other) = default;
///
/// @brief Copy assigment from @p other.
/// @param other Original {@link caf::io::uri uri} object.
/// @returns <code>*this</code>.
///
uri& operator=(const uri& other) = default;
///
/// @brief Move assignment from @p other;
/// @param other Original {@link caf::io::uri uri} object.
/// @return <code>*this</code>.
///
uri& operator=(uri&& other) = default;
/// ///
/// @brief Create an URI from @p uri_str. /// @brief Create an URI from @p uri_str.
/// ///
...@@ -101,7 +118,7 @@ public: ...@@ -101,7 +118,7 @@ public:
/// (e.g. "Hello World" is a string, but is an invalid URI). /// (e.g. "Hello World" is a string, but is an invalid URI).
/// ///
static optional<uri> make(const std::string& uri_str); static optional<uri> make(const std::string& uri_str);
/// ///
/// @brief Create an URI from @p uri_str_c_str. /// @brief Create an URI from @p uri_str_c_str.
/// @param uri_c_str An URI encoded as a C-string. /// @param uri_c_str An URI encoded as a C-string.
...@@ -251,13 +268,6 @@ public: ...@@ -251,13 +268,6 @@ public:
/// ///
void swap(uri& other); void swap(uri& other);
///
/// @brief Equivalent to <code>uri(other).swap(*this)</code>.
/// @param other Original {@link caf::io::uri uri} object.
/// @returns <code>*this</code>.
///
uri& operator=(const uri& other);
/// @cond private /// @cond private
template <class Inspector> template <class Inspector>
...@@ -268,9 +278,9 @@ public: ...@@ -268,9 +278,9 @@ public:
/// @endcond /// @endcond
private: private:
uri(detail::uri_private* d); uri(uri_private* d);
intrusive_ptr<detail::uri_private> d_; intrusive_ptr<uri_private> d_;
}; };
} // namespace io } // namespace io
......
...@@ -44,7 +44,6 @@ using str_bounds = std::pair<std::string::iterator, std::string::iterator>; ...@@ -44,7 +44,6 @@ using str_bounds = std::pair<std::string::iterator, std::string::iterator>;
namespace caf { namespace caf {
namespace io { namespace io {
namespace detail {
class uri_private : public ref_counted { class uri_private : public ref_counted {
friend optional<uri> uri::make(const string& uri_str); friend optional<uri> uri::make(const string& uri_str);
...@@ -206,7 +205,7 @@ public: ...@@ -206,7 +205,7 @@ public:
inline const str_bounds& port() const { return m_port_; } inline const str_bounds& port() const { return m_port_; }
inline uint16_t port_as_int() const { return m_int_port_; } inline uint16_t port_as_int() const { return m_int_port_; }
inline const str_bounds& user_information() const { inline const str_bounds& user_information() const {
return m_user_information_; return m_user_information_;
} }
...@@ -229,20 +228,19 @@ void intrusive_ptr_release(uri_private* p) { ...@@ -229,20 +228,19 @@ void intrusive_ptr_release(uri_private* p) {
} }
namespace { namespace {
intrusive_ptr<uri_private> m_default_uri_private(new uri_private); intrusive_ptr<uri_private> m_default_uri_private(new uri_private);
} // namespace <anonymous> } // namespace <anonymous>
} // namespace detail
} // namespace io } // namespace io
} // namespace caf } // namespace caf
namespace caf { namespace caf {
namespace io { namespace io {
optional<uri> uri::make(const string& uri_str) { optional<uri> uri::make(const string& uri_str) {
detail::uri_private* result = new detail::uri_private; uri_private* result = new uri_private;
if (result->parse_uri(uri_str)) if (result->parse_uri(uri_str))
return uri{result}; return uri{result};
else { else {
...@@ -256,22 +254,14 @@ optional<uri> uri::make(const char* cstr) { ...@@ -256,22 +254,14 @@ optional<uri> uri::make(const char* cstr) {
return make(tmp); return make(tmp);
} }
uri::uri() : d_(detail::m_default_uri_private) { uri::uri() : d_(m_default_uri_private) {
// nop // nop
} }
uri::uri(detail::uri_private* d) : d_(d) { uri::uri(uri_private* d) : d_(d) {
// nop
}
uri::uri(const uri& other) : d_(other.d_) {
// nop // nop
} }
uri& uri::operator=(const uri& other) {
d_ = other.d_;
return *this;
}
const string& uri::str() const { const string& uri::str() const {
return d_->as_string(); return d_->as_string();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment