no default construct

This commit is contained in:
DashyFox 2024-08-29 14:14:46 +03:00
parent 784365181e
commit 2f4ac3ddf8
6 changed files with 188 additions and 13 deletions

View File

@ -1,19 +1,22 @@
#include "IR_Decoder.h" #include "IR_Decoder.h"
std::list<IR_Decoder*>& IR_Decoder::get_dec_list() // определение функции std::list<IR_Decoder *> &IR_Decoder::get_dec_list() // определение функции
{ {
static std::list<IR_Decoder*> dec_list; // статическая локальная переменная static std::list<IR_Decoder *> dec_list; // статическая локальная переменная
return dec_list; // возвращается ссылка на переменную return dec_list; // возвращается ссылка на переменную
} }
IR_Decoder::IR_Decoder(){}; // IR_Decoder::IR_Decoder() {};
IR_Decoder::IR_Decoder(const uint8_t pin, uint16_t addr, IR_Encoder *encPair) IR_Decoder::IR_Decoder(const uint8_t pin, uint16_t addr, IR_Encoder *encPair)
: IR_DecoderRaw(pin, addr, encPair) : IR_DecoderRaw(pin, addr, encPair)
{ {
get_dec_list().push_back(this); get_dec_list().push_back(this);
}; };
void IR_Decoder::operator()() { isr(); } std::function<void()> IR_Decoder::operator()()
{
return std::bind(&IR_Decoder::isr, this);
}
IR_Decoder::~IR_Decoder() IR_Decoder::~IR_Decoder()
{ {

View File

@ -24,10 +24,10 @@ public:
PacketTypes::Request gotRequest; PacketTypes::Request gotRequest;
PacketTypes::BasePack gotRaw; PacketTypes::BasePack gotRaw;
IR_Decoder(); // IR_Decoder();
IR_Decoder(const uint8_t pin, uint16_t addr, IR_Encoder *encPair = nullptr); IR_Decoder(const uint8_t pin, uint16_t addr, IR_Encoder *encPair = nullptr);
void operator()() ; std::function<void()> operator()();
~IR_Decoder(); ~IR_Decoder();

View File

@ -1,7 +1,6 @@
#include "IR_DecoderRaw.h" #include "IR_DecoderRaw.h"
#include "IR_Encoder.h" #include "IR_Encoder.h"
IR_DecoderRaw::IR_DecoderRaw(){};
IR_DecoderRaw::IR_DecoderRaw(const uint8_t pin, uint16_t addr, IR_Encoder *encPair) : encoder(encPair) IR_DecoderRaw::IR_DecoderRaw(const uint8_t pin, uint16_t addr, IR_Encoder *encPair) : encoder(encPair)
{ {
setPin(pin); setPin(pin);
@ -651,3 +650,179 @@ inline void IR_DecoderRaw::infoPulse(uint8_t pin, uint8_t count)
} }
} }
#endif #endif
// Конструктор копирования
IR_DecoderRaw::IR_DecoderRaw(const IR_DecoderRaw& other)
: packInfo(other.packInfo),
encoder(other.encoder), // Если IR_Encoder имеет безопасный копируемый указатель
isAvailable(other.isAvailable),
packSize(other.packSize),
crcValue(other.crcValue),
isPairSending(other.isPairSending),
isRecive(other.isRecive),
isPreamb(other.isPreamb),
isSubBufferOverflow(other.isSubBufferOverflow),
isBufferOverflow(other.isBufferOverflow),
isWrongPack(other.isWrongPack),
riseSyncTime(other.riseSyncTime),
currentSubBufferIndex(other.currentSubBufferIndex),
subBuffer(other.subBuffer), // Копирование буфера
lastFront(other.lastFront),
firstUnHandledFront(other.firstUnHandledFront),
prevRise(other.prevRise),
prevPrevRise(other.prevPrevRise),
prevFall(other.prevFall),
prevPrevFall(other.prevPrevFall),
risePeriod(other.risePeriod),
highTime(other.highTime),
lowTime(other.lowTime),
oldTime(other.oldTime),
wrongCounter(other.wrongCounter),
highCount(other.highCount),
lowCount(other.lowCount),
allCount(other.allCount),
errorCounter(other.errorCounter),
preambFrontCounter(other.preambFrontCounter),
bufBitPos(other.bufBitPos),
isData(other.isData),
i_dataBuffer(other.i_dataBuffer),
nextControlBit(other.nextControlBit),
i_syncBit(other.i_syncBit),
err_syncBit(other.err_syncBit)
{
// Специфическое копирование, если нужно
}
// Оператор копирующего присваивания
IR_DecoderRaw& IR_DecoderRaw::operator=(const IR_DecoderRaw& other) {
if (this != &other) { // Проверка на самоприсваивание
packInfo = other.packInfo;
encoder = other.encoder;
isAvailable = other.isAvailable;
packSize = other.packSize;
crcValue = other.crcValue;
isPairSending = other.isPairSending;
isRecive = other.isRecive;
isPreamb = other.isPreamb;
isSubBufferOverflow = other.isSubBufferOverflow;
isBufferOverflow = other.isBufferOverflow;
isWrongPack = other.isWrongPack;
riseSyncTime = other.riseSyncTime;
currentSubBufferIndex = other.currentSubBufferIndex;
subBuffer = other.subBuffer;
lastFront = other.lastFront;
firstUnHandledFront = other.firstUnHandledFront;
prevRise = other.prevRise;
prevPrevRise = other.prevPrevRise;
prevFall = other.prevFall;
prevPrevFall = other.prevPrevFall;
risePeriod = other.risePeriod;
highTime = other.highTime;
lowTime = other.lowTime;
oldTime = other.oldTime;
wrongCounter = other.wrongCounter;
highCount = other.highCount;
lowCount = other.lowCount;
allCount = other.allCount;
errorCounter = other.errorCounter;
preambFrontCounter = other.preambFrontCounter;
bufBitPos = other.bufBitPos;
isData = other.isData;
i_dataBuffer = other.i_dataBuffer;
nextControlBit = other.nextControlBit;
i_syncBit = other.i_syncBit;
err_syncBit = other.err_syncBit;
}
return *this;
}
// Конструктор перемещения
IR_DecoderRaw::IR_DecoderRaw(IR_DecoderRaw&& other)
: packInfo(std::move(other.packInfo)),
encoder(other.encoder),
isAvailable(other.isAvailable),
packSize(other.packSize),
crcValue(other.crcValue),
isPairSending(other.isPairSending),
isRecive(other.isRecive),
isPreamb(other.isPreamb),
isSubBufferOverflow(other.isSubBufferOverflow),
isBufferOverflow(other.isBufferOverflow),
isWrongPack(other.isWrongPack),
riseSyncTime(other.riseSyncTime),
currentSubBufferIndex(other.currentSubBufferIndex),
subBuffer(std::move(other.subBuffer)),
lastFront(other.lastFront),
firstUnHandledFront(other.firstUnHandledFront),
prevRise(other.prevRise),
prevPrevRise(other.prevPrevRise),
prevFall(other.prevFall),
prevPrevFall(other.prevPrevFall),
risePeriod(other.risePeriod),
highTime(other.highTime),
lowTime(other.lowTime),
oldTime(other.oldTime),
wrongCounter(other.wrongCounter),
highCount(other.highCount),
lowCount(other.lowCount),
allCount(other.allCount),
errorCounter(other.errorCounter),
preambFrontCounter(other.preambFrontCounter),
bufBitPos(other.bufBitPos),
isData(other.isData),
i_dataBuffer(other.i_dataBuffer),
nextControlBit(other.nextControlBit),
i_syncBit(other.i_syncBit),
err_syncBit(other.err_syncBit)
{
other.encoder = nullptr;
other.lastFront = nullptr;
other.firstUnHandledFront = nullptr;
}
// Оператор перемещающего присваивания
IR_DecoderRaw& IR_DecoderRaw::operator=(IR_DecoderRaw&& other) {
if (this != &other) { // Проверка на самоприсваивание
packInfo = std::move(other.packInfo);
encoder = other.encoder;
isAvailable = other.isAvailable;
packSize = other.packSize;
crcValue = other.crcValue;
isPairSending = other.isPairSending;
isRecive = other.isRecive;
isPreamb = other.isPreamb;
isSubBufferOverflow = other.isSubBufferOverflow;
isBufferOverflow = other.isBufferOverflow;
isWrongPack = other.isWrongPack;
riseSyncTime = other.riseSyncTime;
currentSubBufferIndex = other.currentSubBufferIndex;
subBuffer = std::move(other.subBuffer);
lastFront = other.lastFront;
firstUnHandledFront = other.firstUnHandledFront;
prevRise = other.prevRise;
prevPrevRise = other.prevPrevRise;
prevFall = other.prevFall;
prevPrevFall = other.prevPrevFall;
risePeriod = other.risePeriod;
highTime = other.highTime;
lowTime = other.lowTime;
oldTime = other.oldTime;
wrongCounter = other.wrongCounter;
highCount = other.highCount;
lowCount = other.lowCount;
allCount = other.allCount;
errorCounter = other.errorCounter;
preambFrontCounter = other.preambFrontCounter;
bufBitPos = other.bufBitPos;
isData = other.isData;
i_dataBuffer = other.i_dataBuffer;
nextControlBit = other.nextControlBit;
i_syncBit = other.i_syncBit;
err_syncBit = other.err_syncBit;
other.encoder = nullptr;
other.lastFront = nullptr;
other.firstUnHandledFront = nullptr;
}
return *this;
}

