From ed97ce3242176f44704216581d23547c302a238c Mon Sep 17 00:00:00 2001 From: Martin Braun Date: Mon, 28 Jan 2019 14:52:59 +0100 Subject: uhd: utils: Add noncopyable class This is a replacement for boost::noncopyable. It has two implementations with identical APIs, selectable by a macro. One "implementation" is a renaming of the Boost version. The other is simply implemented using C++11 features. The motivation is that the location for boost::noncopyable has changed over the range of Boost versions, thus, using boost::noncopyable is difficult to maintain for a broad range of Boost versions. --- host/include/uhd/utils/CMakeLists.txt | 1 + host/include/uhd/utils/noncopyable.hpp | 55 ++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 host/include/uhd/utils/noncopyable.hpp (limited to 'host/include') diff --git a/host/include/uhd/utils/CMakeLists.txt b/host/include/uhd/utils/CMakeLists.txt index 7f45df1d3..894a804c4 100644 --- a/host/include/uhd/utils/CMakeLists.txt +++ b/host/include/uhd/utils/CMakeLists.txt @@ -20,6 +20,7 @@ UHD_INSTALL(FILES log_add.hpp math.hpp msg_task.hpp + noncopyable.hpp paths.hpp pimpl.hpp platform.hpp diff --git a/host/include/uhd/utils/noncopyable.hpp b/host/include/uhd/utils/noncopyable.hpp new file mode 100644 index 000000000..0f480f6c3 --- /dev/null +++ b/host/include/uhd/utils/noncopyable.hpp @@ -0,0 +1,55 @@ +// +// Copyright 2019 Ettus Research, a National Instruments Brand +// +// SPDX-License-Identifier: GPL-3.0-or-later +// + +#ifndef INCLUDED_UHDLIB_UTILS_NONCOPYABLE_HPP +#define INCLUDED_UHDLIB_UTILS_NONCOPYABLE_HPP + +#ifdef UHD_AVOID_BOOST + +namespace uhd { + +/*! Non-copyable class + * + * This is a re-implementation of boost::noncopyable using C++11 features. + * Deriving a class from this one will disallow it being assigned or copied: + * + * ~~~~{.cpp} + * #include + * + * class C : uhd::noncopyable {}; + * + * C c1; + * C c2(c1); // Won't work + * C c3; + * c3 = c1; // Won't work + * ~~~~ + */ +class noncopyable +{ +public: + noncopyable() = default; + ~noncopyable() = default; + + noncopyable(const noncopyable&) = delete; + noncopyable& operator=(const noncopyable&) = delete; +}; + +} /* namespace uhd */ + +#else + +# if BOOST_VERSION >= 105600 +# include +# else +# include +# endif +namespace uhd { +typedef boost::noncopyable noncopyable; +} + +#endif + +#endif /* INCLUDED_UHDLIB_UTILS_NONCOPYABLE_HPP */ -- cgit v1.2.3