Move IntrusivePtr and utility methods to the zeek namespace

This commit is contained in:
Tim Wojtulewicz 2020-06-24 16:40:00 -04:00
parent 4668378d91
commit 9364e6a5b7
255 changed files with 3761 additions and 3730 deletions

View file

@ -5,6 +5,8 @@
#include <type_traits>
#include <utility>
namespace zeek {
/**
* A tag class for the #IntrusivePtr constructor which means: adopt
* the reference from the caller.
@ -97,7 +99,7 @@ public:
}
IntrusivePtr(const IntrusivePtr& other) noexcept
: IntrusivePtr(NewRef{}, other.get())
: IntrusivePtr(zeek::NewRef{}, other.get())
{
}
@ -181,7 +183,7 @@ template <class T, class... Ts>
IntrusivePtr<T> make_intrusive(Ts&&... args)
{
// Assumes that objects start with a reference count of 1!
return {AdoptRef{}, new T(std::forward<Ts>(args)...)};
return {zeek::AdoptRef{}, new T(std::forward<Ts>(args)...)};
}
/**
@ -193,16 +195,18 @@ IntrusivePtr<T> make_intrusive(Ts&&... args)
template <class T, class U>
IntrusivePtr<T> cast_intrusive(IntrusivePtr<U> p) noexcept
{
return {AdoptRef{}, static_cast<T*>(p.release())};
return {zeek::AdoptRef{}, static_cast<T*>(p.release())};
}
}
// -- comparison to nullptr ----------------------------------------------------
/**
* @relates IntrusivePtr
*/
template <class T>
bool operator==(const IntrusivePtr<T>& x, std::nullptr_t) {
bool operator==(const zeek::IntrusivePtr<T>& x, std::nullptr_t) {
return !x;
}
@ -210,7 +214,7 @@ bool operator==(const IntrusivePtr<T>& x, std::nullptr_t) {
* @relates IntrusivePtr
*/
template <class T>
bool operator==(std::nullptr_t, const IntrusivePtr<T>& x) {
bool operator==(std::nullptr_t, const zeek::IntrusivePtr<T>& x) {
return !x;
}
@ -218,7 +222,7 @@ bool operator==(std::nullptr_t, const IntrusivePtr<T>& x) {
* @relates IntrusivePtr
*/
template <class T>
bool operator!=(const IntrusivePtr<T>& x, std::nullptr_t) {
bool operator!=(const zeek::IntrusivePtr<T>& x, std::nullptr_t) {
return static_cast<bool>(x);
}
@ -226,7 +230,7 @@ bool operator!=(const IntrusivePtr<T>& x, std::nullptr_t) {
* @relates IntrusivePtr
*/
template <class T>
bool operator!=(std::nullptr_t, const IntrusivePtr<T>& x) {
bool operator!=(std::nullptr_t, const zeek::IntrusivePtr<T>& x) {
return static_cast<bool>(x);
}
@ -236,7 +240,7 @@ bool operator!=(std::nullptr_t, const IntrusivePtr<T>& x) {
* @relates IntrusivePtr
*/
template <class T>
bool operator==(const IntrusivePtr<T>& x, const T* y) {
bool operator==(const zeek::IntrusivePtr<T>& x, const T* y) {
return x.get() == y;
}
@ -244,7 +248,7 @@ bool operator==(const IntrusivePtr<T>& x, const T* y) {
* @relates IntrusivePtr
*/
template <class T>
bool operator==(const T* x, const IntrusivePtr<T>& y) {
bool operator==(const T* x, const zeek::IntrusivePtr<T>& y) {
return x == y.get();
}
@ -252,7 +256,7 @@ bool operator==(const T* x, const IntrusivePtr<T>& y) {
* @relates IntrusivePtr
*/
template <class T>
bool operator!=(const IntrusivePtr<T>& x, const T* y) {
bool operator!=(const zeek::IntrusivePtr<T>& x, const T* y) {
return x.get() != y;
}
@ -260,7 +264,7 @@ bool operator!=(const IntrusivePtr<T>& x, const T* y) {
* @relates IntrusivePtr
*/
template <class T>
bool operator!=(const T* x, const IntrusivePtr<T>& y) {
bool operator!=(const T* x, const zeek::IntrusivePtr<T>& y) {
return x != y.get();
}
@ -273,7 +277,7 @@ bool operator!=(const T* x, const IntrusivePtr<T>& y) {
* @relates IntrusivePtr
*/
template <class T, class U>
auto operator==(const IntrusivePtr<T>& x, const IntrusivePtr<U>& y)
auto operator==(const zeek::IntrusivePtr<T>& x, const zeek::IntrusivePtr<U>& y)
-> decltype(x.get() == y.get())
{
return x.get() == y.get();
@ -283,9 +287,8 @@ auto operator==(const IntrusivePtr<T>& x, const IntrusivePtr<U>& y)
* @relates IntrusivePtr
*/
template <class T, class U>
auto operator!=(const IntrusivePtr<T>& x, const IntrusivePtr<U>& y)
auto operator!=(const zeek::IntrusivePtr<T>& x, const zeek::IntrusivePtr<U>& y)
-> decltype(x.get() != y.get())
{
return x.get() != y.get();
}