NO_COPY_CLASS c++11
This commit is contained in:
@@ -28,6 +28,7 @@
|
|||||||
*/
|
*/
|
||||||
class PIP_EXPORT PIConditionLock {
|
class PIP_EXPORT PIConditionLock {
|
||||||
public:
|
public:
|
||||||
|
NO_COPY_CLASS(PIConditionLock)
|
||||||
explicit PIConditionLock();
|
explicit PIConditionLock();
|
||||||
~PIConditionLock();
|
~PIConditionLock();
|
||||||
|
|
||||||
@@ -43,7 +44,6 @@ public:
|
|||||||
void * handle();
|
void * handle();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
NO_COPY_CLASS(PIConditionLock)
|
|
||||||
PRIVATE_DECLARATION
|
PRIVATE_DECLARATION
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -32,6 +32,7 @@
|
|||||||
*/
|
*/
|
||||||
class PIP_EXPORT PIConditionVariable {
|
class PIP_EXPORT PIConditionVariable {
|
||||||
public:
|
public:
|
||||||
|
NO_COPY_CLASS(PIConditionVariable)
|
||||||
explicit PIConditionVariable();
|
explicit PIConditionVariable();
|
||||||
virtual ~PIConditionVariable();
|
virtual ~PIConditionVariable();
|
||||||
|
|
||||||
@@ -111,7 +112,6 @@ public:
|
|||||||
virtual bool waitFor(PIConditionLock& lk, int timeoutMs, const std::function<bool()>& condition);
|
virtual bool waitFor(PIConditionLock& lk, int timeoutMs, const std::function<bool()>& condition);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
NO_COPY_CLASS(PIConditionVariable)
|
|
||||||
PRIVATE_DECLARATION
|
PRIVATE_DECLARATION
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -96,9 +96,7 @@
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef PIP_CXX11_SUPPORT
|
#include <functional>
|
||||||
# include <functional>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
@@ -220,8 +218,8 @@
|
|||||||
#define PRIVATEWB __privateinitializer__.p
|
#define PRIVATEWB __privateinitializer__.p
|
||||||
|
|
||||||
#define NO_COPY_CLASS(name) \
|
#define NO_COPY_CLASS(name) \
|
||||||
explicit name(const name & ); \
|
name(const name&) = delete; \
|
||||||
void operator =(const name & );
|
name& operator=(const name&) = delete;
|
||||||
|
|
||||||
#ifdef FREERTOS
|
#ifdef FREERTOS
|
||||||
# define PIP_MIN_MSLEEP 10.
|
# define PIP_MIN_MSLEEP 10.
|
||||||
@@ -255,15 +253,9 @@ typedef unsigned long long ullong;
|
|||||||
typedef long long llong;
|
typedef long long llong;
|
||||||
typedef long double ldouble;
|
typedef long double ldouble;
|
||||||
|
|
||||||
#ifdef PIP_CXX11_SUPPORT
|
|
||||||
#define piMove(v) std::move(v)
|
|
||||||
#else
|
|
||||||
#define piMove(v) v
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*! \brief Templated function for swap two values
|
/*! \brief Templated function for swap two values
|
||||||
* \details Example:\n \snippet piincludes.cpp swap */
|
* \details Example:\n \snippet piincludes.cpp swap */
|
||||||
template<typename T> inline void piSwap(T & f, T & s) {T t(piMove(f)); f = piMove(s); s = piMove(t);}
|
template<typename T> inline void piSwap(T & f, T & s) {T t(std::move(f)); f = std::move(s); s = std::move(t);}
|
||||||
|
|
||||||
/*! \brief Templated function for swap two values without "="
|
/*! \brief Templated function for swap two values without "="
|
||||||
* \details Example:\n \snippet piincludes.cpp swapBinary */
|
* \details Example:\n \snippet piincludes.cpp swapBinary */
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ class PIP_EXPORT PIIODevice: public PIThread
|
|||||||
PIOBJECT_SUBCLASS(PIIODevice, PIThread)
|
PIOBJECT_SUBCLASS(PIIODevice, PIThread)
|
||||||
friend void __DevicePool_threadReadDP(void * ddp);
|
friend void __DevicePool_threadReadDP(void * ddp);
|
||||||
public:
|
public:
|
||||||
|
NO_COPY_CLASS(PIIODevice)
|
||||||
|
|
||||||
//! Constructs a empty PIIODevice
|
//! Constructs a empty PIIODevice
|
||||||
explicit PIIODevice();
|
explicit PIIODevice();
|
||||||
@@ -388,8 +389,6 @@ protected:
|
|||||||
void * ret_data_;
|
void * ret_data_;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
NO_COPY_CLASS(PIIODevice)
|
|
||||||
|
|
||||||
EVENT_HANDLER2(void, check_start, void * , data, int, delim);
|
EVENT_HANDLER2(void, check_start, void * , data, int, delim);
|
||||||
EVENT_HANDLER(void, write_func);
|
EVENT_HANDLER(void, write_func);
|
||||||
|
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ class PIP_EXPORT PIDiagnostics: public PITimer
|
|||||||
PIOBJECT_SUBCLASS(PIDiagnostics, PITimer)
|
PIOBJECT_SUBCLASS(PIDiagnostics, PITimer)
|
||||||
friend class PIConnection;
|
friend class PIConnection;
|
||||||
public:
|
public:
|
||||||
|
NO_COPY_CLASS(PIDiagnostics)
|
||||||
|
|
||||||
//! Constructs an empty diagnostics and if "start_" start it
|
//! Constructs an empty diagnostics and if "start_" start it
|
||||||
PIDiagnostics(bool start_ = true);
|
PIDiagnostics(bool start_ = true);
|
||||||
@@ -122,8 +123,6 @@ public:
|
|||||||
//! \}
|
//! \}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
NO_COPY_CLASS(PIDiagnostics)
|
|
||||||
|
|
||||||
struct Entry {
|
struct Entry {
|
||||||
Entry() {bytes_ok = bytes_fail = 0; cnt_ok = cnt_fail = 0; empty = true;}
|
Entry() {bytes_ok = bytes_fail = 0; cnt_ok = cnt_fail = 0; empty = true;}
|
||||||
ullong bytes_ok;
|
ullong bytes_ok;
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
/*! \file pimutex.h
|
/*! \file pimutex.h
|
||||||
* \brief Mutex
|
* \brief PIMutexLocker
|
||||||
*/
|
*/
|
||||||
/*
|
/*
|
||||||
PIP - Platform Independent Primitives
|
PIP - Platform Independent Primitives
|
||||||
Mutex
|
PIMutexLocker
|
||||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
@@ -25,15 +25,19 @@
|
|||||||
|
|
||||||
#include "piinit.h"
|
#include "piinit.h"
|
||||||
|
|
||||||
|
//! \brief PIMutexLocker
|
||||||
|
//! \details Same as std::lock_guard<std::mutex>.
|
||||||
|
//! When a PIMutexLocker object is created, it attempts to lock the mutex it is given, if "condition" true.
|
||||||
|
//! When control leaves the scope in which the PIMutexLocker object was created,
|
||||||
|
//! the PIMutexLocker is destructed and the mutex is released, if "condition" true.
|
||||||
|
//! If "condition" false this class do nothing.
|
||||||
|
//! The PIMutexLocker class is non-copyable.
|
||||||
class PIP_EXPORT PIMutexLocker
|
class PIP_EXPORT PIMutexLocker
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
NO_COPY_CLASS(PIMutexLocker)
|
||||||
PIMutexLocker(PIMutex & m, bool condition = true): mutex(m), cond(condition) {if (cond) mutex.lock();}
|
PIMutexLocker(PIMutex & m, bool condition = true): mutex(m), cond(condition) {if (cond) mutex.lock();}
|
||||||
~PIMutexLocker() {if (cond) mutex.unlock();}
|
~PIMutexLocker() {if (cond) mutex.unlock();}
|
||||||
|
|
||||||
PIMutexLocker(const PIMutexLocker&) = delete;
|
|
||||||
PIMutexLocker& operator=(const PIMutexLocker&) = delete;
|
|
||||||
private:
|
private:
|
||||||
PIMutex & mutex;
|
PIMutex & mutex;
|
||||||
std::atomic_bool cond;
|
std::atomic_bool cond;
|
||||||
|
|||||||
@@ -71,6 +71,7 @@ class PIP_EXPORT PIThread: public PIObject
|
|||||||
PIOBJECT_SUBCLASS(PIThread, PIObject)
|
PIOBJECT_SUBCLASS(PIThread, PIObject)
|
||||||
friend class PIIntrospectionThreads;
|
friend class PIIntrospectionThreads;
|
||||||
public:
|
public:
|
||||||
|
NO_COPY_CLASS(PIThread)
|
||||||
|
|
||||||
//! Contructs thread with custom data "data", external function "func" and main loop delay "loop_delay".
|
//! Contructs thread with custom data "data", external function "func" and main loop delay "loop_delay".
|
||||||
PIThread(void * data, ThreadFunc func, bool startNow = false, int loop_delay = -1);
|
PIThread(void * data, ThreadFunc func, bool startNow = false, int loop_delay = -1);
|
||||||
@@ -257,8 +258,6 @@ protected:
|
|||||||
PRIVATE_DECLARATION
|
PRIVATE_DECLARATION
|
||||||
|
|
||||||
private:
|
private:
|
||||||
NO_COPY_CLASS(PIThread)
|
|
||||||
|
|
||||||
bool _startThread(void * func);
|
bool _startThread(void * func);
|
||||||
void _beginThread();
|
void _beginThread();
|
||||||
void _runThread();
|
void _runThread();
|
||||||
|
|||||||
@@ -78,6 +78,7 @@ protected:
|
|||||||
class PIP_EXPORT PITimer: public PIObject {
|
class PIP_EXPORT PITimer: public PIObject {
|
||||||
PIOBJECT_SUBCLASS(PITimer, PIObject)
|
PIOBJECT_SUBCLASS(PITimer, PIObject)
|
||||||
public:
|
public:
|
||||||
|
NO_COPY_CLASS(PITimer)
|
||||||
|
|
||||||
//! \brief Constructs timer with PITimer::Thread implementation
|
//! \brief Constructs timer with PITimer::Thread implementation
|
||||||
explicit PITimer();
|
explicit PITimer();
|
||||||
@@ -254,17 +255,13 @@ protected:
|
|||||||
virtual void tick(void * data_, int delimiter) {}
|
virtual void tick(void * data_, int delimiter) {}
|
||||||
|
|
||||||
void * data_t;
|
void * data_t;
|
||||||
volatile bool lockRun, callEvents;
|
std::atomic_bool lockRun, callEvents;
|
||||||
PIMutex mutex_;
|
PIMutex mutex_;
|
||||||
TimerEvent ret_func;
|
TimerEvent ret_func;
|
||||||
TimerImplementation imp_mode;
|
TimerImplementation imp_mode;
|
||||||
PIVector<Delimiter> delims;
|
PIVector<Delimiter> delims;
|
||||||
|
|
||||||
mutable _PITimerBase * imp;
|
mutable _PITimerBase * imp;
|
||||||
|
|
||||||
private:
|
|
||||||
NO_COPY_CLASS(PITimer)
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user