Skip to content

Commit b061058

Browse files
Modernizing
1 parent 955ba59 commit b061058

File tree

1 file changed

+37
-61
lines changed

1 file changed

+37
-61
lines changed

include/buffer/shared_buffer.hpp

Lines changed: 37 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -66,29 +66,27 @@ namespace chops {
6666
class const_shared_buffer;
6767

6868
/**
69-
* @brief A mutable (modifiable) byte buffer class with convenience methods, internally
70-
* reference-counted for efficient copying.
69+
* @brief A mutable (modifiable) byte buffer class with convenience methods, internally
70+
* reference-counted for efficient copying.
7171
*
72-
* This class provides ownership, copying, and lifetime management for byte oriented
73-
* buffers. In particular, it is designed to be used in conjunction with the
74-
* @c const_shared_buffer class for efficient transfer and correct lifetime management
75-
* of buffers in asynchronous libraries (such as the C++ Networking TS). In particular,
76-
* a reference counted buffer can be passed among multiple layers of software without
77-
* any one layer "owning" the buffer.
72+
* This class provides ownership, copying, and lifetime management for byte oriented
73+
* buffers. In particular, it is designed to be used in conjunction with the
74+
* @c const_shared_buffer class for efficient transfer and correct lifetime management
75+
* of buffers in asynchronous libraries (such as the C++ Networking TS). In particular,
76+
* a reference counted buffer can be passed among multiple layers of software without
77+
* any one layer "owning" the buffer.
7878
*
79-
* A std::byte pointer returned by the @c data method may be invalidated if the
80-
* @c mutable_shared_buffer is modified in any way (this follows the usual constraints
81-
* on @c std::vector iterator invalidation).
79+
* A std::byte pointer returned by the @c data method may be invalidated if the
80+
* @c mutable_shared_buffer is modified in any way (this follows the usual constraints
81+
* on @c std::vector iterator invalidation).
8282
*
83-
* This class is similar to @c const_shared_buffer, but with mutable characteristics.
83+
* This class is similar to @c const_shared_buffer, but with mutable characteristics.
8484
*
85-
* @invariant There will always be an internal buffer of data, even if the size is zero.
86-
*
87-
* @note Modifying the underlying buffer of data (for example by writing bytes using the
88-
* @c data method, or appending data) will show up in any other @c mutable_shared_buffer
89-
* objects that have been copied to or from the original object.
85+
* @invariant There will always be an internal buffer of data, even if the size is zero.
9086
*
91-
* @ingroup utility_module
87+
* @note Modifying the underlying buffer of data (for example by writing bytes using the
88+
* @c data method, or appending data) will show up in any other @c mutable_shared_buffer
89+
* objects that have been copied to or from the original object.
9290
*
9391
*/
9492

@@ -104,9 +102,6 @@ class mutable_shared_buffer {
104102

105103
friend class const_shared_buffer;
106104

107-
friend bool operator==(const mutable_shared_buffer&, const mutable_shared_buffer&) noexcept;
108-
friend bool operator<(const mutable_shared_buffer&, const mutable_shared_buffer&) noexcept;
109-
110105
friend bool operator==(const mutable_shared_buffer&, const const_shared_buffer&) noexcept;
111106
friend bool operator==(const const_shared_buffer&, const mutable_shared_buffer&) noexcept;
112107

@@ -343,19 +338,6 @@ class mutable_shared_buffer {
343338
return append(b);
344339
}
345340

346-
}; // end mutable_shared_buffer class
347-
348-
// non-member functions
349-
/**
350-
* @brief Swap two @c mutable_shared_buffer objects.
351-
*
352-
* @relates mutable_shared_buffer
353-
*/
354-
355-
inline void swap(mutable_shared_buffer& lhs, mutable_shared_buffer& rhs) noexcept {
356-
lhs.swap(rhs);
357-
}
358-
359341
/**
360342
* @brief Compare two @c mutable_shared_buffer objects for internal buffer
361343
* byte-by-byte equality.
@@ -364,38 +346,37 @@ inline void swap(mutable_shared_buffer& lhs, mutable_shared_buffer& rhs) noexcep
364346
* elements.
365347
*
366348
* @return @c true if @c size() same for each, and each byte compares @c true.
367-
*
368-
* @relates mutable_shared_buffer
369349
*/
370-
inline bool operator== (const mutable_shared_buffer& lhs, const mutable_shared_buffer& rhs) noexcept {
371-
return *(lhs.m_data) == *(rhs.m_data);
372-
}
350+
bool operator== (const mutable_shared_buffer& rhs) noexcept {
351+
return *m_data == *(rhs.m_data);
352+
}
373353

374354
/**
375-
* @brief Compare two @c mutable_shared_buffer objects for inequality.
355+
* @brief Compare two @c mutable_shared_buffer objects for internal buffer
356+
* byte-by-byte spaceship operator ordering.
376357
*
377-
* @return Opposite of @c operator==.
358+
* Internally this invokes the @c std::vector @c <=> on @c std::byte
359+
* elements.
360+
*
361+
* @return Spaceship operator comparison result.
378362
*
379-
* @relates mutable_shared_buffer
380363
*/
381-
inline bool operator!= (const mutable_shared_buffer& lhs, const mutable_shared_buffer& rhs) noexcept {
382-
return !(lhs == rhs);
383-
}
364+
auto operator<=>(const mutable_shared_buffer& rhs) noexcept {
365+
return *m_data <=> *(rhs.m_data);
366+
}
384367

368+
}; // end mutable_shared_buffer class
369+
370+
// non-member functions
385371
/**
386-
* @brief Compare two @c mutable_shared_buffer objects for internal buffer
387-
* byte-by-byte less-than ordering.
388-
*
389-
* Internally this invokes the @c std::vector @c operator< on @c std::byte
390-
* elements.
391-
*
392-
* @return @c true if internal buffer of left is less than internal buffer of right.
372+
* @brief Swap two @c mutable_shared_buffer objects.
393373
*
394-
* @relates mutable_shared_buffer
395374
*/
396-
inline bool operator< (const mutable_shared_buffer& lhs, const mutable_shared_buffer& rhs) noexcept {
397-
return *(lhs.m_data) < *(rhs.m_data);
398-
}
375+
376+
inline void swap(mutable_shared_buffer& lhs, mutable_shared_buffer& rhs) noexcept {
377+
lhs.swap(rhs);
378+
}
379+
399380

