Skip to content

Commit

Permalink
Fix copy and move objects to comply with "rule of three/five/zero"
Browse files Browse the repository at this point in the history
  • Loading branch information
yh-sb committed Nov 30, 2024
1 parent e88b57f commit f98739b
Show file tree
Hide file tree
Showing 38 changed files with 314 additions and 2 deletions.
8 changes: 8 additions & 0 deletions drivers/include/drivers/dataflash.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@ class dataflash

enum res jedec(jedec_t &jedec);

// Delete copy constructor and copy assignment operator
dataflash(const dataflash&) = delete;
dataflash& operator=(const dataflash&) = delete;

// Delete move constructor and move assignment operator
dataflash(dataflash&&) = delete;
dataflash& operator=(dataflash&&) = delete;

private:
/* 0 bit allways equal to 0
3:1 bits are significant
Expand Down
8 changes: 8 additions & 0 deletions drivers/include/drivers/dht.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ class dht

enum res read(value_t &value);

// Delete copy constructor and copy assignment operator
dht(const dht&) = delete;
dht& operator=(const dht&) = delete;

// Delete move constructor and move assignment operator
dht(dht&&) = delete;
dht& operator=(dht&&) = delete;

private:
drv::singlewire &singlewire;
enum device dht_device;
Expand Down
8 changes: 8 additions & 0 deletions drivers/include/drivers/ds18b20.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ class ds18b20
enum res write_eeprom(uint64_t rom); // 1 ms
enum res restore_eeprom(uint64_t rom); // 1 ms

// Delete copy constructor and copy assignment operator
ds18b20(const ds18b20&) = delete;
ds18b20& operator=(const ds18b20&) = delete;

// Delete move constructor and move assignment operator
ds18b20(ds18b20&&) = delete;
ds18b20& operator=(ds18b20&&) = delete;

private:
#pragma pack(push, 1)
struct scratchpad_t
Expand Down
8 changes: 8 additions & 0 deletions drivers/include/drivers/encoder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ class encoder
void set_callback(std::function<void(int8_t diff)> on_change);
void poll();

// Delete copy constructor and copy assignment operator
encoder(const encoder&) = delete;
encoder& operator=(const encoder&) = delete;

// Delete move constructor and move assignment operator
encoder(encoder&&) = delete;
encoder& operator=(encoder&&) = delete;

private:
periph::gpio &a, &b;
uint8_t prev_state;
Expand Down
8 changes: 8 additions & 0 deletions drivers/include/drivers/gpio_pin_debouncer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ class gpio_pin_debouncer
std::chrono::milliseconds debounce_timeout() const { return _debounce_timeout; }
void debounce_timeout(std::chrono::milliseconds debounce_timeout) { _debounce_timeout = debounce_timeout; }

// Delete copy constructor and copy assignment operator
gpio_pin_debouncer(const gpio_pin_debouncer&) = delete;
gpio_pin_debouncer& operator=(const gpio_pin_debouncer&) = delete;

// Delete move constructor and move assignment operator
gpio_pin_debouncer(gpio_pin_debouncer&&) = delete;
gpio_pin_debouncer& operator=(gpio_pin_debouncer&&) = delete;

private:
bool get_filtered_state();

Expand Down
8 changes: 8 additions & 0 deletions drivers/include/drivers/hd44780.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ class hd44780

void clear();

// Delete copy constructor and copy assignment operator
hd44780(const hd44780&) = delete;
hd44780& operator=(const hd44780&) = delete;

// Delete move constructor and move assignment operator
hd44780(hd44780&&) = delete;
hd44780& operator=(hd44780&&) = delete;

private:
periph::gpio &rs, &rw, &e;
periph::gpio *db[4];
Expand Down
8 changes: 8 additions & 0 deletions drivers/include/drivers/nrf24l01.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,14 @@ class nrf24l01
*/
enum res power_down();

// Delete copy constructor and copy assignment operator
nrf24l01(const nrf24l01&) = delete;
nrf24l01& operator=(const nrf24l01&) = delete;

// Delete move constructor and move assignment operator
nrf24l01(nrf24l01&&) = delete;
nrf24l01& operator=(nrf24l01&&) = delete;

