Home C-Bits Package Documentation Project Page

Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

TempLock.h

Go to the documentation of this file.
00001 /* ====================================================================
00002  *              The CBITS Software License, Version 1.0
00003  *
00004  *               Copyright (c) 2002-2003 <contributor>
00005  *                       All rights reserved
00006  *
00007  * Redistribution and use of this software, in source and binary forms, 
00008  * with or without modification, are permitted provided that the above 
00009  * copyright notice, this paragraph, and the following paragraph are 
00010  * retained in each source code file.
00011  *
00012  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
00013  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00014  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00015  * DISCLAIMED.  IN NO EVENT SHALL BRUCE LOWERY OR OTHER CONTRIBUTORS 
00016  * TO THE CBITS LIBRARY BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00017  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00018  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
00019  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00020  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00021  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
00022  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00023  * SUCH DAMAGE.
00024  * ====================================================================
00025  */
00026 #ifndef __TEMPLOCK_H__
00027 #define __TEMPLOCK_H__
00028 
00029 
00030 namespace cbits {
00031 
00060 template< typename Lockable >
00061 class TempLock
00062 {
00063 public:
00069     TempLock
00070     ( 
00072         Lockable* l 
00073     ) 
00074     : _lk(l) { _lk->lock(); }
00075 
00076 
00082     ~TempLock()
00083     {
00084         _lk->unlock();
00085     }
00086 
00087 
00094     operator Lockable*()
00095     {
00096         return _lk;
00097     }
00098 
00099 
00106     operator Lockable&()
00107     {
00108         return *_lk;
00109     }
00110 
00111 
00117     Lockable& get() { return *_lk; }
00118 
00119 
00120 private:
00122     Lockable* _lk;
00123 
00124 };
00125 
00126 };
00127 
00128 #endif
00129 
00130 /*
00131  * $Id: TempLock.h,v 1.2 2002/10/07 21:07:43 brulow Exp $
00132  * 
00133  * History: (Add nothing manually below)
00134  * -----------------------------------------------------------------------
00135  *
00136  * $Log: TempLock.h,v $
00137  * Revision 1.2  2002/10/07 21:07:43  brulow
00138  * Add/improve documentation
00139  *
00140  * Revision 1.1  2002/09/28 00:07:19  brulow
00141  * Add to project
00142  *
00143  *
00144  */

Generated by
doxygen
Hosted by
SourceForge