Skip to content

Commit f6d0c29

Browse files
Merge pull request #4594 from pan-/non_copyable
Introduce mbed::NonCopyable traits
2 parents fc39ad1 + 3f388ca commit f6d0c29

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+253
-80
lines changed

drivers/BusIn.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "platform/platform.h"
2020
#include "drivers/DigitalIn.h"
2121
#include "platform/PlatformMutex.h"
22+
#include "platform/NonCopyable.h"
2223

2324
namespace mbed {
2425
/** \addtogroup drivers */
@@ -28,7 +29,7 @@ namespace mbed {
2829
* @note Synchronization level: Thread safe
2930
* @ingroup drivers
3031
*/
31-
class BusIn {
32+
class BusIn : private NonCopyable<BusIn> {
3233

3334
public:
3435
/* Group: Configuration Methods */
@@ -115,12 +116,9 @@ class BusIn {
115116

116117
PlatformMutex _mutex;
117118

118-
/* disallow copy constructor and assignment operators */
119119
private:
120120
virtual void lock();
121121
virtual void unlock();
122-
BusIn(const BusIn&);
123-
BusIn & operator = (const BusIn&);
124122
};
125123

126124
} // namespace mbed

drivers/BusInOut.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include "drivers/DigitalInOut.h"
2020
#include "platform/PlatformMutex.h"
21+
#include "platform/NonCopyable.h"
2122

2223
namespace mbed {
2324
/** \addtogroup drivers */
@@ -27,7 +28,7 @@ namespace mbed {
2728
* @note Synchronization level: Thread safe
2829
* @ingroup drivers
2930
*/
30-
class BusInOut {
31+
class BusInOut : private NonCopyable<BusInOut> {
3132

3233
public:
3334

@@ -135,11 +136,6 @@ class BusInOut {
135136
int _nc_mask;
136137

137138
PlatformMutex _mutex;
138-
139-
/* disallow copy constructor and assignment operators */
140-
private:
141-
BusInOut(const BusInOut&);
142-
BusInOut & operator = (const BusInOut&);
143139
};
144140

145141
} // namespace mbed

drivers/BusOut.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@
1818

1919
#include "drivers/DigitalOut.h"
2020
#include "platform/PlatformMutex.h"
21+
#include "platform/NonCopyable.h"
2122

2223
namespace mbed {
2324
/** \addtogroup drivers */
2425

2526
/** A digital output bus, used for setting the state of a collection of pins
2627
* @ingroup drivers
2728
*/
28-
class BusOut {
29+
class BusOut : private NonCopyable<BusOut> {
2930

3031
public:
3132

@@ -119,11 +120,6 @@ class BusOut {
119120
int _nc_mask;
120121

121122
PlatformMutex _mutex;
122-
123-
/* disallow copy constructor and assignment operators */
124-
private:
125-
BusOut(const BusOut&);
126-
BusOut & operator = (const BusOut&);
127123
};
128124

129125
} // namespace mbed

drivers/CAN.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "hal/can_api.h"
2424
#include "platform/Callback.h"
2525
#include "platform/PlatformMutex.h"
26+
#include "platform/NonCopyable.h"
2627

2728
namespace mbed {
2829
/** \addtogroup drivers */
@@ -78,7 +79,7 @@ class CANMessage : public CAN_Message {
7879
/** A can bus client, used for communicating with can devices
7980
* @ingroup drivers
8081
*/
81-
class CAN {
82+
class CAN : private NonCopyable<CAN> {
8283

8384
public:
8485
/** Creates an CAN interface connected to specific pins.

drivers/Ethernet.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#define MBED_ETHERNET_H
1818

1919
#include "platform/platform.h"
20+
#include "platform/NonCopyable.h"
2021

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

@@ -54,7 +55,7 @@ namespace mbed {
5455
* @endcode
5556
* @ingroup drivers
5657
*/
57-
class Ethernet {
58+
class Ethernet : private NonCopyable<Ethernet> {
5859

5960
public:
6061

drivers/FlashIAP.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "flash_api.h"
2828
#include "platform/SingletonPtr.h"
2929
#include "platform/PlatformMutex.h"
30+
#include "platform/NonCopyable.h"
3031

3132
namespace mbed {
3233

@@ -37,7 +38,7 @@ namespace mbed {
3738
* @note Synchronization level: Thread safe
3839
* @ingroup drivers
3940
*/
40-
class FlashIAP {
41+
class FlashIAP : private NonCopyable<FlashIAP> {
4142
public:
4243
FlashIAP();
4344
~FlashIAP();

drivers/I2C.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "hal/i2c_api.h"
2424
#include "platform/SingletonPtr.h"
2525
#include "platform/PlatformMutex.h"
26+
#include "platform/NonCopyable.h"
2627

2728
#if DEVICE_I2C_ASYNCH
2829
#include "platform/CThunk.h"
@@ -53,7 +54,7 @@ namespace mbed {
5354
* @endcode
5455
* @ingroup drivers
5556
*/
56-
class I2C {
57+
class I2C : private NonCopyable<I2C> {
5758

5859
public:
5960
enum RxStatus {

drivers/InterruptIn.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "platform/Callback.h"
2626
#include "platform/mbed_critical.h"
2727
#include "platform/mbed_toolchain.h"
28+
#include "platform/NonCopyable.h"
2829

2930
namespace mbed {
3031
/** \addtogroup drivers */
@@ -56,7 +57,7 @@ namespace mbed {
5657
* @endcode
5758
* @ingroup drivers
5859
*/
59-
class InterruptIn {
60+
class InterruptIn : private NonCopyable<InterruptIn> {
6061

6162
public:
6263

drivers/InterruptManager.h

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "cmsis.h"
2020
#include "platform/CallChain.h"
2121
#include "platform/PlatformMutex.h"
22+
#include "platform/NonCopyable.h"
2223
#include <string.h>
2324

2425
namespace mbed {
@@ -53,7 +54,7 @@ namespace mbed {
5354
* @endcode
5455
* @ingroup drivers
5556
*/
56-
class InterruptManager {
57+
class InterruptManager : private NonCopyable<InterruptManager> {
5758
public:
5859
/** Get the instance of InterruptManager Class
5960
*
@@ -138,12 +139,6 @@ class InterruptManager {
138139
void lock();
139140
void unlock();
140141

141-
// We declare the copy contructor and the assignment operator, but we don't
142-
// implement them. This way, if someone tries to copy/assign our instance,
143-
// he will get an error at compile time.
144-
InterruptManager(const InterruptManager&);
145-
InterruptManager& operator =(const InterruptManager&);
146-
147142
template<typename T>
148143
pFunctionPointer_t add_common(T *tptr, void (T::*mptr)(void), IRQn_Type irq, bool front=false) {
149144
_mutex.lock();

drivers/LowPowerTicker.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include "platform/platform.h"
2020
#include "drivers/Ticker.h"
21+
#include "platform/NonCopyable.h"
2122

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

@@ -31,7 +32,7 @@ namespace mbed {
3132
* @note Synchronization level: Interrupt safe
3233
* @ingroup drivers
3334
*/
34-
class LowPowerTicker : public Ticker {
35+
class LowPowerTicker : public Ticker, private NonCopyable<LowPowerTicker> {
3536

3637
public:
3738
LowPowerTicker() : Ticker(get_lp_ticker_data()) {

drivers/LowPowerTimeout.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
#include "hal/lp_ticker_api.h"
2424
#include "drivers/LowPowerTicker.h"
25+
#include "platform/NonCopyable.h"
2526

2627
namespace mbed {
2728
/** \addtogroup drivers */
@@ -31,7 +32,7 @@ namespace mbed {
3132
* @note Synchronization level: Interrupt safe
3233
* @ingroup drivers
3334
*/
34-
class LowPowerTimeout : public LowPowerTicker {
35+
class LowPowerTimeout : public LowPowerTicker, private NonCopyable<LowPowerTimeout> {
3536

3637
private:
3738
virtual void handler(void) {

drivers/LowPowerTimer.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include "platform/platform.h"
2020
#include "drivers/Timer.h"
21+
#include "platform/NonCopyable.h"
2122

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

@@ -31,7 +32,7 @@ namespace mbed {
3132
* @note Synchronization level: Interrupt safe
3233
* @ingroup drivers
3334
*/
34-
class LowPowerTimer : public Timer {
35+
class LowPowerTimer : public Timer, private NonCopyable<LowPowerTimer> {
3536

3637
public:
3738
LowPowerTimer() : Timer(get_lp_ticker_data()) {

drivers/RawSerial.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
#include "drivers/SerialBase.h"
2424
#include "hal/serial_api.h"
25+
#include "platform/NonCopyable.h"
2526

2627
namespace mbed {
2728
/** \addtogroup drivers */
@@ -49,7 +50,7 @@ namespace mbed {
4950
* @endcode
5051
* @ingroup drivers
5152
*/
52-
class RawSerial: public SerialBase {
53+
class RawSerial: public SerialBase, private NonCopyable<RawSerial> {
5354

5455
public:
5556
/** Create a RawSerial port, connected to the specified transmit and receive pins, with the specified baud.

drivers/SPI.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "platform/PlatformMutex.h"
2424
#include "hal/spi_api.h"
2525
#include "platform/SingletonPtr.h"
26+
#include "platform/NonCopyable.h"
2627

2728
#if DEVICE_SPI_ASYNCH
2829
#include "platform/CThunk.h"
@@ -72,7 +73,7 @@ namespace mbed {
7273
* @endcode
7374
* @ingroup drivers
7475
*/
75-
class SPI {
76+
class SPI : private NonCopyable<SPI> {
7677

7778
public:
7879

drivers/SPISlave.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#define MBED_SPISLAVE_H
1818

1919
#include "platform/platform.h"
20+
#include "platform/NonCopyable.h"
2021

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

@@ -52,7 +53,7 @@ namespace mbed {
5253
* @endcode
5354
* @ingroup drivers
5455
*/
55-
class SPISlave {
56+
class SPISlave : private NonCopyable<SPISlave> {
5657

5758
public:
5859

drivers/Serial.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "SerialBase.h"
2525
#include "PlatformMutex.h"
2626
#include "serial_api.h"
27+
#include "platform/NonCopyable.h"
2728

2829
namespace mbed {
2930
/** \addtogroup drivers */
@@ -49,7 +50,7 @@ namespace mbed {
4950
* @endcode
5051
* @ingroup drivers
5152
*/
52-
class Serial : public SerialBase, public Stream {
53+
class Serial : public SerialBase, public Stream, private NonCopyable<Serial> {
5354

5455
public:
5556
#if DEVICE_SERIAL_ASYNCH

drivers/SerialBase.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "Callback.h"
2424
#include "serial_api.h"
2525
#include "mbed_toolchain.h"
26+
#include "platform/NonCopyable.h"
2627

2728
#if DEVICE_SERIAL_ASYNCH
2829
#include "CThunk.h"
@@ -38,7 +39,7 @@ namespace mbed {
3839
* @note Synchronization level: Set by subclass
3940
* @ingroup drivers
4041
*/
41-
class SerialBase {
42+
class SerialBase : private NonCopyable<SerialBase> {
4243

4344
public:
4445
/** Set the baud rate of the serial port

drivers/Ticker.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "drivers/TimerEvent.h"
2020
#include "platform/Callback.h"
2121
#include "platform/mbed_toolchain.h"
22+
#include "platform/NonCopyable.h"
2223

2324
namespace mbed {
2425
/** \addtogroup drivers */
@@ -59,7 +60,7 @@ namespace mbed {
5960
* @endcode
6061
* @ingroup drivers
6162
*/
62-
class Ticker : public TimerEvent {
63+
class Ticker : public TimerEvent, private NonCopyable<Ticker> {
6364

6465
public:
6566
Ticker() : TimerEvent() {

drivers/Timeout.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#define MBED_TIMEOUT_H
1818

1919
#include "drivers/Ticker.h"
20+
#include "platform/NonCopyable.h"
2021

2122
namespace mbed {
2223
/** \addtogroup drivers */
@@ -52,7 +53,7 @@ namespace mbed {
5253
* @endcode
5354
* @ingroup drivers
5455
*/
55-
class Timeout : public Ticker {
56+
class Timeout : public Ticker, private NonCopyable<Timeout> {
5657

5758
protected:
5859
virtual void handler();

drivers/Timer.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include "platform/platform.h"
2020
#include "hal/ticker_api.h"
21+
#include "platform/NonCopyable.h"
2122

2223
namespace mbed {
2324
/** \addtogroup drivers */
@@ -46,7 +47,7 @@ namespace mbed {
4647
* @endcode
4748
* @ingroup drivers
4849
*/
49-
class Timer {
50+
class Timer : private NonCopyable<Timer> {
5051

5152
public:
5253
Timer();

0 commit comments

Comments
 (0)