private:
enum class reg : uint8_t
{
Expand Down
10 changes: 9 additions & 1 deletion drivers/include/drivers/onewire.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,15 @@ class onewire
void *read_buff, uint16_t read_size);
enum res read_rom(uint64_t &rom);
//enum res search(uint64_t *rom_list, size_t *rom_list_size);


// Delete copy constructor and copy assignment operator
onewire(const onewire&) = delete;
onewire& operator=(const onewire&) = delete;

// Delete move constructor and move assignment operator
onewire(onewire&&) = delete;
onewire& operator=(onewire&&) = delete;

private:
enum res do_reset();
enum res write_buff(void *buff, uint8_t size);
Expand Down
8 changes: 8 additions & 0 deletions drivers/include/drivers/sd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ class sd
enum res read_cid(drv::sd_regs::cid_t *cid);
enum res read_csd(drv::sd_regs::csd_t *csd);

// Delete copy constructor and copy assignment operator
sd(const sd&) = delete;
sd& operator=(const sd&) = delete;

// Delete move constructor and move assignment operator
sd(sd&&) = delete;
sd& operator=(sd&&) = delete;

protected:
enum cmd_t
{
Expand Down
8 changes: 8 additions & 0 deletions drivers/include/drivers/sd_spi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ class sd_spi : public sd
sd_spi(periph::spi &spi, periph::gpio &cs, periph::gpio *cd = nullptr);
~sd_spi();

// Delete copy constructor and copy assignment operator
sd_spi(const sd_spi&) = delete;
sd_spi& operator=(const sd_spi&) = delete;

// Delete move constructor and move assignment operator
sd_spi(sd_spi&&) = delete;
sd_spi& operator=(sd_spi&&) = delete;

private:
void select(bool is_selected) final;
enum res init_sd() final;
Expand Down
8 changes: 8 additions & 0 deletions drivers/include/drivers/singlewire.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ class singlewire

enum res read(uint8_t *buff, uint16_t size);

// Delete copy constructor and copy assignment operator
singlewire(const singlewire&) = delete;
singlewire& operator=(const singlewire&) = delete;

// Delete move constructor and move assignment operator
singlewire(singlewire&&) = delete;
singlewire& operator=(singlewire&&) = delete;

private:
periph::gpio &gpio;
periph::timer &timer;
Expand Down
10 changes: 9 additions & 1 deletion drivers/src/freertos_wrappers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,15 @@ class semaphore_take
}

bool is_taken;


// Delete copy constructor and copy assignment operator
semaphore_take(const semaphore_take&) = delete;
semaphore_take& operator=(const semaphore_take&) = delete;

// Delete move constructor and move assignment operator
semaphore_take(semaphore_take&&) = delete;
semaphore_take& operator=(semaphore_take&&) = delete;

private:
const SemaphoreHandle_t &_semaphore;
};
Expand Down
8 changes: 8 additions & 0 deletions periph/esp32s3/include/periph/gpio_esp32s3.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ class gpio_esp32s3 : public gpio
enum mode mode() const final { return _mode; }
uint8_t pin() const final { return _pin; }

// Delete copy constructor and copy assignment operator
gpio_esp32s3(const gpio_esp32s3&) = delete;
gpio_esp32s3& operator=(const gpio_esp32s3&) = delete;

// Delete move constructor and move assignment operator
gpio_esp32s3(gpio_esp32s3&&) = delete;
gpio_esp32s3& operator=(gpio_esp32s3&&) = delete;

private:
uint8_t _pin;
enum mode _mode;
Expand Down
8 changes: 8 additions & 0 deletions periph/rp2040/include/periph/gpio_rp2040.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ class gpio_rp2040 : public gpio
enum mode mode() const final { return _mode; }
uint8_t pin() const final { return _pin; }

// Delete copy constructor and copy assignment operator
gpio_rp2040(const gpio_rp2040&) = delete;
gpio_rp2040& operator=(const gpio_rp2040&) = delete;

// Delete move constructor and move assignment operator
gpio_rp2040(gpio_rp2040&&) = delete;
gpio_rp2040& operator=(gpio_rp2040&&) = delete;

