Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

base/Singleton.cpp

Go to the documentation of this file.
00001 /****************************************************************************
00002   Copyright (C)2001 by Andrei Alexandrescu
00003 
00004   This file is a derivative of a file from the Loki Library written by
00005   Andrei Alexandrescu.  It was distributed by him under the terms
00006   listed below (titled Loki Original Distribution Terms).
00007   In accordance with the terms, this distribution contains the copyright
00008   notice here and the copyright notice and permission notice
00009   in supporting documentation.  The terms do *not* require
00010   redistribution under those same terms.  This code is distributed
00011   to you under the terms of the GNU General Public License (GPL) 
00012   below.  The GPL does not require you to maintain the terms of
00013   the Loki Original Distribution Terms, but you are encouraged to do so.
00014 
00015   This program/file is free software; you can redistribute it and/or modify
00016   it under the terms of the GNU General Public License as published by
00017   the Free Software Foundation; either version 2 of the License, or
00018   (at your option) any later version.
00019   
00020   This program is distributed in the hope that it will be useful,
00021   but WITHOUT ANY WARRANTY; without even the implied warranty of
00022   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023   GNU General Public License for more details. (http://www.gnu.org)
00024   
00025   You should have received a copy of the GNU General Public License
00026   along with this program; if not, write to the Free Software
00027   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00028   
00029  ****************************************************************************
00030   Loki Original Distribution Terms:
00031 
00032   The Loki Library
00033   Copyright (c) 2001 by Andrei Alexandrescu
00034   This code accompanies the book:
00035   Alexandrescu, Andrei. "Modern C++ Design: Generic Programming and Design 
00036       Patterns Applied". Copyright (c) 2001. Addison-Wesley.
00037   Permission to use, copy, modify, distribute and sell this software for any 
00038       purpose is hereby granted without fee, provided that the above copyright 
00039       notice appear in all copies and that both that copyright notice and this 
00040       permission notice appear in supporting documentation.
00041   The author or Addison-Welsey Longman make no representations about the 
00042       suitability of this software for any purpose. It is provided "as is" 
00043       without express or implied warranty.
00044  ****************************************************************************
00045 
00046   $Id: Singleton.cpp 1029 2004-02-11 20:45:54Z jungd $
00047   $Revision: 1.1 $
00048   $Date: 2004-02-11 15:45:54 -0500 (Wed, 11 Feb 2004) $
00049   $Author: jungd $
00050  
00051 ****************************************************************************/
00052 
00053 // Last update: June 20, 2001
00054 
00055 #include <base/Singleton>
00056 
00057 using namespace base::Private;
00058 
00059 base::Private::TrackerArray base::Private::pTrackerArray = 0;
00060 unsigned int base::Private::elements = 0;
00061 
00062 ////////////////////////////////////////////////////////////////////////////////
00063 // function AtExitFn
00064 // Ensures proper destruction of objects with longevity
00065 ////////////////////////////////////////////////////////////////////////////////
00066 
00067 void base::Private::AtExitFn()
00068 {
00069     assert(elements > 0 && pTrackerArray != 0);
00070     // Pick the element at the top of the stack
00071     LifetimeTracker* pTop = pTrackerArray[elements - 1];
00072     // Remove that object off the stack
00073     // Don't check errors - realloc with less memory 
00074     //     can't fail
00075     pTrackerArray = static_cast<TrackerArray>(std::realloc(
00076         pTrackerArray, --elements));
00077     // Destroy the element
00078     delete pTop;
00079 }
00080 
00081 ////////////////////////////////////////////////////////////////////////////////
00082 // Change log:
00083 // June 20, 2001: ported by Nick Thurn to gcc 2.95.3. Kudos, Nick!!!
00084 // Feb 25, 2002: David Jung: integrated into larger project - changed to 
00085 //                namespace base and changed header comments to reflect GPL
00086 //                distribution
00087 ////////////////////////////////////////////////////////////////////////////////

Generated on Thu Jul 29 15:56:14 2004 for OpenSim by doxygen 1.3.6