00001 00002 // MathCore = a WYSIWYG equation editor + a powerful math engine // 00003 // Copyright (C) 2003 by Francesco Montorsi // 00004 // // 00005 // This library is free software; you can redistribute it and/or // 00006 // modify it under the terms of the GNU Lesser General Public // 00007 // License as published by the Free Software Foundation; either // 00008 // version 2.1 of the License, or (at your option) any later // 00009 // version. // 00010 // // 00011 // This library is distributed in the hope that it will be useful, // 00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of // 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // 00014 // GNU Lesser General Public License for more details. // 00015 // // 00016 // You should have received a copy of the GNU Lesser General Public // 00017 // License along with this program; if not, write to the Free // 00018 // Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, // 00019 // MA 02111-1307, USA. // 00020 // // 00021 // For any comment, suggestion or feature request, please contact // 00022 // the administrator of the project at frm@users.sourceforge.net // 00023 // // 00030 00031 00032 // optimization for GCC compiler 00033 #ifdef __GNUG__ 00034 #pragma implementation "Object.h" 00035 #endif 00036 00037 // includes 00038 #include "mc/mcprec.h" 00039 #ifdef __BORLANDC__ 00040 #pragma hdrstop 00041 #endif 00042 00043 #ifndef mcPRECOMP 00044 #include "mc/Object.h" 00045 #include "mc/MathHelpers.h" 00046 #endif 00047 00048 00049 00050 00051 // ---------------------------------------------------------------------------- 00052 // mcOBJECT 00053 // ---------------------------------------------------------------------------- 00054 00055 void mcObject::data_Ref(const mcObject& clone) 00056 { 00057 // nothing to be done 00058 if (mdata_refData == clone.mdata_refData) 00059 return; 00060 00061 // delete reference to old data 00062 data_UnRef(); 00063 00064 // reference new data 00065 if ( clone.mdata_refData ) 00066 { 00067 mdata_refData = clone.mdata_refData; 00068 mdata_refData->data_IncRefCount(); 00069 00070 #ifndef mcENABLE_COW 00071 data_MakePrivateCopy(); // no sharing allowed 00072 #endif 00073 } 00074 } 00075 00076 void mcObject::data_UnRef() 00077 { 00078 if ( mdata_refData ) 00079 { 00080 wxASSERT_MSG( mdata_refData->data_GetRefCount() > 0, 00081 _T("invalid ref data count") ); 00082 00083 mdata_refData->data_DecRefCount(); 00084 if ( mdata_refData->data_GetRefCount() == 0 ) { 00085 00086 #ifdef mcENABLE_COW_DEEPDEBUG 00087 // since this code is repeated a LOT of times, 00088 // generally, it is better not to output log messages here... 00089 mcLOG("mcObject::UnRef - deleting shared data"); 00090 #endif 00091 delete mdata_refData; 00092 } 00093 00094 // reset to NULL 00095 mdata_refData = NULL; 00096 } 00097 } 00098 00099
[ Top ] |