diff options
author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
---|---|---|
committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
commit | 1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch) | |
tree | 46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/WebCore/rendering/style/DataRef.h | |
parent | 32761a6cee1d0dee366b885b7b9c777e67885688 (diff) | |
download | WebKitGtk-tarball-master.tar.gz |
webkitgtk-2.16.5HEADwebkitgtk-2.16.5master
Diffstat (limited to 'Source/WebCore/rendering/style/DataRef.h')
-rw-r--r-- | Source/WebCore/rendering/style/DataRef.h | 72 |
1 files changed, 50 insertions, 22 deletions
diff --git a/Source/WebCore/rendering/style/DataRef.h b/Source/WebCore/rendering/style/DataRef.h index 3eb14e1eb..f542d6c2a 100644 --- a/Source/WebCore/rendering/style/DataRef.h +++ b/Source/WebCore/rendering/style/DataRef.h @@ -1,8 +1,5 @@ /* - * Copyright (C) 2000 Lars Knoll (knoll@kde.org) - * (C) 2000 Antti Koivisto (koivisto@kde.org) - * (C) 2000 Dirk Mueller (mueller@kde.org) - * Copyright (C) 2003, 2005, 2008 Apple Inc. All rights reserved. + * Copyright (C) 2003-2017 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -21,40 +18,73 @@ * */ -#ifndef DataRef_h -#define DataRef_h +#pragma once -#include <wtf/PassRef.h> #include <wtf/Ref.h> namespace WebCore { template <typename T> class DataRef { public: - DataRef(PassRef<T> data) : m_data(std::move(data)) { } - DataRef(const DataRef& other) : m_data(const_cast<T&>(other.m_data.get())) { } - DataRef& operator=(const DataRef& other) { m_data = const_cast<T&>(other.m_data.get()); return *this; } + DataRef(Ref<T>&& data) + : m_data(WTFMove(data)) + { + } + + DataRef(const DataRef& other) + : m_data(other.m_data.copyRef()) + { + } + + DataRef& operator=(const DataRef& other) + { + m_data = other.m_data.copyRef(); + return *this; + } + + DataRef(DataRef&&) = default; + DataRef& operator=(DataRef&&) = default; + + DataRef replace(DataRef&& other) + { + return m_data.replace(WTFMove(other.m_data)); + } - const T* get() const { return &m_data.get(); } + operator const T&() const + { + return m_data; + } + + const T& get() const + { + return m_data; + } + + const T& operator*() const + { + return m_data; + } - const T& operator*() const { return *get(); } - const T* operator->() const { return get(); } + const T* operator->() const + { + return m_data.ptr(); + } - T* access() + T& access() { if (!m_data->hasOneRef()) m_data = m_data->copy(); - return &m_data.get(); + return m_data; } - bool operator==(const DataRef<T>& o) const + bool operator==(const DataRef& other) const { - return &m_data.get() == &o.m_data.get() || m_data.get() == o.m_data.get(); + return m_data.ptr() == other.m_data.ptr() || m_data.get() == other.m_data.get(); } - - bool operator!=(const DataRef<T>& o) const + + bool operator!=(const DataRef& other) const { - return &m_data.get() != &o.m_data.get() && m_data.get() != o.m_data.get(); + return !(*this == other); } private: @@ -62,5 +92,3 @@ private: }; } // namespace WebCore - -#endif // DataRef_h |