/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /* * $Id: Janitor.c 568078 2007-08-21 11:43:25Z amassari $ */ // --------------------------------------------------------------------------- // Includes // --------------------------------------------------------------------------- #if defined(XERCES_TMPLSINC) #include #endif XERCES_CPP_NAMESPACE_BEGIN // --------------------------------------------------------------------------- // Janitor: Constructors and Destructor // --------------------------------------------------------------------------- template Janitor::Janitor(T* const toDelete) : fData(toDelete) { } template Janitor::~Janitor() { reset(); } // --------------------------------------------------------------------------- // Janitor: Public, non-virtual methods // --------------------------------------------------------------------------- template void Janitor::orphan() { release(); } template T& Janitor::operator*() const { return *fData; } template T* Janitor::operator->() const { return fData; } template T* Janitor::get() const { return fData; } template T* Janitor::release() { T* p = fData; fData = 0; return p; } template void Janitor::reset(T* p) { if (fData) delete fData; fData = p; } template bool Janitor::isDataNull() { return (fData == 0); } // ----------------------------------------------------------------------- // ArrayJanitor: Constructors and Destructor // ----------------------------------------------------------------------- template ArrayJanitor::ArrayJanitor(T* const toDelete) : fData(toDelete) , fMemoryManager(0) { } template ArrayJanitor::ArrayJanitor(T* const toDelete, MemoryManager* const manager) : fData(toDelete) , fMemoryManager(manager) { } template ArrayJanitor::~ArrayJanitor() { reset(); } // ----------------------------------------------------------------------- // ArrayJanitor: Public, non-virtual methods // ----------------------------------------------------------------------- template void ArrayJanitor::orphan() { release(); } // Look, Ma! No hands! Don't call this with null data! template T& ArrayJanitor::operator[](int index) const { // TODO: Add appropriate exception return fData[index]; } template T* ArrayJanitor::get() const { return fData; } template T* ArrayJanitor::release() { T* p = fData; fData = 0; return p; } template void ArrayJanitor::reset(T* p) { if (fData) { if (fMemoryManager) fMemoryManager->deallocate((void*)fData); else delete [] fData; } fData = p; fMemoryManager = 0; } template void ArrayJanitor::reset(T* p, MemoryManager* const manager) { if (fData) { if (fMemoryManager) fMemoryManager->deallocate((void*)fData); else delete [] fData; } fData = p; fMemoryManager = manager; } template JanitorMemFunCall::JanitorMemFunCall( T* object, MFPT toCall) : fObject(object), fToCall(toCall) { } template JanitorMemFunCall::~JanitorMemFunCall() { if (fObject != 0 && fToCall != 0) { (fObject->*fToCall)(); } } // --------------------------------------------------------------------------- // Janitor: Public, non-virtual methods // --------------------------------------------------------------------------- template void JanitorMemFunCall::release() { fObject = 0; fToCall = 0; } XERCES_CPP_NAMESPACE_END