1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-07-02 16:38:41 +00:00

Add DISABLE_CLASS_COPY macro (and use it)

Use this macro to disallow copying of an object using the assignment
operator or copy constructor.  This catches otherwise silent-but-deadly
mistakes such as "ServerMap map = env->getMap();" at compile time.

If so desired, it is still possible to copy a class, but it now requires
an explicit call to memcpy or std::copy.
This commit is contained in:
kwolekr 2015-10-27 02:51:43 -04:00
parent ca8e56c15a
commit c56d7fe0eb
11 changed files with 30 additions and 0 deletions

View file

@ -44,6 +44,7 @@ DEALINGS IN THE SOFTWARE.
#include <pthread.h>
#endif
#include "basicmacros.h"
class Mutex
{
@ -59,6 +60,8 @@ private:
#else // pthread
pthread_mutex_t mutex;
#endif
DISABLE_CLASS_COPY(Mutex);
};
#endif // C++11

View file

@ -28,6 +28,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <semaphore.h>
#endif
#include "basicmacros.h"
class Semaphore {
public:
@ -46,6 +47,8 @@ private:
#else
sem_t semaphore;
#endif
DISABLE_CLASS_COPY(Semaphore);
};
#endif

View file

@ -161,6 +161,7 @@ private:
std::thread *m_thread_obj;
#endif
DISABLE_CLASS_COPY(Thread);
};
#endif