Use deleted members to prevent copying in Beast (RIPD-268)

This commit is contained in:
Nik Bougalis authored and Vinnie Falco committed 2014-10-01 08:47:52 -07:00
1 parent cd97b5beec
commit 60330da25c
48 files changed
+255 -191

No files matched your search

+4 -2
View File
@@ -20,7 +20,6 @@
#ifndef BEAST_ASIO_BASICS_SSLCONTEXT_H_INCLUDED
#define BEAST_ASIO_BASICS_SSLCONTEXT_H_INCLUDED
#include <beast/Uncopyable.h>
#include <boost/asio/ssl/context.hpp>
namespace beast {
@@ -29,7 +28,7 @@ namespace asio {
/** Simple base class for passing a context around.
This lets derived classes hide their implementation from the headers.
*/
class SSLContext : public Uncopyable
class SSLContext
{
public:
virtual ~SSLContext ();
@@ -61,6 +60,9 @@ public:
protected:
explicit SSLContext (ContextType& context);
SSLContext(SSLContext const&) = delete;
SSLContext& operator= (SSLContext const&) = delete;
ContextType& m_context;
};
+4 -1
View File
@@ -26,7 +26,7 @@
namespace beast {
namespace asio {
class HTTPClientType : public HTTPClientBase, public Uncopyable
class HTTPClientType : public HTTPClientBase
{
public:
class Session;
@@ -61,6 +61,9 @@ public:
{
}
HTTPClientType(HTTPClientType const&) = delete;
HTTPClientType& operator= (HTTPClientType const&) = delete;
~HTTPClientType ()
{
cancel();
@@ -55,7 +55,7 @@ namespace beast
@endcode
*/
template <class ObjectType>
class LinkedListPointer : public Uncopyable
class LinkedListPointer
{
public:
//==============================================================================
@@ -65,6 +65,9 @@ public:
{
}
LinkedListPointer(LinkedListPointer const&) = delete;
LinkedListPointer& operator= (LinkedListPointer const&) = delete;
/** Creates a pointer to a list whose head is the item provided. */
explicit LinkedListPointer (ObjectType* const headItem) noexcept
: item (headItem)
@@ -332,7 +335,7 @@ public:
list, and then repeatedly call Appender::append() to add items to the end
of the list in O(1) time.
*/
class Appender : public Uncopyable
class Appender
{
public:
/** Creates an appender which will add items to the given list.
@@ -344,6 +347,9 @@ public:
bassert (endOfListPointer.item == nullptr);
}
Appender(LinkedListPointer const&) = delete;
Appender& operator= (Appender const&) = delete;
/** Appends an item to the list. */
void append (ObjectType* const newItem) noexcept
{
@@ -54,7 +54,7 @@ namespace beast
*/
template <typename ValueType>
class ScopedValueSetter : public Uncopyable
class ScopedValueSetter
{
public:
/** Creates a ScopedValueSetter that will immediately change the specified value to the
@@ -80,6 +80,9 @@ public:
valueToSet = newValue;
}
ScopedValueSetter(ScopedValueSetter const&) = delete;
ScopedValueSetter& operator= (ScopedValueSetter const&) = delete;
~ScopedValueSetter()
{
value = originalValue;
-1
View File
@@ -42,7 +42,6 @@
// New header-only library modeled more closely according to boost
#include <beast/SmartPtr.h>
#include <beast/StaticAssert.h>
#include <beast/Uncopyable.h>
#include <beast/Atomic.h>
#include <beast/Arithmetic.h>
#include <beast/ByteOrder.h>
+4 -1
View File
@@ -34,7 +34,7 @@ namespace beast
the process is terminated, a listener object gets notified so that the
client application can perform logging or emit further diagnostics.
*/
class FatalError : public Uncopyable
class FatalError
{
public:
struct Reporter
@@ -145,6 +145,9 @@ public:
*/
FatalError (char const* message, char const* filePath, int lineNumber);
FatalError(FatalError const&) = delete;
FatalError& operator= (FatalError const&) = delete;
private:
static Reporter* s_reporter;
};
+9 -2
View File
@@ -41,7 +41,7 @@ namespace beast {
It can also guess how far it's got using a wildly inaccurate algorithm.
*/
class DirectoryIterator : LeakChecked <DirectoryIterator>, public Uncopyable
class DirectoryIterator : LeakChecked <DirectoryIterator>
{
public:
//==============================================================================
@@ -72,6 +72,9 @@ public:
const String& wildCard = "*",
int whatToLookFor = File::findFiles);
DirectoryIterator(DirectoryIterator const&) = delete;
DirectoryIterator& operator= (DirectoryIterator const&) = delete;
/** Destructor. */
~DirectoryIterator();
@@ -116,10 +119,14 @@ public:
private:
//==============================================================================
class NativeIterator : LeakChecked <NativeIterator>, public Uncopyable
class NativeIterator : LeakChecked <NativeIterator>
{
public:
NativeIterator (const File& directory, const String& wildCard);
NativeIterator(NativeIterator const&) = delete;
NativeIterator& operator= (NativeIterator const&) = delete;
~NativeIterator();
bool next (String& filenameFound,
+4 -1
View File
@@ -39,7 +39,7 @@ namespace beast
@see FileInputStream, FileOutputStream
*/
class RandomAccessFile : public Uncopyable, LeakChecked <RandomAccessFile>
class RandomAccessFile : LeakChecked <RandomAccessFile>
{
public:
/** The type of an FileOffset.
@@ -71,6 +71,9 @@ public:
*/
RandomAccessFile () noexcept;
RandomAccessFile(RandomAccessFile const&) = delete;
RandomAccessFile& operator= (RandomAccessFile const&) = delete;
/** Destroy the file object.
If the operating system file is open it will be closed.
+4 -1
View File
@@ -65,7 +65,7 @@ namespace beast
@see File, FileOutputStream
*/
class TemporaryFile : LeakChecked <TemporaryFile>, public Uncopyable
class TemporaryFile : LeakChecked <TemporaryFile>
{
public:
//==============================================================================
@@ -117,6 +117,9 @@ public:
TemporaryFile (const File& targetFile,
const File& temporaryFile);
TemporaryFile(TemporaryFile const&) = delete;
TemporaryFile& operator= (TemporaryFile const&) = delete;
/** Destructor.
When this object is deleted it will make sure that its temporary file is
+5 -4
View File
@@ -169,7 +169,7 @@ private:
// This structure gets zero-filled at static initialization time.
// No constructors are called.
//
class StaticData : public Uncopyable
class StaticData
{
public:
LockType mutex;
@@ -177,9 +177,10 @@ private:
SharedSingleton object;
bool destructorCalled;
private:
StaticData();
~StaticData();
StaticData() = delete;
StaticData(StaticData const&) = delete;
StaticData& operator= (StaticData const&) = delete;
~StaticData() = delete;
};
static StaticData& getStaticData ()
+4 -3
View File
@@ -33,7 +33,7 @@ namespace beast
Contains some static helper functions for manipulating the MS Windows registry
(Only available on Windows, of course!)
*/
class WindowsRegistry : public Uncopyable
class WindowsRegistry
{
public:
//==============================================================================
@@ -113,8 +113,9 @@ public:
int iconResourceNumber,
bool registerForCurrentUserOnly);
private:
WindowsRegistry();
WindowsRegistry() = delete;
WindowsRegistry(WindowsRegistry const&) = delete;
WindowsRegistry const& operator= (WindowsRegistry const&) = delete;
};
#endif
+4 -1
View File
@@ -244,7 +244,7 @@ bool File::moveToTrash() const
}
//==============================================================================
class DirectoryIterator::NativeIterator::Pimpl : public Uncopyable
class DirectoryIterator::NativeIterator::Pimpl
{
public:
Pimpl (const File& directory, const String& wildCard_)
@@ -254,6 +254,9 @@ public:
{
}
Pimpl (Pimpl const&) = delete;
Pimpl& operator= (Pimpl const&) = delete;
~Pimpl()
{
if (dir != nullptr)
+4 -1
View File
@@ -244,7 +244,7 @@ bool File::moveToTrash() const
}
//==============================================================================
class DirectoryIterator::NativeIterator::Pimpl : public Uncopyable
class DirectoryIterator::NativeIterator::Pimpl
{
public:
Pimpl (const File& directory, const String& wildCard_)
@@ -254,6 +254,9 @@ public:
{
}
Pimpl (Pimpl const&) = delete;
Pimpl& operator= (Pimpl const&) = delete;
~Pimpl()
{
if (dir != nullptr)
+4 -1
View File
@@ -312,7 +312,7 @@ bool File::moveToTrash() const
}
//==============================================================================
class DirectoryIterator::NativeIterator::Pimpl : public Uncopyable
class DirectoryIterator::NativeIterator::Pimpl
{
public:
Pimpl (const File& directory, const String& wildCard_)
@@ -326,6 +326,9 @@ public:
}
}
Pimpl (Pimpl const&) = delete;
Pimpl& operator= (Pimpl const&) = delete;
~Pimpl()
{
[enumerator release];
+4 -1
View File
@@ -66,13 +66,16 @@ struct NSObjectRetainer
//==============================================================================
template <typename SuperclassType>
struct ObjCClass : public Uncopyable
struct ObjCClass
{
ObjCClass (const char* nameRoot)
: cls (objc_allocateClassPair ([SuperclassType class], getRandomisedName (nameRoot).toUTF8(), 0))
{
}
ObjCClass (ObjCClass const&);
ObjCClass& operator= (ObjCClass const&);
~ObjCClass()
{
objc_disposeClassPair (cls);
+3 -1
View File
@@ -735,7 +735,6 @@ bool File::createLink (const String& description, const File& linkFileToCreate)
//==============================================================================
class DirectoryIterator::NativeIterator::Pimpl
: LeakChecked <DirectoryIterator::NativeIterator::Pimpl>
, public Uncopyable
{
public:
Pimpl (const File& directory, const String& wildCard)
@@ -744,6 +743,9 @@ public:
{
}
Pimpl (Pimpl const&) = delete;
Pimpl& operator= (Pimpl const&) = delete;
~Pimpl()
{
if (handle != INVALID_HANDLE_VALUE)
+4 -1
View File
@@ -24,7 +24,7 @@
namespace beast
{
struct RegistryKeyWrapper : public Uncopyable
struct RegistryKeyWrapper
{
RegistryKeyWrapper (String name, const bool createForWriting, const DWORD wow64Flags)
: key (0), wideCharValueName (nullptr)
@@ -55,6 +55,9 @@ struct RegistryKeyWrapper : public Uncopyable
}
}
RegistryKeyWrapper (RegistryKeyWrapper const&) = delete;
RegistryKeyWrapper& operator= (RegistryKeyWrapper const&) = delete;
~RegistryKeyWrapper()
{
if (key != 0)
+3 -1
View File
@@ -36,7 +36,6 @@ namespace beast
class FileInputSource
: public InputSource
, LeakChecked <FileInputSource>
, public Uncopyable
{
public:
//==============================================================================
@@ -47,6 +46,9 @@ public:
*/
FileInputSource (const File& file, bool useFileTimeInHashGeneration = false);
FileInputSource (FileInputSource const&) = delete;
FileInputSource& operator= (FileInputSource const&) = delete;
/** Destructor. */
~FileInputSource();
+3 -2
View File
@@ -38,7 +38,6 @@ class MemoryBlock;
@see OutputStream, FileInputStream
*/
class InputStream
: public Uncopyable
, LeakChecked <InputStream>
{
public:
@@ -352,7 +351,9 @@ public:
protected:
//==============================================================================
InputStream() noexcept {}
InputStream() = default;
InputStream (InputStream const&) = delete;
InputStream& operator= (InputStream const&) = delete;
};
} // beast
+4 -1
View File
@@ -40,12 +40,15 @@ class File;
@see InputStream, MemoryOutputStream, FileOutputStream
*/
class OutputStream : public Uncopyable
class OutputStream
{
protected:
//==============================================================================
OutputStream();
OutputStream (OutputStream const&) = delete;
OutputStream& operator= (OutputStream const&) = delete;
public:
/** Destructor.
+4 -2
View File
@@ -31,7 +31,7 @@ namespace beast
/**
Contains methods for finding out about the current hardware and OS configuration.
*/
class SystemStats : public Uncopyable
class SystemStats
{
public:
//==============================================================================
@@ -177,7 +177,9 @@ public:
private:
//==============================================================================
SystemStats();
SystemStats() = delete;
SystemStats (SystemStats const&) = delete;
SystemStats const& operator= (SystemStats const&) = delete;
};
} // beast
+3 -1
View File
@@ -28,7 +28,6 @@ namespace beast {
*/
class DeadlineTimer
: public List <DeadlineTimer>::Node
, public Uncopyable
{
public:
/** Listener for a deadline timer.
@@ -50,6 +49,9 @@ public:
*/
explicit DeadlineTimer (Listener* listener);
DeadlineTimer (DeadlineTimer const&) = delete;
DeadlineTimer& operator= (DeadlineTimer const&) = delete;
~DeadlineTimer ();
/** Cancel all notifications.
+24 -6
View File
@@ -29,7 +29,7 @@ namespace detail
{
template <typename Mutex>
class TrackedScopedLock : public Uncopyable
class TrackedScopedLock
{
public:
inline explicit TrackedScopedLock (Mutex const& mutex,
@@ -40,6 +40,9 @@ public:
lock (fileName, lineNumber);
}
TrackedScopedLock (TrackedScopedLock const&) = delete;
TrackedScopedLock& operator= (TrackedScopedLock const&) = delete;
inline ~TrackedScopedLock () noexcept
{
if (m_lock_count > 0)
@@ -66,7 +69,7 @@ private:
//--------------------------------------------------------------------------
template <typename Mutex>
class TrackedScopedTryLock : public Uncopyable
class TrackedScopedTryLock
{
public:
inline explicit TrackedScopedTryLock (Mutex const& mutex,
@@ -77,6 +80,9 @@ public:
try_lock (fileName, lineNumber);
}
TrackedScopedTryLock (TrackedScopedTryLock const&) = delete;
TrackedScopedTryLock& operator= (TrackedScopedTryLock const&) = delete;
inline ~TrackedScopedTryLock () noexcept
{
if (m_lock_count > 0)
@@ -110,7 +116,7 @@ private:
//--------------------------------------------------------------------------
template <typename Mutex>
class TrackedScopedUnlock : public Uncopyable
class TrackedScopedUnlock
{
public:
inline explicit TrackedScopedUnlock (Mutex const& mutex,
@@ -122,6 +128,9 @@ public:
m_mutex.unlock ();
}
TrackedScopedUnlock (TrackedScopedUnlock const&) = delete;
TrackedScopedUnlock& operator= (TrackedScopedUnlock const&) = delete;
inline ~TrackedScopedUnlock () noexcept
{
m_mutex.lock (m_fileName, m_lineNumber);
@@ -136,7 +145,7 @@ private:
//--------------------------------------------------------------------------
template <typename Mutex>
class UntrackedScopedLock : public Uncopyable
class UntrackedScopedLock
{
public:
inline explicit UntrackedScopedLock (Mutex const& mutex,
@@ -147,6 +156,9 @@ public:
lock ();
}
UntrackedScopedLock (UntrackedScopedLock const&) = delete;
UntrackedScopedLock& operator= (UntrackedScopedLock const&) = delete;
inline ~UntrackedScopedLock () noexcept
{
if (m_lock_count > 0)
@@ -178,7 +190,7 @@ private:
//--------------------------------------------------------------------------
template <typename Mutex>
class UntrackedScopedTryLock : public Uncopyable
class UntrackedScopedTryLock
{
public:
inline explicit UntrackedScopedTryLock (Mutex const& mutex,
@@ -189,6 +201,9 @@ public:
try_lock ();
}
UntrackedScopedTryLock (UntrackedScopedTryLock const&) = delete;
UntrackedScopedTryLock& operator= (UntrackedScopedTryLock const&) = delete;
inline ~UntrackedScopedTryLock () noexcept
{
if (m_lock_count > 0)
@@ -227,7 +242,7 @@ private:
//--------------------------------------------------------------------------
template <typename Mutex>
class UntrackedScopedUnlock : public Uncopyable
class UntrackedScopedUnlock
{
public:
UntrackedScopedUnlock (Mutex const& mutex,
@@ -239,6 +254,9 @@ public:
m_owns_lock = false;
}
UntrackedScopedUnlock (UntrackedScopedUnlock const&) = delete;
UntrackedScopedUnlock& operator= (UntrackedScopedUnlock const&) = delete;
~UntrackedScopedUnlock () noexcept
{
MutexTraits <Mutex>::lock (m_mutex);
+9 -4
View File
@@ -39,13 +39,16 @@ namespace beast {
@see ScopedLock, ScopedTryLock, ScopedUnlock, SpinLock, Thread
*/
class CriticalSection : public Uncopyable
class CriticalSection
{
public:
//==============================================================================
/** Creates a CriticalSection object. */
CriticalSection() noexcept;
CriticalSection (CriticalSection const&) = delete;
CriticalSection& operator= (CriticalSection const&) = delete;
/** Destructor.
If the critical section is deleted whilst locked, any subsequent behaviour
is unpredictable.
@@ -138,11 +141,13 @@ private:
@see CriticalSection, Array, SharedObjectArray
*/
class DummyCriticalSection : public Uncopyable
class DummyCriticalSection
{
public:
inline DummyCriticalSection() noexcept {}
inline ~DummyCriticalSection() noexcept {}
DummyCriticalSection() = default;
DummyCriticalSection (DummyCriticalSection const&) = delete;
DummyCriticalSection& operator= (DummyCriticalSection const&) = delete;
~DummyCriticalSection() = default;
inline void enter() const noexcept {}
inline bool tryEnter() const noexcept { return true; }
+4 -1
View File
@@ -34,7 +34,7 @@ namespace beast
Since the DLL is freed when this object is deleted, it's handy for managing
library lifetimes using RAII.
*/
class DynamicLibrary : LeakChecked <DynamicLibrary>, public Uncopyable
class DynamicLibrary : LeakChecked <DynamicLibrary>
{
public:
/** Creates an unopened DynamicLibrary object.
@@ -46,6 +46,9 @@ public:
*/
DynamicLibrary (const String& name) : handle (nullptr) { open (name); }
DynamicLibrary (DynamicLibrary const&) = delete;
DynamicLibrary& operator= (DynamicLibrary const&) = delete;
/** Destructor.
If a library is currently open, it will be closed when this object is destroyed.
*/
+4 -2
View File
@@ -34,7 +34,7 @@ namespace beast {
@see Thread, BEASTApplication
*/
class Process : public Uncopyable
class Process
{
public:
//==============================================================================
@@ -130,7 +130,9 @@ public:
#endif
private:
Process();
Process() = delete;
Process (Process const&) = delete;
Process const& operator= (Process const&) = delete;
};
} // beast
+12 -3
View File
@@ -53,7 +53,7 @@ namespace beast
@see GenericScopedUnlock, CriticalSection, SpinLock, ScopedLock, ScopedUnlock
*/
template <class LockType>
class GenericScopedLock : public Uncopyable
class GenericScopedLock
{
public:
//==============================================================================
@@ -72,6 +72,9 @@ public:
lock.enter();
}
GenericScopedLock (GenericScopedLock const&) = delete;
GenericScopedLock& operator= (GenericScopedLock const&) = delete;
/** Destructor.
The lock will be released when the destructor is called.
Make sure this object is created and deleted by the same thread, otherwise there are
@@ -126,7 +129,7 @@ private:
@see GenericScopedLock, CriticalSection, ScopedLock, ScopedUnlock
*/
template <class LockType>
class GenericScopedUnlock : public Uncopyable
class GenericScopedUnlock
{
public:
//==============================================================================
@@ -146,6 +149,9 @@ public:
lock.unlock();
}
GenericScopedUnlock (GenericScopedUnlock const&) = delete;
GenericScopedUnlock& operator= (GenericScopedUnlock const&) = delete;
/** Destructor.
The CriticalSection will be unlocked when the destructor is called.
@@ -200,7 +206,7 @@ private:
@see CriticalSection::tryEnter, GenericScopedLock, GenericScopedUnlock
*/
template <class LockType>
class GenericScopedTryLock : public Uncopyable
class GenericScopedTryLock
{
public:
//==============================================================================
@@ -217,6 +223,9 @@ public:
inline explicit GenericScopedTryLock (const LockType& lock) noexcept
: lock_ (lock), lockWasSuccessful (lock.tryEnter()) {}
GenericScopedTryLock (GenericScopedTryLock const&) = delete;
GenericScopedTryLock& operator= (GenericScopedTryLock const&) = delete;
/** Destructor.
The mutex will be unlocked (if it had been successfully locked) when the
@@ -65,7 +65,7 @@ namespace sqdb {
namespace detail {
// used for "once" and "prepare"
class ref_counted_statement_base : public Uncopyable
class ref_counted_statement_base
{
public:
ref_counted_statement_base(session& s);
@@ -82,6 +82,11 @@ public:
}
public:
ref_counted_statement_base (
ref_counted_statement_base const&) = delete;
ref_counted_statement_base& operator= (
ref_counted_statement_base const&) = delete;
// break circular header dependency
std::ostringstream& get_query_stream();
+6 -2
View File
@@ -76,7 +76,6 @@ template <typename T>
class conversion_into_type
: private base_value_holder<T>
, public into_type <typename type_conversion<T>::base_type>
, public Uncopyable
{
public:
typedef typename type_conversion<T>::base_type BASE_TYPE;
@@ -89,6 +88,9 @@ public:
: into_type<BASE_TYPE>(detail::base_value_holder<T>::m_value, ind)
, m_value(value), m_ind(ind) {}
conversion_into_type (conversion_into_type const&) = delete;
conversion_into_type& operator= (conversion_into_type const&) = delete;
private:
void convert_from_base()
{
@@ -107,7 +109,6 @@ template<typename T>
class conversion_use_type
: private base_value_holder<T>
, public use_type<typename type_conversion<T>::base_type>
, public Uncopyable
{
public:
typedef typename type_conversion<T>::base_type BASE_TYPE;
@@ -128,6 +129,9 @@ public:
: use_type<BASE_TYPE>(detail::base_value_holder<T>::m_value, ind)
, m_value(const_cast<T&>(value)), m_ind(ind), m_bReadOnly(true) {}
conversion_use_type (conversion_use_type const&) = delete;
conversion_use_type& operator= (conversion_use_type const&) = delete;
void convert_from_base()
{
if (!m_bReadOnly)