RAUL 0.8.0

- 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 #ifdef BOOST_SP_ENABLE_DEBUG_HOOKS
    00022 #include <algorithm>
    00023 #include <cassert>
    00024 #include <cstddef>
    00025 #include <iostream>
    00026 #include <set>
    00027
    00028 static std::set<void*> shared_ptr_counters;
    00029
    00030 // Use debug hooks to ensure 2 shared_ptrs never point to the same thing
    00031 namespace boost {
    00032     inline void sp_scalar_constructor_hook(void* px, std::size_t size, void* pn) {
    00033         assert(shared_ptr_counters.find(px) == shared_ptr_counters.end());
    00034         shared_ptr_counters.push_back(px);
    00035     }
    00036
    00037     inline void sp_scalar_destructor_hook(void* px, std::size_t size, void* pn) {
    00038         shared_ptr_counters.remove(px);
    00039     }
    00040 }
    00041 #endif // BOOST_SP_ENABLE_DEBUG_HOOKS
    00042
    00043
    00044 #include <boost/shared_ptr.hpp>
    00045
    00046 #ifdef BOOST_AC_USE_PTHREADS
    00047 #error "Boost is using mutexes for shared_ptr reference counting."
    00048 #error "This is VERY slow.  Please report your platform to d@drobilla.net"
    00049 #endif
    00050
    00051 template <typename T> void NullDeleter(T* ptr) {}
    00052
    00053 #define SharedPtr boost::shared_ptr
    00054 #define PtrCast   boost::dynamic_pointer_cast
    00055
    00056 #endif // RAUL_SHARED_PTR_HPP
    00057