Fix the class-memaccess warning
This commit is contained in:
parent
f333013dff
commit
80ee358523
2 changed files with 34 additions and 21 deletions
|
|
@ -15,18 +15,26 @@ ModKey::Parameters::Parameters() noexcept
|
|||
// zero-fill the structure
|
||||
// 1. this ensures that non-used values will be always 0
|
||||
// 2. this makes the object memcmp-comparable
|
||||
std::memset(this, 0, sizeof(*this));
|
||||
std::memset(
|
||||
static_cast<RawParameters*>(this),
|
||||
0, sizeof(RawParameters));
|
||||
}
|
||||
|
||||
ModKey::Parameters::Parameters(const Parameters& other) noexcept
|
||||
{
|
||||
std::memcpy(this, &other, sizeof(*this));
|
||||
std::memcpy(
|
||||
static_cast<RawParameters*>(this),
|
||||
static_cast<const RawParameters*>(&other),
|
||||
sizeof(RawParameters));
|
||||
}
|
||||
|
||||
ModKey::Parameters& ModKey::Parameters::operator=(const Parameters& other) noexcept
|
||||
{
|
||||
if (this != &other)
|
||||
std::memcpy(this, &other, sizeof(*this));
|
||||
std::memcpy(
|
||||
static_cast<RawParameters*>(this),
|
||||
static_cast<const RawParameters*>(&other),
|
||||
sizeof(RawParameters));
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -42,24 +42,7 @@ public:
|
|||
bool isTarget() const noexcept;
|
||||
std::string toString() const;
|
||||
|
||||
struct Parameters {
|
||||
Parameters() noexcept;
|
||||
Parameters(const Parameters& other) noexcept;
|
||||
Parameters& operator=(const Parameters& other) noexcept;
|
||||
|
||||
Parameters(Parameters&&) = delete;
|
||||
Parameters &operator=(Parameters&&) = delete;
|
||||
|
||||
bool operator==(const Parameters& other) const noexcept
|
||||
{
|
||||
return std::memcmp(this, &other, sizeof(*this)) == 0;
|
||||
}
|
||||
|
||||
bool operator!=(const Parameters& other) const noexcept
|
||||
{
|
||||
return std::memcmp(this, &other, sizeof(*this)) != 0;
|
||||
}
|
||||
|
||||
struct RawParameters {
|
||||
union {
|
||||
//! Parameters if this key identifies a CC source
|
||||
struct { uint16_t cc; uint8_t curve, smooth; float step; };
|
||||
|
|
@ -71,6 +54,28 @@ public:
|
|||
};
|
||||
};
|
||||
|
||||
struct Parameters : RawParameters {
|
||||
Parameters() noexcept;
|
||||
Parameters(const Parameters& other) noexcept;
|
||||
Parameters& operator=(const Parameters& other) noexcept;
|
||||
|
||||
Parameters(Parameters&&) = delete;
|
||||
Parameters &operator=(Parameters&&) = delete;
|
||||
|
||||
bool operator==(const Parameters& other) const noexcept
|
||||
{
|
||||
return std::memcmp(
|
||||
static_cast<const RawParameters*>(this),
|
||||
static_cast<const RawParameters*>(&other),
|
||||
sizeof(RawParameters)) == 0;
|
||||
}
|
||||
|
||||
bool operator!=(const Parameters& other) const noexcept
|
||||
{
|
||||
return !operator==(other);
|
||||
}
|
||||
};
|
||||
|
||||
public:
|
||||
bool operator==(const ModKey &other) const noexcept
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue