/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
/** * StaticLocalAutoPtr and StaticLocalRefPtr are like UniquePtr and RefPtr, * except they are suitable for use as "magic static" local variables -- that * is, they are able to take advantage of C++11's guarantee of thread safety * during initialization by atomically constructing both the smart pointer * itself as well as the object being pointed to. * * A static local instance of StaticLocal{Auto,Ref}Ptr does not cause the * compiler to emit any atexit calls. In order to accomplish this, * StaticLocal{Auto,Ref}Ptr must have a trivial destructor. As a consequence, * it does not delete/release its raw pointer upon destruction. * * The clang plugin, run as part of our "static analysis" builds, makes it a * compile-time error to use StaticLocal{Auto,Ref}Ptr as anything except a * static local variable. * * StaticLocal{Auto,Ref}Ptr have a limited interface as compared to * ns{Auto,Ref}Ptr; this is intentional, since their range of acceptable uses is * smaller.
*/
template <typename T> class MOZ_STATIC_LOCAL_CLASS StaticLocalAutoPtr final { public: explicit StaticLocalAutoPtr(T* aRawPtr) : mRawPtr(aRawPtr) {}
// We do not allow assignment as the intention of this class is to only // assign to mRawPtr during construction.
StaticLocalAutoPtr& operator=(const StaticLocalAutoPtr<T>& aOther) = delete;
StaticLocalAutoPtr& operator=(StaticLocalAutoPtr<T>&&) = delete;
private: // We do not allow assignment as the intention of this class is to only // assign to mRawPtr during construction.
StaticLocalRefPtr<T>& operator=(const StaticLocalRefPtr<T>& aRhs) = delete;
StaticLocalRefPtr<T>& operator=(StaticLocalRefPtr<T>&& aRhs) = delete;
REFLEXIVE_EQUALITY_OPERATORS(const StaticLocalAutoPtr<T>&, const U*,
lhs.get() == rhs, class T, class U)
REFLEXIVE_EQUALITY_OPERATORS(const StaticLocalAutoPtr<T>&, U*, lhs.get() == rhs, class T, class U)
// Let us compare StaticLocalAutoPtr to 0.
REFLEXIVE_EQUALITY_OPERATORS(const StaticLocalAutoPtr<T>&,
StaticLocalPtr_internal::Zero*,
lhs.get() == nullptr, class T)
REFLEXIVE_EQUALITY_OPERATORS(const StaticLocalRefPtr<T>&, const U*,
lhs.get() == rhs, class T, class U)
REFLEXIVE_EQUALITY_OPERATORS(const StaticLocalRefPtr<T>&, U*, lhs.get() == rhs, class T, class U)
// Let us compare StaticLocalRefPtr to 0.
REFLEXIVE_EQUALITY_OPERATORS(const StaticLocalRefPtr<T>&,
StaticLocalPtr_internal::Zero*,
lhs.get() == nullptr, class T)
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.