diff --git a/src/misc/pv/lock.h b/src/misc/pv/lock.h index df297c3..9e6ed58 100644 --- a/src/misc/pv/lock.h +++ b/src/misc/pv/lock.h @@ -33,7 +33,8 @@ typedef epicsMutex Mutex; * This is based on item 14 of * * Effective C++, Third Edition, Scott Meyers */ -class Lock : private NoDefaultMethods { +class Lock { + EPICS_NOT_COPYABLE(Lock) public: /** * Constructor diff --git a/src/misc/pv/noDefaultMethods.h b/src/misc/pv/noDefaultMethods.h index 4916261..b80cc31 100644 --- a/src/misc/pv/noDefaultMethods.h +++ b/src/misc/pv/noDefaultMethods.h @@ -11,15 +11,41 @@ #include -namespace epics { namespace pvData { -/* This is based on Item 6 of - * Effective C++, Third Edition, Scott Meyers +/** @macro EPICS_NOT_COPYABLE(CLASS) + * @brief Disable implicit copyable + * + * Prevent the default copy constructor and assignment + * operator from being usable. + * + * For >= C++11 explicitly disable. Attempts to copy/assign will + * fail to compile. + * + * For C++98 make these private, and don't implement them. + * User code will fail to compile, implementation code will fail to link. + @code + struct MyClass { + EPICS_NOT_COPYABLE(MyClass) + public: + ... + }; + @code + * + * @note This macro contains 'private:'. */ +#if __cplusplus>=201103L +# define EPICS_NOT_COPYABLE(CLASS) private: CLASS(const CLASS&) = delete; CLASS& operator=(const CLASS&) = delete; +#else +# define EPICS_NOT_COPYABLE(CLASS) private: CLASS(const CLASS&); CLASS& operator=(const CLASS&); +#endif + +namespace epics { namespace pvData { /** * @brief Base class for not allowing default methods. * * Note that copy constructor a copy methods are declared private. + * + * @deprecated Deprecated in favor of EPICS_NOT_COPYABLE() pvDataCPP 7.0.0 */ class NoDefaultMethods { public: diff --git a/src/misc/pv/serializeHelper.h b/src/misc/pv/serializeHelper.h index df14ce1..5ced0d6 100644 --- a/src/misc/pv/serializeHelper.h +++ b/src/misc/pv/serializeHelper.h @@ -26,7 +26,8 @@ namespace epics { * @brief Serialization helper. * */ - class epicsShareClass SerializeHelper : public NoDefaultMethods { + class epicsShareClass SerializeHelper { + EPICS_NOT_COPYABLE(SerializeHelper) public: /** diff --git a/src/misc/pv/thread.h b/src/misc/pv/thread.h index 57faada..103d434 100644 --- a/src/misc/pv/thread.h +++ b/src/misc/pv/thread.h @@ -43,8 +43,9 @@ typedef epicsThreadRunable Runnable; //! Helper for those cases where a class should have more than one runnable template -class RunnableMethod : public Runnable, private NoDefaultMethods +class RunnableMethod : public Runnable { + EPICS_NOT_COPYABLE(RunnableMethod) typedef void (C::*meth_t)(); C *inst; meth_t meth; @@ -104,7 +105,8 @@ struct BindRunner : public epicsThreadRunable * @brief C++ wrapper for epicsThread from EPICS base. * */ -class Thread : public epicsThread, private NoDefaultMethods { +class Thread : public epicsThread { + EPICS_NOT_COPYABLE(Thread) public: /** @brief Holds all the configuration necessary to launch a @class Thread * diff --git a/src/pv/standardPVField.h b/src/pv/standardPVField.h index 57c73f8..ed968ba 100644 --- a/src/pv/standardPVField.h +++ b/src/pv/standardPVField.h @@ -35,7 +35,8 @@ typedef std::tr1::shared_ptr StandardPVFieldPtr; StandardPVField *standardPVField = getStandardPVField(); * } */ -class epicsShareClass StandardPVField : private NoDefaultMethods { +class epicsShareClass StandardPVField { + EPICS_NOT_COPYABLE(StandardPVField) public: /** * getStandardPVField returns the singleton. diff --git a/src/pvMisc/pv/bitSetUtil.h b/src/pvMisc/pv/bitSetUtil.h index 488ae11..2cfeca3 100644 --- a/src/pvMisc/pv/bitSetUtil.h +++ b/src/pvMisc/pv/bitSetUtil.h @@ -9,7 +9,6 @@ #ifndef BITSETUTIL_H #define BITSETUTIL_H -#include #include #include @@ -21,7 +20,7 @@ namespace epics { namespace pvData { * @brief Compress a bitSet. * */ -class epicsShareClass BitSetUtil : private NoDefaultMethods { +class epicsShareClass BitSetUtil { public: /** * compress the bitSet for a pvStructure. diff --git a/testApp/misc/testSerialization.cpp b/testApp/misc/testSerialization.cpp index 75f1a9b..22376ad 100644 --- a/testApp/misc/testSerialization.cpp +++ b/testApp/misc/testSerialization.cpp @@ -60,8 +60,8 @@ static DeserializableControl* control; static ByteBuffer* buffer; -class SerializableControlImpl : public SerializableControl, - public NoDefaultMethods { +class SerializableControlImpl : public SerializableControl { + EPICS_NOT_COPYABLE(SerializableControlImpl) public: virtual void flushSerializeBuffer() { } @@ -91,8 +91,8 @@ public: } }; -class DeserializableControlImpl : public DeserializableControl, - public NoDefaultMethods { +class DeserializableControlImpl : public DeserializableControl { + EPICS_NOT_COPYABLE(DeserializableControlImpl) public: virtual void ensureData(size_t /*size*/) { }