Skip to content

Introduce mbed::NonCopyable traits #4594

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jun 26, 2017
6 changes: 2 additions & 4 deletions drivers/BusIn.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "platform/platform.h"
#include "drivers/DigitalIn.h"
#include "platform/PlatformMutex.h"
#include "platform/NonCopyable.h"

namespace mbed {
/** \addtogroup drivers */
Expand All @@ -28,7 +29,7 @@ namespace mbed {
* @note Synchronization level: Thread safe
* @ingroup drivers
*/
class BusIn {
class BusIn : private NonCopyable<BusIn> {

public:
/* Group: Configuration Methods */
Expand Down Expand Up @@ -115,12 +116,9 @@ class BusIn {

PlatformMutex _mutex;

/* disallow copy constructor and assignment operators */
private:
virtual void lock();
virtual void unlock();
BusIn(const BusIn&);
BusIn & operator = (const BusIn&);
};

} // namespace mbed
Expand Down
8 changes: 2 additions & 6 deletions drivers/BusInOut.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include "drivers/DigitalInOut.h"
#include "platform/PlatformMutex.h"
#include "platform/NonCopyable.h"

namespace mbed {
/** \addtogroup drivers */
Expand All @@ -27,7 +28,7 @@ namespace mbed {
* @note Synchronization level: Thread safe
* @ingroup drivers
*/
class BusInOut {
class BusInOut : private NonCopyable<BusInOut> {

public:

Expand Down Expand Up @@ -135,11 +136,6 @@ class BusInOut {
int _nc_mask;

PlatformMutex _mutex;

/* disallow copy constructor and assignment operators */
private:
BusInOut(const BusInOut&);
BusInOut & operator = (const BusInOut&);
};

} // namespace mbed
Expand Down
8 changes: 2 additions & 6 deletions drivers/BusOut.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@

#include "drivers/DigitalOut.h"
#include "platform/PlatformMutex.h"
#include "platform/NonCopyable.h"

namespace mbed {
/** \addtogroup drivers */

/** A digital output bus, used for setting the state of a collection of pins
* @ingroup drivers
*/
class BusOut {
class BusOut : private NonCopyable<BusOut> {

public:

Expand Down Expand Up @@ -119,11 +120,6 @@ class BusOut {
int _nc_mask;

PlatformMutex _mutex;

/* disallow copy constructor and assignment operators */
private:
BusOut(const BusOut&);
BusOut & operator = (const BusOut&);
};

} // namespace mbed
Expand Down
3 changes: 2 additions & 1 deletion drivers/CAN.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "hal/can_api.h"
#include "platform/Callback.h"
#include "platform/PlatformMutex.h"
#include "platform/NonCopyable.h"

namespace mbed {
/** \addtogroup drivers */
Expand Down Expand Up @@ -78,7 +79,7 @@ class CANMessage : public CAN_Message {
/** A can bus client, used for communicating with can devices
* @ingroup drivers
*/
class CAN {
class CAN : private NonCopyable<CAN> {

public:
/** Creates an CAN interface connected to specific pins.
Expand Down
3 changes: 2 additions & 1 deletion drivers/Ethernet.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#define MBED_ETHERNET_H

#include "platform/platform.h"
#include "platform/NonCopyable.h"

#if defined (DEVICE_ETHERNET) || defined(DOXYGEN_ONLY)

Expand Down Expand Up @@ -54,7 +55,7 @@ namespace mbed {
* @endcode
* @ingroup drivers
*/
class Ethernet {
class Ethernet : private NonCopyable<Ethernet> {

public:

Expand Down
3 changes: 2 additions & 1 deletion drivers/FlashIAP.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "flash_api.h"
#include "platform/SingletonPtr.h"
#include "platform/PlatformMutex.h"
#include "platform/NonCopyable.h"

namespace mbed {

Expand All @@ -37,7 +38,7 @@ namespace mbed {
* @note Synchronization level: Thread safe
* @ingroup drivers
*/
class FlashIAP {
class FlashIAP : private NonCopyable<FlashIAP> {
public:
FlashIAP();
~FlashIAP();
Expand Down
3 changes: 2 additions & 1 deletion drivers/I2C.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "hal/i2c_api.h"
#include "platform/SingletonPtr.h"
#include "platform/PlatformMutex.h"
#include "platform/NonCopyable.h"

#if DEVICE_I2C_ASYNCH
#include "platform/CThunk.h"
Expand Down Expand Up @@ -53,7 +54,7 @@ namespace mbed {
* @endcode
* @ingroup drivers
*/
class I2C {
class I2C : private NonCopyable<I2C> {

public:
enum RxStatus {
Expand Down
3 changes: 2 additions & 1 deletion drivers/InterruptIn.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "platform/Callback.h"
#include "platform/mbed_critical.h"
#include "platform/mbed_toolchain.h"
#include "platform/NonCopyable.h"

namespace mbed {
/** \addtogroup drivers */
Expand Down Expand Up @@ -56,7 +57,7 @@ namespace mbed {
* @endcode
* @ingroup drivers
*/
class InterruptIn {
class InterruptIn : private NonCopyable<InterruptIn> {

public:

Expand Down
9 changes: 2 additions & 7 deletions drivers/InterruptManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "cmsis.h"
#include "platform/CallChain.h"
#include "platform/PlatformMutex.h"
#include "platform/NonCopyable.h"
#include <string.h>

namespace mbed {
Expand Down Expand Up @@ -53,7 +54,7 @@ namespace mbed {
* @endcode
* @ingroup drivers
*/
class InterruptManager {
class InterruptManager : private NonCopyable<InterruptManager> {
public:
/** Get the instance of InterruptManager Class
*
Expand Down Expand Up @@ -138,12 +139,6 @@ class InterruptManager {
void lock();
void unlock();

// We declare the copy contructor and the assignment operator, but we don't
// implement them. This way, if someone tries to copy/assign our instance,
// he will get an error at compile time.
InterruptManager(const InterruptManager&);
InterruptManager& operator =(const InterruptManager&);

template<typename T>
pFunctionPointer_t add_common(T *tptr, void (T::*mptr)(void), IRQn_Type irq, bool front=false) {
_mutex.lock();
Expand Down
3 changes: 2 additions & 1 deletion drivers/LowPowerTicker.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include "platform/platform.h"
#include "drivers/Ticker.h"
#include "platform/NonCopyable.h"

#if defined (DEVICE_LOWPOWERTIMER) || defined(DOXYGEN_ONLY)

Expand All @@ -31,7 +32,7 @@ namespace mbed {
* @note Synchronization level: Interrupt safe
* @ingroup drivers
*/
class LowPowerTicker : public Ticker {
class LowPowerTicker : public Ticker, private NonCopyable<LowPowerTicker> {

public:
LowPowerTicker() : Ticker(get_lp_ticker_data()) {
Expand Down
3 changes: 2 additions & 1 deletion drivers/LowPowerTimeout.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include "hal/lp_ticker_api.h"
#include "drivers/LowPowerTicker.h"
#include "platform/NonCopyable.h"

namespace mbed {
/** \addtogroup drivers */
Expand All @@ -31,7 +32,7 @@ namespace mbed {
* @note Synchronization level: Interrupt safe
* @ingroup drivers
*/
class LowPowerTimeout : public LowPowerTicker {
class LowPowerTimeout : public LowPowerTicker, private NonCopyable<LowPowerTimeout> {

private:
virtual void handler(void) {
Expand Down
3 changes: 2 additions & 1 deletion drivers/LowPowerTimer.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include "platform/platform.h"
#include "drivers/Timer.h"
#include "platform/NonCopyable.h"

#if defined (DEVICE_LOWPOWERTIMER) || defined(DOXYGEN_ONLY)

Expand All @@ -31,7 +32,7 @@ namespace mbed {
* @note Synchronization level: Interrupt safe
* @ingroup drivers
*/
class LowPowerTimer : public Timer {
class LowPowerTimer : public Timer, private NonCopyable<LowPowerTimer> {

public:
LowPowerTimer() : Timer(get_lp_ticker_data()) {
Expand Down
3 changes: 2 additions & 1 deletion drivers/RawSerial.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include "drivers/SerialBase.h"
#include "hal/serial_api.h"
#include "platform/NonCopyable.h"

namespace mbed {
/** \addtogroup drivers */
Expand Down Expand Up @@ -49,7 +50,7 @@ namespace mbed {
* @endcode
* @ingroup drivers
*/
class RawSerial: public SerialBase {
class RawSerial: public SerialBase, private NonCopyable<RawSerial> {

public:
/** Create a RawSerial port, connected to the specified transmit and receive pins, with the specified baud.
Expand Down
3 changes: 2 additions & 1 deletion drivers/SPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "platform/PlatformMutex.h"
#include "hal/spi_api.h"
#include "platform/SingletonPtr.h"
#include "platform/NonCopyable.h"

#if DEVICE_SPI_ASYNCH
#include "platform/CThunk.h"
Expand Down Expand Up @@ -72,7 +73,7 @@ namespace mbed {
* @endcode
* @ingroup drivers
*/
class SPI {
class SPI : private NonCopyable<SPI> {

public:

Expand Down
3 changes: 2 additions & 1 deletion drivers/SPISlave.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#define MBED_SPISLAVE_H

#include "platform/platform.h"
#include "platform/NonCopyable.h"

#if defined (DEVICE_SPISLAVE) || defined(DOXYGEN_ONLY)

Expand Down Expand Up @@ -52,7 +53,7 @@ namespace mbed {
* @endcode
* @ingroup drivers
*/
class SPISlave {
class SPISlave : private NonCopyable<SPISlave> {

public:

Expand Down
3 changes: 2 additions & 1 deletion drivers/Serial.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "SerialBase.h"
#include "PlatformMutex.h"
#include "serial_api.h"
#include "platform/NonCopyable.h"

namespace mbed {
/** \addtogroup drivers */
Expand All @@ -49,7 +50,7 @@ namespace mbed {
* @endcode
* @ingroup drivers
*/
class Serial : public SerialBase, public Stream {
class Serial : public SerialBase, public Stream, private NonCopyable<Serial> {

public:
#if DEVICE_SERIAL_ASYNCH
Expand Down
3 changes: 2 additions & 1 deletion drivers/SerialBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "Callback.h"
#include "serial_api.h"
#include "mbed_toolchain.h"
#include "platform/NonCopyable.h"

#if DEVICE_SERIAL_ASYNCH
#include "CThunk.h"
Expand All @@ -38,7 +39,7 @@ namespace mbed {
* @note Synchronization level: Set by subclass
* @ingroup drivers
*/
class SerialBase {
class SerialBase : private NonCopyable<SerialBase> {

public:
/** Set the baud rate of the serial port
Expand Down
3 changes: 2 additions & 1 deletion drivers/Ticker.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "drivers/TimerEvent.h"
#include "platform/Callback.h"
#include "platform/mbed_toolchain.h"
#include "platform/NonCopyable.h"

namespace mbed {
/** \addtogroup drivers */
Expand Down Expand Up @@ -59,7 +60,7 @@ namespace mbed {
* @endcode
* @ingroup drivers
*/
class Ticker : public TimerEvent {
class Ticker : public TimerEvent, private NonCopyable<Ticker> {

public:
Ticker() : TimerEvent() {
Expand Down
3 changes: 2 additions & 1 deletion drivers/Timeout.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#define MBED_TIMEOUT_H

#include "drivers/Ticker.h"
#include "platform/NonCopyable.h"

namespace mbed {
/** \addtogroup drivers */
Expand Down Expand Up @@ -52,7 +53,7 @@ namespace mbed {
* @endcode
* @ingroup drivers
*/
class Timeout : public Ticker {
class Timeout : public Ticker, private NonCopyable<Timeout> {

protected:
virtual void handler();
Expand Down
3 changes: 2 additions & 1 deletion drivers/Timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include "platform/platform.h"
#include "hal/ticker_api.h"
#include "platform/NonCopyable.h"

namespace mbed {
/** \addtogroup drivers */
Expand Down Expand Up @@ -46,7 +47,7 @@ namespace mbed {
* @endcode
* @ingroup drivers
*/
class Timer {
class Timer : private NonCopyable<Timer> {

public:
Timer();
Expand Down
Loading