View File

@ -36,7 +36,6 @@ protected:
public: public:
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
IR_DecoderRaw();
/// @brief Конструктор /// @brief Конструктор
/// @param pin Номер вывода прерывания/данных от приёмника (2 или 3 для atmega 328p) /// @param pin Номер вывода прерывания/данных от приёмника (2 или 3 для atmega 328p)
/// @param addr Адрес приёмника /// @param addr Адрес приёмника

View File

@ -11,7 +11,6 @@ std::list<IR_Encoder*>& IR_Encoder::get_enc_list() // определение ф
return dec_list; // возвращается ссылка на переменную return dec_list; // возвращается ссылка на переменную
} }
IR_Encoder::IR_Encoder(){};
IR_Encoder::IR_Encoder(uint8_t pin, uint16_t addr, IR_DecoderRaw *decPair) IR_Encoder::IR_Encoder(uint8_t pin, uint16_t addr, IR_DecoderRaw *decPair)
{ {

View File

@ -12,7 +12,6 @@ public:
private: private:
uint16_t id; /// @brief Адрес передатчика uint16_t id; /// @brief Адрес передатчика
public: public:
IR_Encoder();
/// @brief Класс передатчика /// @brief Класс передатчика
/// @param addr Адрес передатчика /// @param addr Адрес передатчика
/// @param pin Вывод передатчика /// @param pin Вывод передатчика