secureswitools/swisistools/source/xmlparser/xerces/include/xercesc/util/Janitor.hpp
changeset 0 ba25891c3a9e
child 1 c42dffbd5b4f
equal deleted inserted replaced
-1:000000000000 0:ba25891c3a9e
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 /*
       
    18  * Licensed to the Apache Software Foundation (ASF) under one or more
       
    19  * contributor license agreements.  See the NOTICE file distributed with
       
    20  * this work for additional information regarding copyright ownership.
       
    21  * The ASF licenses this file to You under the Apache License, Version 2.0
       
    22  * (the "License"); you may not use this file except in compliance with
       
    23  * the License.  You may obtain a copy of the License at
       
    24  * 
       
    25  *      http://www.apache.org/licenses/LICENSE-2.0
       
    26  * 
       
    27  * Unless required by applicable law or agreed to in writing, software
       
    28  * distributed under the License is distributed on an "AS IS" BASIS,
       
    29  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
       
    30  * See the License for the specific language governing permissions and
       
    31  * limitations under the License.
       
    32  */
       
    33 
       
    34 /*
       
    35  * $Id: Janitor.hpp 568078 2007-08-21 11:43:25Z amassari $
       
    36  */
       
    37 
       
    38 
       
    39 #if !defined(JANITOR_HPP)
       
    40 #define JANITOR_HPP
       
    41 
       
    42 #include <xercesc/util/XMemory.hpp>
       
    43 #include <xercesc/framework/MemoryManager.hpp>
       
    44 
       
    45 XERCES_CPP_NAMESPACE_BEGIN
       
    46 
       
    47 template <class T> class Janitor : public XMemory
       
    48 {
       
    49 public  :
       
    50     // -----------------------------------------------------------------------
       
    51     //  Constructors and Destructor
       
    52     // -----------------------------------------------------------------------
       
    53     Janitor(T* const toDelete);
       
    54     ~Janitor();
       
    55 
       
    56     // -----------------------------------------------------------------------
       
    57     //  Public, non-virtual methods
       
    58     // -----------------------------------------------------------------------
       
    59     void orphan();
       
    60 
       
    61     //  small amount of auto_ptr compatibility
       
    62     T& operator*() const;
       
    63     T* operator->() const;
       
    64     T* get() const;
       
    65     T* release();
       
    66     void reset(T* p = 0);
       
    67     bool isDataNull();
       
    68 
       
    69 private :
       
    70     // -----------------------------------------------------------------------
       
    71     //  Unimplemented constructors and operators
       
    72     // -----------------------------------------------------------------------
       
    73     Janitor();
       
    74     Janitor(const Janitor<T>&);
       
    75     Janitor<T>& operator=(const Janitor<T>&);
       
    76 
       
    77     // -----------------------------------------------------------------------
       
    78     //  Private data members
       
    79     //
       
    80     //  fData
       
    81     //      This is the pointer to the object or structure that must be
       
    82     //      destroyed when this object is destroyed.
       
    83     // -----------------------------------------------------------------------
       
    84     T*  fData;
       
    85 };
       
    86 
       
    87 
       
    88 
       
    89 template <class T> class ArrayJanitor : public XMemory
       
    90 {
       
    91 public  :
       
    92     // -----------------------------------------------------------------------
       
    93     //  Constructors and Destructor
       
    94     // -----------------------------------------------------------------------
       
    95     ArrayJanitor(T* const toDelete);
       
    96     ArrayJanitor(T* const toDelete, MemoryManager* const manager);
       
    97     ~ArrayJanitor();
       
    98 
       
    99 
       
   100     // -----------------------------------------------------------------------
       
   101     //  Public, non-virtual methods
       
   102     // -----------------------------------------------------------------------
       
   103     void orphan();
       
   104 
       
   105 	//	small amount of auto_ptr compatibility
       
   106 	T&	operator[](int index) const;
       
   107 	T*	get() const;
       
   108 	T*	release();
       
   109 	void reset(T* p = 0);
       
   110 	void reset(T* p, MemoryManager* const manager);
       
   111 
       
   112 private :
       
   113     // -----------------------------------------------------------------------
       
   114     //  Unimplemented constructors and operators
       
   115     // -----------------------------------------------------------------------
       
   116 	ArrayJanitor();
       
   117     ArrayJanitor(const ArrayJanitor<T>& copy);
       
   118     ArrayJanitor<T>& operator=(const ArrayJanitor<T>& copy);    
       
   119 
       
   120     // -----------------------------------------------------------------------
       
   121     //  Private data members
       
   122     //
       
   123     //  fData
       
   124     //      This is the pointer to the object or structure that must be
       
   125     //      destroyed when this object is destroyed.
       
   126     // -----------------------------------------------------------------------
       
   127     T*  fData;
       
   128     MemoryManager* fMemoryManager;
       
   129 };
       
   130 
       
   131 
       
   132 
       
   133 template <class T> class JanitorMemFunCall
       
   134 {
       
   135 public  :
       
   136 
       
   137     typedef void (T::*MFPT) ();
       
   138 
       
   139     // -----------------------------------------------------------------------
       
   140     //  Constructors and Destructor
       
   141     // -----------------------------------------------------------------------
       
   142     JanitorMemFunCall(
       
   143         T*      object,
       
   144         MFPT    toCall);
       
   145 
       
   146     ~JanitorMemFunCall();
       
   147 
       
   148     // -----------------------------------------------------------------------
       
   149     //  Public, non-virtual methods
       
   150     // -----------------------------------------------------------------------
       
   151 	void release();
       
   152 
       
   153 private :
       
   154     // -----------------------------------------------------------------------
       
   155     //  Unimplemented constructors and operators
       
   156     // -----------------------------------------------------------------------
       
   157     JanitorMemFunCall();
       
   158     JanitorMemFunCall(const JanitorMemFunCall<T>&);
       
   159     JanitorMemFunCall<T>& operator=(const JanitorMemFunCall<T>&);
       
   160 
       
   161     // -----------------------------------------------------------------------
       
   162     //  Private data members
       
   163     //
       
   164     //  fObject
       
   165     //      This is the pointer to the object for which we will call the
       
   166     //      member function when this object is destroyed.
       
   167     // -----------------------------------------------------------------------
       
   168     T*      fObject;
       
   169     MFPT    fToCall;
       
   170 };
       
   171 
       
   172 
       
   173 
       
   174 
       
   175 XERCES_CPP_NAMESPACE_END
       
   176 
       
   177 #if !defined(XERCES_TMPLSINC)
       
   178 #include <xercesc/util/Janitor.c>
       
   179 #endif
       
   180 
       
   181 #endif