400381
/**
401382
* @brief A reference counted non-modifiable buffer class with various convenience methods,
@@ -409,8 +390,6 @@ inline bool operator< (const mutable_shared_buffer& lhs, const mutable_shared_bu
409390
*
410391
* @invariant There will always be an internal buffer of data, even if the size is zero.
411392
*
412-
* @ingroup utility_module
413-
*
414393
*/
415394

416395
class const_shared_buffer {
@@ -560,7 +539,6 @@ class const_shared_buffer {
560539
*
561540
* @return @c true if @c size() same for each, and each byte compares @c true.
562541
*
563-
* @relates const_shared_buffer
564542
*/
565543
inline bool operator== (const const_shared_buffer& lhs, const const_shared_buffer& rhs) noexcept {
566544
return *(lhs.m_data) == *(rhs.m_data);
@@ -571,7 +549,6 @@ inline bool operator== (const const_shared_buffer& lhs, const const_shared_buffe
571549
*
572550
* @return Opposite of @c operator==.
573551
*
574-
* @relates const_shared_buffer
575552
*/
576553
inline bool operator!= (const const_shared_buffer& lhs, const const_shared_buffer& rhs) noexcept {
577554
return !(lhs == rhs);
@@ -586,7 +563,6 @@ inline bool operator!= (const const_shared_buffer& lhs, const const_shared_buffe
586563
*
587564
* @return @c true if internal buffer of left is less than internal buffer of right.
588565
*
589-
* @relates const_shared_buffer
590566
*/
591567
inline bool operator< (const const_shared_buffer& lhs, const const_shared_buffer& rhs) noexcept {
592568
return *(lhs.m_data) < *(rhs.m_data);

0 commit comments

Comments
 (0)