diff --git a/mcc/mcc_generics.h b/mcc/mcc_generics.h index de683b1..7a54101 100644 --- a/mcc/mcc_generics.h +++ b/mcc/mcc_generics.h @@ -167,11 +167,11 @@ static constexpr ErrT mcc_deduce_error(const DErrT& err, const ErrT& default_err } } -template +template static constexpr std::error_code mcc_deduce_error_code(const DErrT& err, const ErrT& default_err) - requires(std::is_error_code_enum_v || std::derived_from) + requires(std::is_error_code_enum_v || std::same_as) { - if constexpr (std::is_error_code_enum_v) { + if constexpr (std::is_error_code_enum_v || std::same_as) { return err; } else { return default_err; diff --git a/mcc/mcc_pzone_container.h b/mcc/mcc_pzone_container.h index 221936a..a6b98df 100644 --- a/mcc/mcc_pzone_container.h +++ b/mcc/mcc_pzone_container.h @@ -46,10 +46,7 @@ namespace mcc struct MccPZoneContainerCategory : public std::error_category { MccPZoneContainerCategory() : std::error_category() {} - const char* name() const noexcept - { - return "ALTITUDE-LIMIT-PZ"; - } + const char* name() const noexcept { return "ALTITUDE-LIMIT-PZ"; } std::string message(int ec) const { @@ -113,41 +110,63 @@ public: { auto sptr = std::make_shared(std::move(zone)); - _inZoneFuncCPT.emplace_back([sptr](const MccCelestialPoint& pt, bool* res) { + _inZoneFuncCPT.emplace_back([sptr](const MccCelestialPoint& pt, bool* res) -> error_t { + auto ret = sptr->inPZone(pt, res); + if (ret) { + return mcc_deduce_error_code(ret, MccPZoneContainerErrorCode::ERROR_INZONE_FUNC); + } + return mcc_deduce_error_code(ret, MccPZoneContainerErrorCode::ERROR_OK); + }); + + _inZoneFuncEHC.emplace_back([sptr](const MccEqtHrzCoords& pt, bool* res) -> error_t { auto ret = sptr->inPZone(pt, res); - return mcc_deduce_error_code(ret, mcc::make_error_code(MccPZoneContainerErrorCode::ERROR_INZONE_FUNC)); - }); + if (ret) { + return mcc_deduce_error_code(ret, MccPZoneContainerErrorCode::ERROR_INZONE_FUNC); + } - _inZoneFuncEHC.emplace_back([sptr](const MccEqtHrzCoords& pt, bool* res) { - auto ret = sptr->inPZone(pt, res); - - return mcc_deduce_error_code(ret, mcc::make_error_code(MccPZoneContainerErrorCode::ERROR_INZONE_FUNC)); + return MccPZoneContainerErrorCode::ERROR_OK; }); - _timeToZoneFuncCPT.emplace_back([sptr](const MccCelestialPoint& pt, duration_t* res_time) { + _timeToZoneFuncCPT.emplace_back([sptr](const MccCelestialPoint& pt, duration_t* res_time) -> error_t { auto ret = sptr->timeToPZone(pt, res_time); - return mcc_deduce_error_code(ret, mcc::make_error_code(MccPZoneContainerErrorCode::ERROR_TIMETO_FUNC)); + if (ret) { + return mcc_deduce_error_code(ret, MccPZoneContainerErrorCode::ERROR_TIMETO_FUNC); + } + + return MccPZoneContainerErrorCode::ERROR_OK; }); - _timeToZoneFuncEHC.emplace_back([sptr](const MccEqtHrzCoords& pt, duration_t* res_time) { + _timeToZoneFuncEHC.emplace_back([sptr](const MccEqtHrzCoords& pt, duration_t* res_time) -> error_t { auto ret = sptr->timeToPZone(pt, res_time); - return mcc_deduce_error_code(ret, mcc::make_error_code(MccPZoneContainerErrorCode::ERROR_TIMETO_FUNC)); + if (ret) { + return mcc_deduce_error_code(ret, MccPZoneContainerErrorCode::ERROR_TIMETO_FUNC); + } + + return MccPZoneContainerErrorCode::ERROR_OK; }); - _timeFromZoneFuncCPT.emplace_back([sptr](const MccCelestialPoint& pt, duration_t* res_time) { + _timeFromZoneFuncCPT.emplace_back([sptr](const MccCelestialPoint& pt, duration_t* res_time) -> error_t { auto ret = sptr->timeFromPZone(pt, res_time); - return mcc_deduce_error_code(ret, mcc::make_error_code(MccPZoneContainerErrorCode::ERROR_TIMEFROM_FUNC)); + if (ret) { + return mcc_deduce_error_code(ret, MccPZoneContainerErrorCode::ERROR_TIMEFROM_FUNC); + } + + return MccPZoneContainerErrorCode::ERROR_OK; }); - _timeFromZoneFuncEHC.emplace_back([sptr](const MccEqtHrzCoords& pt, duration_t* res_time) { + _timeFromZoneFuncEHC.emplace_back([sptr](const MccEqtHrzCoords& pt, duration_t* res_time) -> error_t { auto ret = sptr->timeFromPZone(pt, res_time); - return mcc_deduce_error_code(ret, mcc::make_error_code(MccPZoneContainerErrorCode::ERROR_TIMEFROM_FUNC)); + if (ret) { + return mcc_deduce_error_code(ret, MccPZoneContainerErrorCode::ERROR_TIMEFROM_FUNC); + } + + return MccPZoneContainerErrorCode::ERROR_OK; }); // _intersectZoneFuncCPT.emplace_back([sptr](const MccCelestialPoint& pt, MccCelestialPoint* res_pt) { @@ -164,29 +183,47 @@ public: // mcc::make_error_code(MccPZoneContainerErrorCode::ERROR_INTERSECT_FUNC)); // }); - _intersectZoneFuncCPT2CPT.emplace_back([sptr](const MccCelestialPoint& pt, MccCelestialPoint* res_pt) { + _intersectZoneFuncCPT2CPT.emplace_back( + [sptr](const MccCelestialPoint& pt, MccCelestialPoint* res_pt) -> error_t { + auto ret = sptr->intersectPZone(pt, res_pt); + + if (ret) { + return mcc_deduce_error_code(ret, MccPZoneContainerErrorCode::ERROR_INTERSECT_FUNC); + } + + return MccPZoneContainerErrorCode::ERROR_OK; + }); + + _intersectZoneFuncEHC2CPT.emplace_back([sptr](const MccEqtHrzCoords& pt, MccCelestialPoint* res_pt) -> error_t { auto ret = sptr->intersectPZone(pt, res_pt); - return mcc_deduce_error_code(ret, mcc::make_error_code(MccPZoneContainerErrorCode::ERROR_INTERSECT_FUNC)); + if (ret) { + return mcc_deduce_error_code(ret, MccPZoneContainerErrorCode::ERROR_INTERSECT_FUNC); + } + + return MccPZoneContainerErrorCode::ERROR_OK; }); - _intersectZoneFuncEHC2CPT.emplace_back([sptr](const MccEqtHrzCoords& pt, MccCelestialPoint* res_pt) { + _intersectZoneFuncCPT2EHC.emplace_back([sptr](const MccCelestialPoint& pt, MccEqtHrzCoords* res_pt) -> error_t { auto ret = sptr->intersectPZone(pt, res_pt); - return mcc_deduce_error_code(ret, mcc::make_error_code(MccPZoneContainerErrorCode::ERROR_INTERSECT_FUNC)); + if (ret) { + return mcc_deduce_error_code(ret, MccPZoneContainerErrorCode::ERROR_INTERSECT_FUNC); + } + + return MccPZoneContainerErrorCode::ERROR_OK; }); - _intersectZoneFuncCPT2EHC.emplace_back([sptr](const MccCelestialPoint& pt, MccEqtHrzCoords* res_pt) { + _intersectZoneFuncEHC2EHC.emplace_back([sptr](const MccEqtHrzCoords& pt, MccEqtHrzCoords* res_pt) -> error_t { auto ret = sptr->intersectPZone(pt, res_pt); - return mcc_deduce_error_code(ret, mcc::make_error_code(MccPZoneContainerErrorCode::ERROR_INTERSECT_FUNC)); + if (ret) { + return mcc_deduce_error_code(ret, MccPZoneContainerErrorCode::ERROR_INTERSECT_FUNC); + } + + return MccPZoneContainerErrorCode::ERROR_OK; }); - _intersectZoneFuncEHC2EHC.emplace_back([sptr](const MccEqtHrzCoords& pt, MccEqtHrzCoords* res_pt) { - auto ret = sptr->intersectPZone(pt, res_pt); - - return mcc_deduce_error_code(ret, mcc::make_error_code(MccPZoneContainerErrorCode::ERROR_INTERSECT_FUNC)); - }); return _inZoneFuncCPT.size(); } @@ -211,10 +248,7 @@ public: } - size_t sizePZones() const - { - return _inZoneFuncCPT.size(); - } + size_t sizePZones() const { return _inZoneFuncCPT.size(); } template