mcc_keyvalue.h: fix MccKeyValueHolder class coping and moving
mcc_pzone.h: add copy and move constructors and operator=
This commit is contained in:
@@ -137,12 +137,7 @@ public:
|
|||||||
|
|
||||||
static constexpr size_t NUMBER_OF_RECORDS = std::tuple_size_v<DESCR_T>;
|
static constexpr size_t NUMBER_OF_RECORDS = std::tuple_size_v<DESCR_T>;
|
||||||
|
|
||||||
MccKeyValueHolder(DESCR_T desc)
|
MccKeyValueHolder(DESCR_T desc) : _keyValue(desc)
|
||||||
: _keyValue(desc), _mapHash{[&desc]<size_t... Is>(std::index_sequence<Is...>) {
|
|
||||||
auto arr = std::array{std::make_pair(utils::FNV1aHash(std::get<Is>(desc).key), Is)...};
|
|
||||||
std::sort(arr.begin(), arr.end(), [](auto const& p1, auto const& p2) { return p1.first < p2.first; });
|
|
||||||
return arr;
|
|
||||||
}(std::make_index_sequence<NUMBER_OF_RECORDS>())}
|
|
||||||
{
|
{
|
||||||
[this]<size_t... I>(std::index_sequence<I...>) {
|
[this]<size_t... I>(std::index_sequence<I...>) {
|
||||||
((_hashes[I] = utils::FNV1aHash(std::get<I>(_keyValue).key)), ...);
|
((_hashes[I] = utils::FNV1aHash(std::get<I>(_keyValue).key)), ...);
|
||||||
@@ -151,6 +146,29 @@ public:
|
|||||||
_changedKey.insert_range(_hashes);
|
_changedKey.insert_range(_hashes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MccKeyValueHolder(MccKeyValueHolder const& other) : MccKeyValueHolder(other._keyValue)
|
||||||
|
{
|
||||||
|
copyInst(other);
|
||||||
|
};
|
||||||
|
|
||||||
|
MccKeyValueHolder(MccKeyValueHolder&& other)
|
||||||
|
{
|
||||||
|
moveInst(std::move(other));
|
||||||
|
};
|
||||||
|
|
||||||
|
MccKeyValueHolder& operator=(MccKeyValueHolder const& other)
|
||||||
|
{
|
||||||
|
copyInst(other);
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
};
|
||||||
|
|
||||||
|
MccKeyValueHolder& operator=(MccKeyValueHolder&& other)
|
||||||
|
{
|
||||||
|
moveInst(std::move(other));
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
};
|
||||||
|
|
||||||
constexpr std::array<std::string_view, NUMBER_OF_RECORDS> keys() const
|
constexpr std::array<std::string_view, NUMBER_OF_RECORDS> keys() const
|
||||||
{
|
{
|
||||||
@@ -463,8 +481,6 @@ protected:
|
|||||||
std::unordered_map<size_t, std::string> _inlineComment{}; // inline (after key=value pair) comment
|
std::unordered_map<size_t, std::string> _inlineComment{}; // inline (after key=value pair) comment
|
||||||
std::unordered_set<size_t> _changedKey{}; // loaded keys (see fromCharRange)
|
std::unordered_set<size_t> _changedKey{}; // loaded keys (see fromCharRange)
|
||||||
|
|
||||||
const std::array<std::pair<size_t, size_t>, NUMBER_OF_RECORDS> _mapHash;
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// NOTE: deduced this is needed here to use "forKey" method in getter and setter (const and non-const contexts)!!!
|
// NOTE: deduced this is needed here to use "forKey" method in getter and setter (const and non-const contexts)!!!
|
||||||
//
|
//
|
||||||
@@ -540,6 +556,57 @@ protected:
|
|||||||
|
|
||||||
return MccKeyValueHolderErrorCode::ERROR_OK;
|
return MccKeyValueHolderErrorCode::ERROR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template <size_t I = 0>
|
||||||
|
void copyInst(MccKeyValueHolder const& other)
|
||||||
|
{
|
||||||
|
if constexpr (I < NUMBER_OF_RECORDS) {
|
||||||
|
// here one needs check equality of the keys!!!
|
||||||
|
if (_hashes[I] == other._hashes[I]) {
|
||||||
|
auto& orec = std::get<I>(other._keyValue);
|
||||||
|
std::get<I>(_keyValue).value = orec.value;
|
||||||
|
std::get<I>(_keyValue).default_value = orec.default_value;
|
||||||
|
std::get<I>(_keyValue).serial_pars = orec.serial_pars;
|
||||||
|
|
||||||
|
if (auto it = other._headComment.find(_hashes[I]); it != other._headComment.end()) {
|
||||||
|
_headComment[_hashes[I]] = it->second;
|
||||||
|
}
|
||||||
|
if (auto it = other._inlineComment.find(_hashes[I]); it != other._inlineComment.end()) {
|
||||||
|
_inlineComment[_hashes[I]] = it->second;
|
||||||
|
}
|
||||||
|
|
||||||
|
_changedKey.insert(_hashes[I]);
|
||||||
|
}
|
||||||
|
|
||||||
|
copyInst<I + 1>(other);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template <size_t I = 0>
|
||||||
|
void moveInst(MccKeyValueHolder&& other)
|
||||||
|
{
|
||||||
|
if constexpr (I < NUMBER_OF_RECORDS) {
|
||||||
|
// here one needs check equality of the keys!!!
|
||||||
|
if (_hashes[I] == other._hashes[I]) {
|
||||||
|
auto& orec = std::get<I>(other._keyValue);
|
||||||
|
std::get<I>(_keyValue).value = std::move(orec.value);
|
||||||
|
std::get<I>(_keyValue).default_value = std::move(orec.default_value);
|
||||||
|
std::get<I>(_keyValue).serial_pars = std::move(orec.serial_pars);
|
||||||
|
|
||||||
|
if (auto it = other._headComment.find(_hashes[I]); it != other._headComment.end()) {
|
||||||
|
_headComment[_hashes[I]] = std::move(it->second);
|
||||||
|
}
|
||||||
|
if (auto it = other._inlineComment.find(_hashes[I]); it != other._inlineComment.end()) {
|
||||||
|
_inlineComment[_hashes[I]] = std::move(it->second);
|
||||||
|
}
|
||||||
|
|
||||||
|
_changedKey.insert(_hashes[I]);
|
||||||
|
}
|
||||||
|
|
||||||
|
moveInst<I + 1>(other);
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <mcc_record_value_c T>
|
template <mcc_record_value_c T>
|
||||||
|
|||||||
@@ -352,6 +352,7 @@ protected:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static_assert(std::is_copy_assignable_v<MccAltLimitPZ<MccAltLimitKind::MIN_ALT_LIMIT>>);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
to be serialized in format:
|
to be serialized in format:
|
||||||
@@ -589,14 +590,32 @@ protected:
|
|||||||
coords.to(xy);
|
coords.to(xy);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if constexpr (AXIS_KIND == MccCoordKind::COORDS_KIND_HA_OBS) {
|
||||||
double x = xy.x();
|
double x = xy.x();
|
||||||
|
|
||||||
if constexpr (AXIS_KIND == MccCoordKind::COORDS_KIND_HA_OBS) {
|
|
||||||
if (from_time) { // timeFromPZone
|
if (from_time) { // timeFromPZone
|
||||||
time_ang = (_minLimit - x) / MCC_SIDERAL_TO_UT1_RATIO; // to UT1 scale
|
time_ang = (_minLimit - x) / MCC_SIDERAL_TO_UT1_RATIO; // to UT1 scale
|
||||||
} else { // timeToPZone
|
} else { // timeToPZone
|
||||||
time_ang = (_maxLimit - x) / MCC_SIDERAL_TO_UT1_RATIO; // to UT1 scale
|
time_ang = (_maxLimit - x) / MCC_SIDERAL_TO_UT1_RATIO; // to UT1 scale
|
||||||
}
|
}
|
||||||
|
} else if constexpr (AXIS_KIND == MccCoordKind::COORDS_KIND_DEC_OBS) {
|
||||||
|
double y = xy.y();
|
||||||
|
|
||||||
|
// TODO: !!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
|
// assume here sideral speed moving! so, observed DEC is near constant
|
||||||
|
if (from_time) { // timeFromPZone
|
||||||
|
if (y < _minLimit || y > _maxLimit) {
|
||||||
|
time_ang = std::numeric_limits<double>::max();
|
||||||
|
} else {
|
||||||
|
time_ang = 0;
|
||||||
|
}
|
||||||
|
} else { // timeToPZone
|
||||||
|
if (y < _minLimit || y > _maxLimit) { // already in the zone
|
||||||
|
time_ang = 0;
|
||||||
|
} else {
|
||||||
|
time_ang = std::numeric_limits<double>::max();
|
||||||
|
}
|
||||||
|
}
|
||||||
} else if constexpr (AXIS_KIND == MccCoordKind::COORDS_KIND_AZ) {
|
} else if constexpr (AXIS_KIND == MccCoordKind::COORDS_KIND_AZ) {
|
||||||
static_assert(false, "NOT IMPLEMENTED YET!!!");
|
static_assert(false, "NOT IMPLEMENTED YET!!!");
|
||||||
} else {
|
} else {
|
||||||
@@ -613,6 +632,8 @@ protected:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static_assert(std::is_copy_assignable_v<MccAxisLimitSwitchPZ<MccCoordKind::COORDS_KIND_HA_OBS>>);
|
||||||
|
static_assert(std::is_copy_assignable_v<MccAxisLimitSwitchPZ<MccCoordKind::COORDS_KIND_DEC_OBS>>);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
to be serialized in format:
|
to be serialized in format:
|
||||||
|
|||||||
Reference in New Issue
Block a user