User Manual, Developers Guide and API Documentation

SmartPtrBase.hpp

Go to the documentation of this file.
00001 /*******************************************************************************
00002  * This file is part of openWNS (open Wireless Network Simulator)
00003  * _____________________________________________________________________________
00004  *
00005  * Copyright (C) 2004-2007
00006  * Chair of Communication Networks (ComNets)
00007  * Kopernikusstr. 16, D-52074 Aachen, Germany
00008  * phone: ++49-241-80-27910,
00009  * fax: ++49-241-80-22242
00010  * email: info@openwns.org
00011  * www: http://www.openwns.org
00012  * _____________________________________________________________________________
00013  *
00014  * openWNS is free software; you can redistribute it and/or modify it under the
00015  * terms of the GNU Lesser General Public License version 2 as published by the
00016  * Free Software Foundation;
00017  *
00018  * openWNS is distributed in the hope that it will be useful, but WITHOUT ANY
00019  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
00020  * A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
00021  * details.
00022  *
00023  * You should have received a copy of the GNU Lesser General Public License
00024  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00025  *
00026  ******************************************************************************/
00027 
00028 #ifndef WNS_SMARTPTRBASE_HPP
00029 #define WNS_SMARTPTRBASE_HPP
00030 
00031 #include <WNS/TypeInfo.hpp>
00032 #include <WNS/Backtrace.hpp>
00033 
00034 #include <list>
00035 #include <stdint.h>
00036 #include <iostream>
00037 
00038 namespace wns {
00053     class SmartPtrBase
00054     {
00055         typedef std::list<SmartPtrBase*> SmartPtrBaseContainer;
00056     public:
00060         typedef long long int Id;
00061 
00065         SmartPtrBase() :
00066             globalId(++SmartPtrBase::getCounter())
00067         {
00068             SmartPtrBase::getAllPointers().push_back(this);
00069                         wns::Backtrace bt;
00070                         bt.snapshot();
00071                         this->backtrace = bt.toString();
00072         }
00073 
00077         virtual
00078         ~SmartPtrBase()
00079         {
00080             SmartPtrBase::getAllPointers().remove(this);
00081         }
00082 
00091         static void
00092         printAllExistingPointers()
00093         {
00094             std::cout << "Currently existing SmartPtrs:" << "\n";
00095             for(SmartPtrBaseContainer::const_iterator itr = SmartPtrBase::getAllPointers().begin();
00096                 itr != SmartPtrBase::getAllPointers().end();
00097                 ++itr) {
00098                 std::cout << "Pointer type: " << (*itr)->getTypeInfo()
00099                       << " id: " << (*itr)->getId()
00100                       << " global id: " << (*itr)->globalId << "\n"
00101                                           << (*itr)->getBacktrace() << std::endl;
00102             }
00103         }
00104 
00105                 std::string
00106                 getBacktrace()
00107                 {
00108                     return this->backtrace;
00109                 }
00110     private:
00114         virtual wns::TypeInfo
00115         getTypeInfo() const = 0;
00116 
00121         virtual Id
00122         getId() const = 0;
00123 
00127         static Id&
00128         getCounter()
00129         {
00130             static Id counter = 0;
00131             return counter;
00132         }
00133 
00137         static SmartPtrBaseContainer&
00138         getAllPointers()
00139         {
00140             static SmartPtrBaseContainer allPointers;
00141             return allPointers;
00142         }
00143 
00147         Id globalId;
00148 
00152                 std::string backtrace;
00153     };
00154 } // wns
00155 
00156 #endif // NOT defined WNS_SMARTPTRBASE_HPP
00157 
00158 

Generated on Fri May 25 03:31:56 2012 for openWNS by  doxygen 1.5.5