1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19 // Class heaer file... 20 #include "XalanReferenceCountedObject.hpp" 21 22 23 24 #include <cassert> 25 26 #if !defined(NDEBUG) 27 #include <climits> 28 #endif 29 30 31 32 namespace XALAN_CPP_NAMESPACE { 33 34 35 XalanReferenceCountedObject()36XalanReferenceCountedObject::XalanReferenceCountedObject() : 37 m_referenceCount(0) 38 { 39 } 40 41 42 ~XalanReferenceCountedObject()43XalanReferenceCountedObject::~XalanReferenceCountedObject() 44 { 45 assert(m_referenceCount == 0); 46 } 47 48 49 50 void addReference(XalanReferenceCountedObject * theInstance)51XalanReferenceCountedObject::addReference(XalanReferenceCountedObject* theInstance) 52 { 53 if (theInstance != 0) 54 { 55 assert(theInstance->m_referenceCount < UINT_MAX); 56 57 if (++theInstance->m_referenceCount == 1) 58 { 59 theInstance->referenced(); 60 } 61 } 62 } 63 64 65 66 void removeReference(XalanReferenceCountedObject * theInstance)67XalanReferenceCountedObject::removeReference(XalanReferenceCountedObject* theInstance) 68 { 69 if (theInstance != 0) 70 { 71 assert(theInstance->m_referenceCount > 0); 72 73 if (--theInstance->m_referenceCount == 0) 74 { 75 theInstance->dereferenced(); 76 } 77 } 78 } 79 80 81 82 } 83