From: <sv...@ww...> - 2004-06-04 07:58:08
|
Author: mkrose Date: 2004-06-04 00:57:22 -0700 (Fri, 04 Jun 2004) New Revision: 989 Added: trunk/CSP/SimData/Include/SimData/Properties.h Modified: trunk/CSP/SimData/Include/SimData/Link.h trunk/CSP/SimData/Include/SimData/Path.h trunk/CSP/SimData/Include/SimData/Ref.h trunk/CSP/SimData/Source/SConscript trunk/CSP/SimData/setup.py Log: Small cleanups for reference counting classes (more to come). Modified: trunk/CSP/SimData/Include/SimData/Link.h =================================================================== --- trunk/CSP/SimData/Include/SimData/Link.h 2004-06-04 07:54:54 UTC (rev 988) +++ trunk/CSP/SimData/Include/SimData/Link.h 2004-06-04 07:57:22 UTC (rev 989) @@ -155,7 +155,7 @@ inline void _assign_safe(Object* ptr) { _release(); _update(ptr); - if (!isNull()) _reference->_ref(); + if (!isNull()) _reference->_incref(); } /** Rebind to a new object, without testing for type compatibility. @@ -166,14 +166,14 @@ inline void _assign_fast(Object *ptr) { _release(); _reference = ptr; - if (!isNull()) _reference->_ref(); + if (!isNull()) _reference->_incref(); } /** Rebind to null. */ inline void _release() { if (!isNull()) { - _reference->_deref(); + _reference->_decref(); _reference = 0; } } Modified: trunk/CSP/SimData/Include/SimData/Path.h =================================================================== --- trunk/CSP/SimData/Include/SimData/Path.h 2004-06-04 07:54:54 UTC (rev 988) +++ trunk/CSP/SimData/Include/SimData/Path.h 2004-06-04 07:57:22 UTC (rev 989) @@ -275,7 +275,7 @@ inline void _assign_safe(Object* ptr) { _release(); _update(ptr); - if (!isNull()) _reference->_ref(); + if (!isNull()) _reference->_incref(); } /** @@ -287,7 +287,7 @@ inline void _assign_fast(Object *ptr) { _release(); _reference = ptr; - if (!isNull()) _reference->_ref(); + if (!isNull()) _reference->_incref(); } /** @@ -295,7 +295,7 @@ */ inline void _release() { if (!isNull()) { - _reference->_deref(); + _reference->_decref(); _reference = 0; } } Added: trunk/CSP/SimData/Include/SimData/Properties.h =================================================================== --- trunk/CSP/SimData/Include/SimData/Properties.h 2004-06-04 07:54:54 UTC (rev 988) +++ trunk/CSP/SimData/Include/SimData/Properties.h 2004-06-04 07:57:22 UTC (rev 989) @@ -0,0 +1,65 @@ +/* SimData: Data Infrastructure for Simulations + * Copyright (C) 2002-2004 Mark Rose <mk...@us...> + * + * This file is part of SimData. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + + +/** + * @file Properties.h + * + * Inheritable class properties. + */ + + +#ifndef __SIMDATA_PROPERTIES_H__ +#define __SIMDATA_PROPERTIES_H__ + +#include <SimData/Namespace.h> +#include <SimData/Export.h> + + +NAMESPACE_SIMDATA + + +/** Inheritable property for classes that cannot be copied. + * + * @author Mark Rose <mk...@us...> + */ +class NonCopyable { +protected: + NonCopyable() { } +private: + NonCopyable(NonCopyable const &); + void operator = (NonCopyable const &); +}; + + +/** Inheritable property for classes that cannot be (publicly) constructed. + * + * @author Mark Rose <mk...@us...> + */ +class NonConstructable: public NonCopyable { +private: + NonConstructable(); +}; + +NAMESPACE_SIMDATA_END + + +#endif //__SIMDATA_OBJECT_H__ + Modified: trunk/CSP/SimData/Include/SimData/Ref.h =================================================================== --- trunk/CSP/SimData/Include/SimData/Ref.h 2004-06-04 07:54:54 UTC (rev 988) +++ trunk/CSP/SimData/Include/SimData/Ref.h 2004-06-04 07:57:22 UTC (rev 989) @@ -37,6 +37,7 @@ #include <SimData/Export.h> #include <SimData/ExceptionBase.h> #include <SimData/Log.h> +#include <SimData/Properties.h> NAMESPACE_SIMDATA @@ -82,7 +83,7 @@ /** Create a new reference. */ Ref(T* ptr): _reference(ptr) { - if (ptr) ptr->_ref(); + if (ptr) ptr->_incref(); } /** Light-weight copy with reference counting. @@ -97,7 +98,7 @@ Ref(Ref<Q> const & r): _reference(0) { Q *rp = r.get(); if (rp != 0) { - //rp->_ref(); + //rp->_incref(); //_reference = static_cast<T*>(rp); _rebind(rp); } @@ -106,14 +107,14 @@ /** Light-weight copy with reference counting. */ Ref(Ref const & r): _reference(r._reference) { - if (_reference != 0) _reference->_ref(); + if (_reference != 0) _reference->_incref(); } /** Decrement the reference count, and potentially destroy * the referenced object. */ ~Ref() { - if (_reference) _reference->_deref(); + if (_reference) _reference->_decref(); } /** Returns true if this is the only reference. @@ -167,7 +168,7 @@ */ inline void *operator=(void *ptr) { assert(ptr==0); - if (_reference != 0) _reference->_deref(); + if (_reference != 0) _reference->_decref(); _reference = 0; return ptr; } @@ -238,8 +239,8 @@ */ template <class Q> void _rebind(Q* ptr) { - if (ptr) ptr->_ref(); - if (_reference != 0) _reference->_deref(); + if (ptr) ptr->_incref(); + if (_reference != 0) _reference->_decref(); _reference = dynamic_cast<T*>(ptr); if (_reference == 0 && ptr != 0) { SIMDATA_LOG(LOG_ALL, LOG_ERROR, "simdata::Ref() assignment: incompatible types (dynamic cast failed)."); @@ -259,19 +260,18 @@ * * @author Mark Rose <mr...@st...> */ -class SIMDATA_EXPORT Referenced { +class SIMDATA_EXPORT Referenced: public NonCopyable { template <class T> friend class Ref; friend class ReferencePointer; -public: +protected: Referenced(): __count(0) {} -protected: /** @todo This dtor should be eliminated eventually, or at * least made non-virtual if we can be sure that Referenced - * derived objects will never be deleted via a Referenced*. - * Since Referenced::_deref() currently handles deletion, + * derived objects will never be deleted via a Referenced*. + * Since Referenced::_decref() currently handles deletion, * this would require moving the deletion responsibility to * Ref<>, and declaring a Ref<Referenced> specialization for * preventation. --MR @@ -283,23 +283,14 @@ } private: - inline void _ref() const { ++__count; } - - inline void _deref() const { + inline void _incref() const { ++__count; } + inline void _decref() const { if (--__count <= 0) { delete this; } } inline unsigned _count() const { return __count; } - mutable unsigned __count; - - Referenced(Referenced const &); //: __count(0) {} - -#ifndef SWIG - inline Referenced& operator=(Referenced const &);// { return *this; } -#endif // SWIG - }; Modified: trunk/CSP/SimData/Source/SConscript =================================================================== --- trunk/CSP/SimData/Source/SConscript 2004-06-04 07:54:54 UTC (rev 988) +++ trunk/CSP/SimData/Source/SConscript 2004-06-04 07:57:22 UTC (rev 989) @@ -61,6 +61,7 @@ osg.h Path.h PTS.h + Properties.h Quat.h Random.h Real.h Modified: trunk/CSP/SimData/setup.py =================================================================== --- trunk/CSP/SimData/setup.py 2004-06-04 07:54:54 UTC (rev 988) +++ trunk/CSP/SimData/setup.py 2004-06-04 07:57:22 UTC (rev 989) @@ -313,6 +313,7 @@ "osg.h", "Path.h", "PTS.h", + "Properties.h", "Quat.h", "Random.h", "Real.h", |