guard.h

Go to the documentation of this file.
00001 // OSB library ********************************************* -*- C++ -*-
00012 /*
00013   AUTHOR(S): Stephan Broennimann (vb)
00014 
00015   RCS information
00016    $Name: OSB_060808 $
00017    $Revision: 1.13 $
00018 
00019   License
00020    OSB rating and billing library for communication networks
00021    Copyright (C) 2004, 2005, 2006  OSB systems
00022 
00023    This file may be distributed and/or modify under the terms of the
00024    GNU General Public License (GPL) as published by the Free Software
00025    Foundation which is provided in the file LICENSE.GPL included in the
00026    packaging of this file.
00027 
00028    The file is distributed in the hope that it will be useful, but WITHOUT
00029    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00030    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00031    for more details.
00032 
00033    Holders of a OSB Commercial License may use this file under the terms
00034    and conditions of this commercial license.
00035  */
00036 #ifndef _GUARD_H_
00037 #define _GUARD_H_
00038 
00039 // *********************************************************************
00040 // included header files
00041 // + standard includes
00042 #include <memory>
00043 #include <utility>
00044 
00045 // + local headers
00046 
00047 // *********************************************************************
00048 // namespace extensions
00049 namespace OSB_LIB {
00050 
00051 // *********************************************************************
00052 // class definitions
00053 
00054     // *****************************************************************
00055     // class Guard
00105     class Guard {
00106     private:
00112         struct GuardRef {
00114             Guard& s;
00116             GuardRef(Guard& r) : s(r) {}
00117         };
00118 
00119     public:
00132         class Cleanup {
00133         public:
00138             typedef std::auto_ptr<Guard::Cleanup> AutoPtr;
00139 
00147             virtual ~Cleanup();
00157             virtual int cleanup() = 0;
00158         };
00159 
00176         Guard(
00177             Cleanup* pCleanup = 0,
00178             bool     doClean  = true
00179         );
00180 
00194         Guard(
00195             Cleanup::AutoPtr cleanup,
00196             bool             doClean
00197         );
00198 
00205         ~Guard();
00206 
00213         Guard(Guard& rhs);
00214 
00223         Guard& operator=(Guard rhs);
00224 
00237         Guard(GuardRef r);
00238 
00242         operator GuardRef();
00244 
00246         bool isLoaded() const  { return doClean_; }
00247 
00264         std::pair<bool, int> cleanup();
00265 
00277         bool release();
00278     private:
00280         bool     doClean_;
00282         Cleanup* pCleanup_;
00284         bool     delCleanup_;
00285     };                                  // class Guard
00286 }                                       // namespace OSB_LIB
00287 #endif                                  // #ifndef _GUARD_H_

Generated on Sat Sep 2 14:06:32 2006 for OSB Library by  doxygen 1.4.7