From bed446e569b815ebb81e8866579a8abcda77358a Mon Sep 17 00:00:00 2001 From: David Robillard Date: Fri, 20 May 2011 00:33:22 +0000 Subject: Make boost dependency optional. Note Raul compiled with --cpp0x is NOT compatible with Raul compiled without it. git-svn-id: http://svn.drobilla.net/lad/trunk/raul@3289 a436a847-0d15-0410-975c-d299462d15a1 --- raul.pc.in | 2 +- raul/IntrusivePtr.hpp | 26 -------------------------- raul/List.hpp | 5 ++--- raul/Maid.hpp | 8 ++++---- raul/Noncopyable.hpp | 35 +++++++++++++++++++++++++++++++++++ raul/Process.hpp | 5 ++--- raul/RingBuffer.hpp | 4 ++-- raul/SRMWQueue.hpp | 5 ++--- raul/SRSWQueue.hpp | 5 ++--- raul/Semaphore.hpp | 4 ++-- raul/SharedPtr.hpp | 44 +++++++++++++------------------------------- raul/Table.hpp | 5 ++--- raul/Thread.hpp | 4 ++-- raul/TimeSlice.hpp | 5 ++--- raul/WeakPtr.hpp | 10 +++++++--- wscript | 26 +++++++++++++++++++++----- 16 files changed, 99 insertions(+), 94 deletions(-) delete mode 100644 raul/IntrusivePtr.hpp create mode 100644 raul/Noncopyable.hpp diff --git a/raul.pc.in b/raul.pc.in index db1293b..bc2e2bd 100644 --- a/raul.pc.in +++ b/raul.pc.in @@ -7,4 +7,4 @@ Name: raul Version: @RAUL_VERSION@ Description: A C++ convenience library for realtime audio applications Libs: -L${libdir} -lraul @GLIB_LIBS@ @GTHREAD_LIBS@ @RAUL_PC_LIBS@ -Cflags: -I${includedir} @GLIB_CFLAGS@ @GTHREAD_CFLAGS@ +Cflags: -I${includedir} @GLIB_CFLAGS@ @GTHREAD_CFLAGS@ @RAUL_EXTRA_CXXFLAGS@ diff --git a/raul/IntrusivePtr.hpp b/raul/IntrusivePtr.hpp deleted file mode 100644 index 94ce07a..0000000 --- a/raul/IntrusivePtr.hpp +++ /dev/null @@ -1,26 +0,0 @@ -/* A "weak" pointer to a resource owned by a shared pointer. - * Copyright 2007-2011 David Robillard - * - * This is free software; you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free Software - * Foundation; either version 2 of the License, or (at your option) any later - * version. - * - * This file is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#ifndef RAUL_INTRUSIVE_PTR_HPP -#define RAUL_INTRUSIVE_PTR_HPP - -#include - -#define IntrusivePtr boost::intrusive_ptr - -#endif // RAUL_INTRUSIVE_PTR_HPP - diff --git a/raul/List.hpp b/raul/List.hpp index 4ef23a1..62f3f1c 100644 --- a/raul/List.hpp +++ b/raul/List.hpp @@ -21,11 +21,10 @@ #include #include -#include - #include "raul/AtomicInt.hpp" #include "raul/AtomicPtr.hpp" #include "raul/Deletable.hpp" +#include "raul/Noncopyable.hpp" namespace Raul { @@ -37,7 +36,7 @@ namespace Raul { * \ingroup raul */ template -class List : public Raul::Deletable, public boost::noncopyable +class List : Deletable, Noncopyable { public: diff --git a/raul/Maid.hpp b/raul/Maid.hpp index 3eef6c9..a90bf48 100644 --- a/raul/Maid.hpp +++ b/raul/Maid.hpp @@ -18,11 +18,11 @@ #ifndef RAUL_MAID_HPP #define RAUL_MAID_HPP -#include -#include "raul/SharedPtr.hpp" -#include "raul/SRSWQueue.hpp" #include "raul/Deletable.hpp" #include "raul/List.hpp" +#include "raul/Noncopyable.hpp" +#include "raul/SRSWQueue.hpp" +#include "raul/SharedPtr.hpp" namespace Raul { @@ -42,7 +42,7 @@ namespace Raul { * * \ingroup raul */ -class Maid : boost::noncopyable +class Maid : Noncopyable { public: explicit Maid(size_t size); diff --git a/raul/Noncopyable.hpp b/raul/Noncopyable.hpp new file mode 100644 index 0000000..a81894d --- /dev/null +++ b/raul/Noncopyable.hpp @@ -0,0 +1,35 @@ +/* This file is part of Raul. + * Copyright 2011 David Robillard + * + * Raul is free software; you can redistribute it and/or modify it under the + * terms of the GNU General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) any later + * version. + * + * Raul is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef RAUL_NONCOPYABLE_HPP +#define RAUL_NONCOPYABLE_HPP + +namespace Raul { + +class Noncopyable { +protected: + Noncopyable() {} + ~Noncopyable() {} + +private: + Noncopyable(const Noncopyable&); + const Noncopyable& operator=(const Noncopyable&); +}; + +} // namespace Raul + +#endif // RAUL_NONCOPYABLE_HPP diff --git a/raul/Process.hpp b/raul/Process.hpp index d9ec5e0..21e4f33 100644 --- a/raul/Process.hpp +++ b/raul/Process.hpp @@ -25,8 +25,7 @@ #include #include -#include - +#include "raul/Noncopyable.hpp" #include "raul/log.hpp" namespace Raul { @@ -35,7 +34,7 @@ namespace Raul { * * \ingroup raul */ -class Process : boost::noncopyable +class Process : Noncopyable { public: diff --git a/raul/RingBuffer.hpp b/raul/RingBuffer.hpp index bc17b02..8642514 100644 --- a/raul/RingBuffer.hpp +++ b/raul/RingBuffer.hpp @@ -25,7 +25,7 @@ #include -#include +#include "raul/Noncopyable.hpp" namespace Raul { @@ -37,7 +37,7 @@ namespace Raul { @ingroup raul */ -class RingBuffer : public boost::noncopyable { +class RingBuffer : public Noncopyable { public: /** Create a new RingBuffer. diff --git a/raul/SRMWQueue.hpp b/raul/SRMWQueue.hpp index 6680103..2534ba3 100644 --- a/raul/SRMWQueue.hpp +++ b/raul/SRMWQueue.hpp @@ -22,9 +22,8 @@ #include #include -#include - #include "raul/AtomicInt.hpp" +#include "raul/Noncopyable.hpp" namespace Raul { @@ -50,7 +49,7 @@ namespace Raul { * \ingroup raul */ template -class SRMWQueue : boost::noncopyable +class SRMWQueue : Noncopyable { public: explicit SRMWQueue(size_t size); diff --git a/raul/SRSWQueue.hpp b/raul/SRSWQueue.hpp index 80758d2..ee7a053 100644 --- a/raul/SRSWQueue.hpp +++ b/raul/SRSWQueue.hpp @@ -20,9 +20,8 @@ #include -#include - #include "raul/AtomicInt.hpp" +#include "raul/Noncopyable.hpp" namespace Raul { @@ -39,7 +38,7 @@ namespace Raul { * \ingroup raul */ template -class SRSWQueue : boost::noncopyable +class SRSWQueue : Noncopyable { public: /** @param size Size in number of elements */ diff --git a/raul/Semaphore.hpp b/raul/Semaphore.hpp index 63738c2..7df1817 100644 --- a/raul/Semaphore.hpp +++ b/raul/Semaphore.hpp @@ -25,7 +25,7 @@ #include #endif -#include +#include "raul/Noncopyable.hpp" namespace Raul { @@ -33,7 +33,7 @@ namespace Raul { * * \ingroup raul */ -class Semaphore : boost::noncopyable { +class Semaphore : Noncopyable { public: inline Semaphore(unsigned int initial) { #ifdef __APPLE__ diff --git a/raul/SharedPtr.hpp b/raul/SharedPtr.hpp index ef4fea8..6b241f8 100644 --- a/raul/SharedPtr.hpp +++ b/raul/SharedPtr.hpp @@ -18,39 +18,21 @@ #ifndef RAUL_SHARED_PTR_HPP #define RAUL_SHARED_PTR_HPP -#ifdef BOOST_SP_ENABLE_DEBUG_HOOKS -#include -#include -#include -#include -#include - -static std::set shared_ptr_counters; - -// Use debug hooks to ensure 2 shared_ptrs never point to the same thing -namespace boost { - inline void sp_scalar_constructor_hook(void* px, std::size_t size, void* pn) { - assert(shared_ptr_counters.find(px) == shared_ptr_counters.end()); - shared_ptr_counters.push_back(px); - } - - inline void sp_scalar_destructor_hook(void* px, std::size_t size, void* pn) { - shared_ptr_counters.remove(px); - } -} -#endif // BOOST_SP_ENABLE_DEBUG_HOOKS - -#include - -#ifdef BOOST_AC_USE_PTHREADS -#error "Boost is using mutexes for shared_ptr reference counting." -#error "This is VERY slow. Please report your platform to d@drobilla.net" -#endif - template void NullDeleter(T* ptr) {} -#define SharedPtr boost::shared_ptr -#define PtrCast boost::dynamic_pointer_cast +#ifdef RAUL_CPP0x +# include +# define SharedPtr std::shared_ptr +# define PtrCast std::dynamic_pointer_cast +#else +# include +# ifdef BOOST_AC_USE_PTHREADS +# error "Boost is using mutexes for shared_ptr reference counting." +# error "This is VERY slow. Please report your platform to d@drobilla.net" +# endif +# define SharedPtr boost::shared_ptr +# define PtrCast boost::dynamic_pointer_cast +#endif #endif // RAUL_SHARED_PTR_HPP diff --git a/raul/Table.hpp b/raul/Table.hpp index 55b42f8..dd5c1d7 100644 --- a/raul/Table.hpp +++ b/raul/Table.hpp @@ -22,8 +22,7 @@ #include #include -#include - +#include "raul/Noncopyable.hpp" #include "raul/SharedPtr.hpp" //#define TABLE_SORT_DEBUG @@ -38,7 +37,7 @@ namespace Raul { * \ingroup raul */ template -class Table : public boost::noncopyable { +class Table : public Noncopyable { public: Table() : _entries() {} Table(size_t capacity) : _entries(capacity) {} diff --git a/raul/Thread.hpp b/raul/Thread.hpp index 0f5761d..b67531a 100644 --- a/raul/Thread.hpp +++ b/raul/Thread.hpp @@ -24,7 +24,7 @@ #include -#include +#include "raul/Noncopyable.hpp" namespace Raul { @@ -37,7 +37,7 @@ namespace Raul { * * \ingroup raul */ -class Thread : boost::noncopyable +class Thread : Noncopyable { public: virtual ~Thread() { diff --git a/raul/TimeSlice.hpp b/raul/TimeSlice.hpp index 5e7613e..f75f7fd 100644 --- a/raul/TimeSlice.hpp +++ b/raul/TimeSlice.hpp @@ -21,8 +21,7 @@ #include #include -#include - +#include "raul/Noncopyable.hpp" #include "raul/TimeStamp.hpp" namespace Raul { @@ -47,7 +46,7 @@ namespace Raul { * * \ingroup raul */ -class TimeSlice : public boost::noncopyable { +class TimeSlice : public Noncopyable { public: TimeSlice(uint32_t rate, uint32_t ppqn, double bpm) : _tick_rate(rate) diff --git a/raul/WeakPtr.hpp b/raul/WeakPtr.hpp index 031c995..001599c 100644 --- a/raul/WeakPtr.hpp +++ b/raul/WeakPtr.hpp @@ -18,9 +18,13 @@ #ifndef RAUL_WEAK_PTR_HPP #define RAUL_WEAK_PTR_HPP -#include - -#define WeakPtr boost::weak_ptr +#ifdef RAUL_CPP0x +# include +# define WeakPtr std::weak_ptr +#else +# include +# define WeakPtr boost::weak_ptr +#endif #endif // RAUL_WEAK_PTR_HPP diff --git a/wscript b/wscript index bcbfd1e..b8be77d 100644 --- a/wscript +++ b/wscript @@ -42,6 +42,8 @@ def options(opt): help="Coloured console/log output") opt.add_option('--log-debug', action='store_true', default=False, dest='log_debug', help="Print debugging output") + opt.add_option('--cpp0x', action='store_true', default=False, dest='cpp0x', + help="Use C++0x smart pointers instead of boost") def configure(conf): autowaf.configure(conf) @@ -64,12 +66,18 @@ def configure(conf): if Options.options.log_debug: autowaf.define(conf, 'RAUL_LOG_DEBUG', 1) - conf.write_config_header('raul-config.h', remove=False) - # Boost headers - autowaf.check_header(conf, 'boost/shared_ptr.hpp', mandatory=True) - autowaf.check_header(conf, 'boost/weak_ptr.hpp', mandatory=True) - autowaf.check_header(conf, 'boost/utility.hpp', mandatory=True) + if Options.options.cpp0x: + conf.env.append_value('CXXFLAGS', [ '-std=c++0x' ]) + autowaf.check_header(conf, 'memory', mandatory=True) + autowaf.define(conf, 'RAUL_CPP0x', 1) + autowaf.define(conf, 'RAUL_EXTRA_CXXFLAGS', '-std=c++0x') + else: + autowaf.check_header(conf, 'boost/shared_ptr.hpp', mandatory=True) + autowaf.check_header(conf, 'boost/weak_ptr.hpp', mandatory=True) + autowaf.define(conf, 'RAUL_EXTRA_CXXFLAGS', '') + + conf.write_config_header('raul-config.h', remove=False) autowaf.display_msg(conf, "Unit tests", str(conf.env['BUILD_TESTS'])) print('') @@ -79,6 +87,7 @@ tests = ''' test/atomic_test test/list_test test/path_test + test/ptr_test test/quantize_test test/queue_test test/ringbuffer_test @@ -115,6 +124,10 @@ def build(bld): if Options.platform == 'darwin': framework = ' CoreServices ' + def set_defines(obj): + if bld.env['RAUL_CPP0x']: + obj.defines = ['RAUL_CPP0x'] + # Library obj = bld(features = 'cxx cxxshlib') obj.export_includes = ['.'] @@ -127,6 +140,7 @@ def build(bld): obj.framework = framework obj.install_path = '${LIBDIR}' obj.vnum = RAUL_LIB_VERSION + set_defines(obj); if bld.env['BUILD_TESTS']: # Static library (for unit test code coverage) @@ -139,6 +153,7 @@ def build(bld): obj.framework = framework obj.install_path = '' obj.cxxflags = [ '-fprofile-arcs', '-ftest-coverage' ] + set_defines(obj); # Unit tests for i in tests.split(): @@ -152,6 +167,7 @@ def build(bld): obj.install_path = '' obj.cxxflags = [ '-fprofile-arcs', '-ftest-coverage' ] obj.linkflags = ['-lgcov'] + set_defines(obj); # Documentation autowaf.build_dox(bld, 'RAUL', RAUL_VERSION, top, out) -- cgit v1.2.1