private:
uint8_t _pin;
enum mode _mode;
Expand Down
8 changes: 8 additions & 0 deletions periph/stm32f0/include/periph/dma_stm32f0.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ class dma_stm32f0

uint8_t channel() const { return _channel; }

// Delete copy constructor and copy assignment operator
dma_stm32f0(const dma_stm32f0&) = delete;
dma_stm32f0& operator=(const dma_stm32f0&) = delete;

// Delete move constructor and move assignment operator
dma_stm32f0(dma_stm32f0&&) = delete;
dma_stm32f0& operator=(dma_stm32f0&&) = delete;

private:
uint8_t dma;
uint8_t _channel;
Expand Down
8 changes: 8 additions & 0 deletions periph/stm32f0/include/periph/exti_stm32f0.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ class exti_stm32f0 : public exti
void trigger(enum trigger trigger) final;
enum trigger trigger() final { return _trigger; }

// Delete copy constructor and copy assignment operator
exti_stm32f0(const exti_stm32f0&) = delete;
exti_stm32f0& operator=(const exti_stm32f0&) = delete;

// Delete move constructor and move assignment operator
exti_stm32f0(exti_stm32f0&&) = delete;
exti_stm32f0& operator=(exti_stm32f0&&) = delete;

private:
enum trigger _trigger;
gpio_stm32f0 &gpio;
Expand Down
8 changes: 8 additions & 0 deletions periph/stm32f0/include/periph/gpio_stm32f0.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ class gpio_stm32f0 : public gpio
enum port port() const { return _port; }
uint8_t pin() const final { return _pin; }

// Delete copy constructor and copy assignment operator
gpio_stm32f0(const gpio_stm32f0&) = delete;
gpio_stm32f0& operator=(const gpio_stm32f0&) = delete;

// Delete move constructor and move assignment operator
gpio_stm32f0(gpio_stm32f0&&) = delete;
gpio_stm32f0& operator=(gpio_stm32f0&&) = delete;

private:
enum port _port;
uint8_t _pin;
Expand Down
8 changes: 8 additions & 0 deletions periph/stm32f0/include/periph/spi_stm32f0.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ class spi_stm32f0 : public spi

res write_read(const void *write_buff, void *read_buff, uint16_t size, gpio *cs = nullptr) final;

// Delete copy constructor and copy assignment operator
spi_stm32f0(const spi_stm32f0&) = delete;
spi_stm32f0& operator=(const spi_stm32f0&) = delete;

// Delete move constructor and move assignment operator
spi_stm32f0(spi_stm32f0&&) = delete;
spi_stm32f0& operator=(spi_stm32f0&&) = delete;

private:
uint8_t spi;
uint32_t baud;
Expand Down
8 changes: 8 additions & 0 deletions periph/stm32f0/include/periph/timer_stm32f0.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ class timer_stm32f0 : public timer

bool is_expired() const final;

// Delete copy constructor and copy assignment operator
timer_stm32f0(const timer_stm32f0&) = delete;
timer_stm32f0& operator=(const timer_stm32f0&) = delete;

// Delete move constructor and move assignment operator
timer_stm32f0(timer_stm32f0&&) = delete;
timer_stm32f0& operator=(timer_stm32f0&&) = delete;

private:
uint8_t tim;
std::chrono::microseconds _timeout;
Expand Down
8 changes: 8 additions & 0 deletions periph/stm32f0/include/periph/uart_stm32f0.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ class uart_stm32f0 : public uart
res write_read(const void *write_buff, uint16_t write_size, void *read_buff,
uint16_t *read_size, std::chrono::milliseconds timeout = std::chrono::milliseconds::max()) final;

// Delete copy constructor and copy assignment operator
uart_stm32f0(const uart_stm32f0&) = delete;
uart_stm32f0& operator=(const uart_stm32f0&) = delete;

// Delete move constructor and move assignment operator
uart_stm32f0(uart_stm32f0&&) = delete;
uart_stm32f0& operator=(uart_stm32f0&&) = delete;

