From fab22963cf29ac8cf3f80fd2aff93b788f5392e0 Mon Sep 17 00:00:00 2001 From: Alexis Duburcq Date: Sat, 23 Dec 2023 20:17:53 +0100 Subject: [PATCH 1/6] [core] Move member initialization in header when possible. --- .../jiminy/core/engine/engine_multi_robot.h | 62 +++++++++---------- core/include/jiminy/core/utilities/helpers.h | 10 +-- core/include/jiminy/core/utilities/random.h | 2 +- core/src/engine/engine_multi_robot.cc | 22 +------ core/src/utilities/helpers.cc | 12 +--- core/src/utilities/random.cc | 19 +++--- 6 files changed, 49 insertions(+), 78 deletions(-) diff --git a/core/include/jiminy/core/engine/engine_multi_robot.h b/core/include/jiminy/core/engine/engine_multi_robot.h index 0b48258a1..e20ee3cde 100644 --- a/core/include/jiminy/core/engine/engine_multi_robot.h +++ b/core/include/jiminy/core/engine/engine_multi_robot.h @@ -69,18 +69,18 @@ namespace jiminy } public: - uint32_t iter; - uint32_t iterFailed; - double t; - double tPrev; + uint32_t iter{0U}; + uint32_t iterFailed{0U}; + double t{0.0}; + double tPrev{0.0}; /// \brief Internal buffer used for Kahan algorithm storing the residual sum of errors. - double tError; - double dt; - double dtLargest; - double dtLargestPrev; - std::vector qSplit; - std::vector vSplit; - std::vector aSplit; + double tError{0.0}; + double dt{0.0}; + double dtLargest{0.0}; + double dtLargestPrev{0.0}; + std::vector qSplit{}; + std::vector vSplit{}; + std::vector aSplit{}; }; class JIMINY_DLLAPI EngineMultiRobot @@ -654,30 +654,30 @@ namespace jiminy const vector_aligned_t & fext); public: - std::unique_ptr engineOptions_; - std::vector systems_; + std::unique_ptr engineOptions_{nullptr}; + std::vector systems_{}; protected: - bool isTelemetryConfigured_; - bool isSimulationRunning_; - GenericConfig engineOptionsHolder_; + bool isTelemetryConfigured_{false}; + bool isSimulationRunning_{false}; + GenericConfig engineOptionsHolder_{}; private: - std::unique_ptr timer_; - contactModel_t contactModel_; - TelemetrySender telemetrySender_; - std::shared_ptr telemetryData_; - std::unique_ptr telemetryRecorder_; - std::unique_ptr stepper_; - double stepperUpdatePeriod_; - StepperState stepperState_; - vector_aligned_t systemsDataHolder_; - ForceCouplingRegister forcesCoupling_; - vector_aligned_t contactForcesPrev_; - vector_aligned_t fPrev_; - vector_aligned_t aPrev_; - std::vector energy_; - std::shared_ptr logData_; + std::unique_ptr timer_{std::make_unique()}; + contactModel_t contactModel_{contactModel_t::UNSUPPORTED}; + TelemetrySender telemetrySender_{}; + std::shared_ptr telemetryData_{nullptr}; + std::unique_ptr telemetryRecorder_{nullptr}; + std::unique_ptr stepper_{nullptr}; + double stepperUpdatePeriod_{INF}; + StepperState stepperState_{}; + vector_aligned_t systemsDataHolder_{}; + ForceCouplingRegister forcesCoupling_{}; + vector_aligned_t contactForcesPrev_{}; + vector_aligned_t fPrev_{}; + vector_aligned_t aPrev_{}; + std::vector energy_{}; + std::shared_ptr logData_{nullptr}; }; } diff --git a/core/include/jiminy/core/utilities/helpers.h b/core/include/jiminy/core/utilities/helpers.h index 4610b4359..e6c27453f 100644 --- a/core/include/jiminy/core/utilities/helpers.h +++ b/core/include/jiminy/core/utilities/helpers.h @@ -24,7 +24,7 @@ namespace jiminy DISABLE_COPY(MutexLocal) public: - MutexLocal(); + MutexLocal() = default; MutexLocal(MutexLocal && other) = default; ~MutexLocal(); @@ -32,7 +32,7 @@ namespace jiminy bool isLocked() const; private: - std::shared_ptr isLocked_; + std::shared_ptr isLocked_{std::make_shared()}; }; class JIMINY_DLLAPI LockGuardLocal @@ -62,9 +62,9 @@ namespace jiminy void toc(); public: - std::chrono::time_point