diff --git a/include/mcc/mcc_keyvalue.h b/include/mcc/mcc_keyvalue.h index ca84f12..418f7b5 100644 --- a/include/mcc/mcc_keyvalue.h +++ b/include/mcc/mcc_keyvalue.h @@ -137,12 +137,7 @@ public: static constexpr size_t NUMBER_OF_RECORDS = std::tuple_size_v; - MccKeyValueHolder(DESCR_T desc) - : _keyValue(desc), _mapHash{[&desc](std::index_sequence) { - auto arr = std::array{std::make_pair(utils::FNV1aHash(std::get(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())} + MccKeyValueHolder(DESCR_T desc) : _keyValue(desc) { [this](std::index_sequence) { ((_hashes[I] = utils::FNV1aHash(std::get(_keyValue).key)), ...); @@ -151,6 +146,29 @@ public: _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 keys() const { @@ -463,8 +481,6 @@ protected: std::unordered_map _inlineComment{}; // inline (after key=value pair) comment std::unordered_set _changedKey{}; // loaded keys (see fromCharRange) - const std::array, NUMBER_OF_RECORDS> _mapHash; - // // 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; } + + + template + 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(other._keyValue); + std::get(_keyValue).value = orec.value; + std::get(_keyValue).default_value = orec.default_value; + std::get(_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(other); + } + } + + template + 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(other._keyValue); + std::get(_keyValue).value = std::move(orec.value); + std::get(_keyValue).default_value = std::move(orec.default_value); + std::get(_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(other); + } + } }; template diff --git a/include/mcc/mcc_pzone.h b/include/mcc/mcc_pzone.h index e089524..18eef99 100644 --- a/include/mcc/mcc_pzone.h +++ b/include/mcc/mcc_pzone.h @@ -352,6 +352,7 @@ protected: } }; +static_assert(std::is_copy_assignable_v>); /* to be serialized in format: @@ -589,14 +590,32 @@ protected: coords.to(xy); } - double x = xy.x(); - if constexpr (AXIS_KIND == MccCoordKind::COORDS_KIND_HA_OBS) { + double x = xy.x(); + if (from_time) { // timeFromPZone time_ang = (_minLimit - x) / MCC_SIDERAL_TO_UT1_RATIO; // to UT1 scale } else { // timeToPZone 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::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::max(); + } + } } else if constexpr (AXIS_KIND == MccCoordKind::COORDS_KIND_AZ) { static_assert(false, "NOT IMPLEMENTED YET!!!"); } else { @@ -613,6 +632,8 @@ protected: } }; +static_assert(std::is_copy_assignable_v>); +static_assert(std::is_copy_assignable_v>); /* to be serialized in format: