|
reSIProcate/DialogUsageManager
9694
|
00001 #if !defined(RESIP_REFCOUNTEDDESTROYER_HXX) 00002 #define RESIP_REFCOUNTEDDESTROYER_HXX 00003 00004 namespace resip 00005 { 00006 00007 //designed to be used by composition, does not destroy itself. 00008 template<class T> 00009 class RefCountedDestroyer 00010 { 00011 public: 00012 class Guard 00013 { 00014 public: 00015 void destroy() 00016 { 00017 mRefCountedDestroyer.mDestroying = true; 00018 } 00019 00020 bool destroyed() 00021 { 00022 return mRefCountedDestroyer.mDestroying; 00023 } 00024 00025 Guard(RefCountedDestroyer& rcd) 00026 : mRefCountedDestroyer(rcd) 00027 { 00028 mRefCountedDestroyer.mCount++; 00029 } 00030 00031 ~Guard() 00032 { 00033 mRefCountedDestroyer.mCount--; 00034 if (mRefCountedDestroyer.mDestroying && mRefCountedDestroyer.mCount == 0) 00035 { 00036 delete mRefCountedDestroyer.mTarget; 00037 } 00038 } 00039 private: 00040 RefCountedDestroyer& mRefCountedDestroyer; 00041 }; 00042 00043 RefCountedDestroyer(T* target) : 00044 mTarget(target), 00045 mCount(0), 00046 mDestroying(false) 00047 { 00048 } 00049 private: 00050 friend class Guard; 00051 T* mTarget; 00052 int mCount; 00053 bool mDestroying; 00054 }; 00055 00056 } 00057 00058 #endif 00059 00060 /* ==================================================================== 00061 * The Vovida Software License, Version 1.0 00062 * 00063 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved. 00064 * 00065 * Redistribution and use in source and binary forms, with or without 00066 * modification, are permitted provided that the following conditions 00067 * are met: 00068 * 00069 * 1. Redistributions of source code must retain the above copyright 00070 * notice, this list of conditions and the following disclaimer. 00071 * 00072 * 2. Redistributions in binary form must reproduce the above copyright 00073 * notice, this list of conditions and the following disclaimer in 00074 * the documentation and/or other materials provided with the 00075 * distribution. 00076 * 00077 * 3. The names "VOCAL", "Vovida Open Communication Application Library", 00078 * and "Vovida Open Communication Application Library (VOCAL)" must 00079 * not be used to endorse or promote products derived from this 00080 * software without prior written permission. For written 00081 * permission, please contact vocal@vovida.org. 00082 * 00083 * 4. Products derived from this software may not be called "VOCAL", nor 00084 * may "VOCAL" appear in their name, without prior written 00085 * permission of Vovida Networks, Inc. 00086 * 00087 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED 00088 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00089 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND 00090 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA 00091 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES 00092 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL, 00093 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00094 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00095 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 00096 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00097 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 00098 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 00099 * DAMAGE. 00100 * 00101 * ==================================================================== 00102 * 00103 * This software consists of voluntary contributions made by Vovida 00104 * Networks, Inc. and many individuals on behalf of Vovida Networks, 00105 * Inc. For more information on Vovida Networks, Inc., please see 00106 * <http://www.vovida.org/>. 00107 * 00108 */
1.7.5.1