/* Copyright (C) 2008 Nikolas Zimmermann This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef SynchronizableTypeWrapper_h #define SynchronizableTypeWrapper_h #if ENABLE(SVG) #include namespace WebCore { template class SynchronizableTypeWrapperBase : public Noncopyable { protected: SynchronizableTypeWrapperBase(); template void assign(AssignableType type); bool needsSynchronization() const; void setSynchronized(); protected: StoredType m_value; bool m_needsSynchronization; }; template class SynchronizableTypeWrapper : private SynchronizableTypeWrapperBase { public: typedef SynchronizableTypeWrapperBase Base; SynchronizableTypeWrapper(); // "Forwarding constructors" for primitive type assignment with more than one argument, for exampe SVGLength template SynchronizableTypeWrapper(const T1&); template SynchronizableTypeWrapper(const T1&, const T2&); template SynchronizableTypeWrapper(const T1&, const T2&, const T3&); SynchronizableTypeWrapper& operator=(const StoredType&); operator StoredType() const; using Base::needsSynchronization; using Base::setSynchronized; private: using Base::m_value; }; template class SynchronizableTypeWrapper > : private SynchronizableTypeWrapperBase > { public: typedef SynchronizableTypeWrapperBase > Base; SynchronizableTypeWrapper(); SynchronizableTypeWrapper(const PassRefPtr&); SynchronizableTypeWrapper& operator=(StoredPointerType*); operator StoredPointerType*() const; using Base::needsSynchronization; using Base::setSynchronized; private: using Base::m_value; }; // SynchronizableTypeWrapperBase implementation template inline SynchronizableTypeWrapperBase::SynchronizableTypeWrapperBase() : m_value() , m_needsSynchronization(false) { } template template inline void SynchronizableTypeWrapperBase::assign(AssignableType type) { m_value = type; m_needsSynchronization = true; } template inline bool SynchronizableTypeWrapperBase::needsSynchronization() const { return m_needsSynchronization; } template inline void SynchronizableTypeWrapperBase::setSynchronized() { m_needsSynchronization = false; } // SynchronizableTypeWrapper implementation for primitive types template inline SynchronizableTypeWrapper::SynchronizableTypeWrapper() : Base() { } template template inline SynchronizableTypeWrapper::SynchronizableTypeWrapper(const T1& arg1) : Base() { m_value = StoredType(arg1); } template template inline SynchronizableTypeWrapper::SynchronizableTypeWrapper(const T1& arg1, const T2& arg2) : Base() { m_value = StoredType(arg1, arg2); } template template inline SynchronizableTypeWrapper::SynchronizableTypeWrapper(const T1& arg1, const T2& arg2, const T3& arg3) : Base() { m_value = StoredType(arg1, arg2, arg3); } template inline SynchronizableTypeWrapper& SynchronizableTypeWrapper::operator=(const StoredType& other) { Base::assign(other); return (*this); } template inline SynchronizableTypeWrapper::operator StoredType() const { return m_value; } // SynchronizableTypeWrapper implementation for refcounted types template inline SynchronizableTypeWrapper >::SynchronizableTypeWrapper() : Base() { } template inline SynchronizableTypeWrapper >::SynchronizableTypeWrapper(const PassRefPtr& type) : Base() { Base::m_value = type; } template inline SynchronizableTypeWrapper >& SynchronizableTypeWrapper >::operator=(StoredPointerType* other) { Base::assign(other); return (*this); } template inline SynchronizableTypeWrapper >::operator StoredPointerType*() const { return Base::m_value.get(); } }; #endif #endif