• Main Page
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List

SharedPtr.hpp

00001 /* A Reference Counting Smart Pointer.
00002  * Copyright (C) 2007-2009 David Robillard <http://drobilla.net>
00003  *
00004  * This is free software; you can redistribute it and/or modify it under the
00005  * terms of the GNU General Public License as published by the Free Software
00006  * Foundation; either version 2 of the License, or (at your option) any later
00007  * version.
00008  *
00009  * This file is distributed in the hope that it will be useful, but WITHOUT ANY
00010  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00011  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for details.
00012  *
00013  * You should have received a copy of the GNU General Public License along
00014  * with this program; if not, write to the Free Software Foundation, Inc.,
00015  * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00016  */
00017 
00018 #ifndef RAUL_SHARED_PTR_HPP
00019 #define RAUL_SHARED_PTR_HPP
00020 
00021 #include <cassert>
00022 #include <cstddef>
00023 
00024 #ifdef BOOST_SP_ENABLE_DEBUG_HOOKS
00025 #include <iostream>
00026 #include <list>
00027 #include <algorithm>
00028 
00029 static std::list<void*> shared_ptr_counters;
00030 
00031 // Use debug hooks to ensure 2 shared_ptrs never point to the same thing
00032 namespace boost {
00033 
00034     inline void sp_scalar_constructor_hook(void* object, unsigned long cnt, void* ptr) {
00035         assert(std::find(shared_ptr_counters.begin(), shared_ptr_counters.end(),
00036                 (void*)object) == shared_ptr_counters.end());
00037         shared_ptr_counters.push_back(object);
00038         //std::cerr << "Creating SharedPtr to "
00039         //  << object << ", count = " << cnt << std::endl;
00040     }
00041 
00042     inline void sp_scalar_destructor_hook(void* object, unsigned long cnt, void* ptr) {
00043         shared_ptr_counters.remove(object);
00044         //std::cerr << "Destroying SharedPtr to "
00045         //  << object << ", count = " << cnt << std::endl;
00046     }
00047 
00048 }
00049 #endif // BOOST_SP_ENABLE_DEBUG_HOOKS
00050 
00051 
00052 #include <boost/shared_ptr.hpp>
00053 
00054 #ifdef BOOST_AC_USE_PTHREADS
00055 #error "Boost is using mutex locking for pointer reference counting."
00056 #error "This is VERY slow.  Please report your platform to d@drobilla.net"
00057 #endif
00058 
00059 template <typename T> void NullDeleter(T* ptr) {}
00060 
00061 #define SharedPtr boost::shared_ptr
00062 #define PtrCast   boost::dynamic_pointer_cast
00063 
00064 #endif // RAUL_SHARED_PTR_HPP
00065 

Generated on Sun Sep 12 2010 for RAUL by  doxygen 1.7.1