private:
uint8_t uart;
uint32_t baud;
Expand Down
16 changes: 16 additions & 0 deletions periph/stm32f1/include/periph/adc_stm32f1.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ class adc_onetime_stm32f1 : public adc_onetime
*/
double read() final;

// Delete copy constructor and copy assignment operator
adc_onetime_stm32f1(const adc_onetime_stm32f1&) = delete;
adc_onetime_stm32f1& operator=(const adc_onetime_stm32f1&) = delete;

// Delete move constructor and move assignment operator
adc_onetime_stm32f1(adc_onetime_stm32f1&&) = delete;
adc_onetime_stm32f1& operator=(adc_onetime_stm32f1&&) = delete;

private:
static constexpr uint8_t ch_max_num = 18; // The total number of channels in ADC
uint8_t adc;
Expand Down Expand Up @@ -74,6 +82,14 @@ class adc_cyclic_stm32f1 : public adc_cyclic
void start() final;
void stop() final;

// Delete copy constructor and copy assignment operator
adc_cyclic_stm32f1(const adc_cyclic_stm32f1&) = delete;
adc_cyclic_stm32f1& operator=(const adc_cyclic_stm32f1&) = delete;

// Delete move constructor and move assignment operator
adc_cyclic_stm32f1(adc_cyclic_stm32f1&&) = delete;
adc_cyclic_stm32f1& operator=(adc_cyclic_stm32f1&&) = delete;

private:
static constexpr uint8_t ch_max_num = 18; // The total number of channels in ADC
uint8_t adc;
Expand Down
8 changes: 8 additions & 0 deletions periph/stm32f1/include/periph/dac_stm32f1.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ class dac_stm32f1 : public dac
void set(float voltage) final;
uint16_t get() const final;

// Delete copy constructor and copy assignment operator
dac_stm32f1(const dac_stm32f1&) = delete;
dac_stm32f1& operator=(const dac_stm32f1&) = delete;

// Delete move constructor and move assignment operator
dac_stm32f1(dac_stm32f1&&) = delete;
dac_stm32f1& operator=(dac_stm32f1&&) = delete;

private:
uint8_t dac;
align align;
Expand Down
8 changes: 8 additions & 0 deletions periph/stm32f1/include/periph/dma_stm32f1.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ class dma_stm32f1

uint8_t channel() const { return _channel; }

// Delete copy constructor and copy assignment operator
dma_stm32f1(const dma_stm32f1&) = delete;
dma_stm32f1& operator=(const dma_stm32f1&) = delete;

// Delete move constructor and move assignment operator
dma_stm32f1(dma_stm32f1&&) = delete;
dma_stm32f1& operator=(dma_stm32f1&&) = delete;

private:
uint8_t dma;
uint8_t _channel;
Expand Down
8 changes: 8 additions & 0 deletions periph/stm32f1/include/periph/exti_stm32f1.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ class exti_stm32f1 : public exti
void trigger(enum trigger trigger) final;
enum trigger trigger() final { return _trigger; }

// Delete copy constructor and copy assignment operator
exti_stm32f1(const exti_stm32f1&) = delete;
exti_stm32f1& operator=(const exti_stm32f1&) = delete;

// Delete move constructor and move assignment operator
exti_stm32f1(exti_stm32f1&&) = delete;
exti_stm32f1& operator=(exti_stm32f1&&) = delete;

private:
enum trigger _trigger;
gpio_stm32f1 &gpio;
Expand Down
8 changes: 8 additions & 0 deletions periph/stm32f1/include/periph/gpio_stm32f1.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ class gpio_stm32f1 : public gpio
enum port port() const { return _port; }
uint8_t pin() const final { return _pin; }

// Delete copy constructor and copy assignment operator
gpio_stm32f1(const gpio_stm32f1&) = delete;
gpio_stm32f1& operator=(const gpio_stm32f1&) = delete;

// Delete move constructor and move assignment operator
gpio_stm32f1(gpio_stm32f1&&) = delete;
gpio_stm32f1& operator=(gpio_stm32f1&&) = delete;

private:
enum port _port;
uint8_t _pin;
Expand Down
Loading

0 comments on commit f98739b

Please sign in to comment.