mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-01-03 06:28:27 -04:00
AP_Common: Bitmask: add assignment operator
This commit is contained in:
parent
942555ceb8
commit
db5f933e7a
27
libraries/AP_Common/Bitmask.cpp
Normal file
27
libraries/AP_Common/Bitmask.cpp
Normal file
@ -0,0 +1,27 @@
|
||||
#include "Bitmask.h"
|
||||
|
||||
#include <AP_HAL/AP_HAL.h>
|
||||
|
||||
Bitmask &Bitmask::operator=(const Bitmask&other)
|
||||
{
|
||||
if (other.numwords != numwords || other.numbits != numbits) {
|
||||
#if CONFIG_HAL_BOARD == HAL_BOARD_SITL
|
||||
// we really should not be assigning from a bitmask of a
|
||||
// different number of bits!
|
||||
AP_HAL::panic("attempt to copy from bitmask of different size");
|
||||
#endif
|
||||
// ... but try to cope if it happens in real life:
|
||||
if (numwords != other.numwords) {
|
||||
delete bits;
|
||||
bits = new uint32_t[numwords];
|
||||
numwords = other.numwords;
|
||||
}
|
||||
numbits = other.numbits;
|
||||
}
|
||||
if (other.numwords > 20) {
|
||||
abort();
|
||||
}
|
||||
memcpy(bits, other.bits, 4*other.numwords);
|
||||
|
||||
return *this;
|
||||
}
|
@ -33,7 +33,7 @@ public:
|
||||
delete[] bits;
|
||||
}
|
||||
|
||||
Bitmask &operator=(const Bitmask&other) = delete;
|
||||
Bitmask &operator=(const Bitmask&other);
|
||||
Bitmask(const Bitmask &other) = delete;
|
||||
|
||||
// set given bitnumber
|
||||
@ -119,7 +119,7 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
const uint16_t numbits;
|
||||
const uint16_t numwords;
|
||||
uint16_t numbits;
|
||||
uint16_t numwords;
|
||||
uint32_t *bits;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user