diff --git a/include/core/capture/capture_base.h b/include/core/capture/capture_base.h index acecc0f7c6a9aecd4de40a34e178b08654f46dc5..387fd71d5c82dd05fc4d14aab782254cca28557b 100644 --- a/include/core/capture/capture_base.h +++ b/include/core/capture/capture_base.h @@ -107,7 +107,7 @@ class CaptureBase : public NodeBase, public std::enable_shared_from_this<Capture void move(FrameBasePtr); void link(FrameBasePtr); template<typename classType, typename... T> - static std::shared_ptr<CaptureBase> emplace(FrameBasePtr _frm_ptr, T&&... all); + static std::shared_ptr<classType> emplace(FrameBasePtr _frm_ptr, T&&... all); protected: SizeEigen computeCalibSize() const; @@ -130,9 +130,9 @@ class CaptureBase : public NodeBase, public std::enable_shared_from_this<Capture namespace wolf{ template<typename classType, typename... T> -std::shared_ptr<CaptureBase> CaptureBase::emplace(FrameBasePtr _frm_ptr, T&&... all) +std::shared_ptr<classType> CaptureBase::emplace(FrameBasePtr _frm_ptr, T&&... all) { - CaptureBasePtr cpt = std::make_shared<classType>(std::forward<T>(all)...); + std::shared_ptr<classType> cpt = std::make_shared<classType>(std::forward<T>(all)...); cpt->link(_frm_ptr); return cpt; } diff --git a/include/core/factor/factor_base.h b/include/core/factor/factor_base.h index b6b7953940279fef26735a06b3d012910590be77..6593383e5137629b94a5f60cf17bc053b0b9991b 100644 --- a/include/core/factor/factor_base.h +++ b/include/core/factor/factor_base.h @@ -165,7 +165,7 @@ class FactorBase : public NodeBase, public std::enable_shared_from_this<FactorBa void link(FeatureBasePtr ftr); template<typename classType, typename... T> - static std::shared_ptr<FactorBase> emplace(FeatureBasePtr _oth_ptr, T&&... all); + static std::shared_ptr<classType> emplace(FeatureBasePtr _oth_ptr, T&&... all); private: @@ -191,9 +191,9 @@ class FactorBase : public NodeBase, public std::enable_shared_from_this<FactorBa namespace wolf{ template<typename classType, typename... T> -std::shared_ptr<FactorBase> FactorBase::emplace(FeatureBasePtr _ftr_ptr, T&&... all) +std::shared_ptr<classType> FactorBase::emplace(FeatureBasePtr _ftr_ptr, T&&... all) { - FactorBasePtr ctr = std::make_shared<classType>(std::forward<T>(all)...); + std::shared_ptr<classType> ctr = std::make_shared<classType>(std::forward<T>(all)...); ctr->link(_ftr_ptr); return ctr; } diff --git a/include/core/feature/feature_base.h b/include/core/feature/feature_base.h index eb4094d1aa0581478aeef801845abd8ee98ca1b1..65e9228f5b48a6c9687c95d3c1d10c5cce58eb3b 100644 --- a/include/core/feature/feature_base.h +++ b/include/core/feature/feature_base.h @@ -98,7 +98,7 @@ class FeatureBase : public NodeBase, public std::enable_shared_from_this<Feature void link(CaptureBasePtr cap_ptr); template<typename classType, typename... T> - static std::shared_ptr<FeatureBase> emplace(CaptureBasePtr _cpt_ptr, T&&... all); + static std::shared_ptr<classType> emplace(CaptureBasePtr _cpt_ptr, T&&... all); protected: @@ -122,9 +122,9 @@ class FeatureBase : public NodeBase, public std::enable_shared_from_this<Feature namespace wolf{ template<typename classType, typename... T> - std::shared_ptr<FeatureBase> FeatureBase::emplace(CaptureBasePtr _cpt_ptr, T&&... all) + std::shared_ptr<classType> FeatureBase::emplace(CaptureBasePtr _cpt_ptr, T&&... all) { - FeatureBasePtr ftr = std::make_shared<classType>(std::forward<T>(all)...); + std::shared_ptr<classType> ftr = std::make_shared<classType>(std::forward<T>(all)...); ftr->link(_cpt_ptr); return ftr; } diff --git a/include/core/frame/frame_base.h b/include/core/frame/frame_base.h index 189b5b5a06ceb0275fa1d11c59ff25a8dad4bc89..e3548b5300b69f29f9bca6992a12f4b2a64c4f04 100644 --- a/include/core/frame/frame_base.h +++ b/include/core/frame/frame_base.h @@ -149,7 +149,7 @@ class FrameBase : public NodeBase, public std::enable_shared_from_this<FrameBase const FactorBasePtrList& getConstrainedByList() const; void link(TrajectoryBasePtr); template<typename classType, typename... T> - static std::shared_ptr<FrameBase> emplace(TrajectoryBasePtr _ptr, T&&... all); + static std::shared_ptr<classType> emplace(TrajectoryBasePtr _ptr, T&&... all); private: @@ -173,9 +173,9 @@ class FrameBase : public NodeBase, public std::enable_shared_from_this<FrameBase namespace wolf { template<typename classType, typename... T> -std::shared_ptr<FrameBase> FrameBase::emplace(TrajectoryBasePtr _ptr, T&&... all) +std::shared_ptr<classType> FrameBase::emplace(TrajectoryBasePtr _ptr, T&&... all) { - FrameBasePtr frm = std::make_shared<classType>(std::forward<T>(all)...); + std::shared_ptr<classType> frm = std::make_shared<classType>(std::forward<T>(all)...); frm->link(_ptr); return frm; } diff --git a/include/core/landmark/landmark_base.h b/include/core/landmark/landmark_base.h index d4843590bd3974d02bcded1360616bac13cf8adb..e33351c3b3bf416baed99b4afa2601cdd923f67e 100644 --- a/include/core/landmark/landmark_base.h +++ b/include/core/landmark/landmark_base.h @@ -93,7 +93,7 @@ class LandmarkBase : public NodeBase, public std::enable_shared_from_this<Landma MapBasePtr getMap(); void link(MapBasePtr); template<typename classType, typename... T> - static std::shared_ptr<LandmarkBase> emplace(MapBasePtr _map_ptr, T&&... all); + static std::shared_ptr<classType> emplace(MapBasePtr _map_ptr, T&&... all); /** \brief Creator for Factory<LandmarkBase, YAML::Node> * Caution: This creator does not set the landmark's anchor frame and sensor. @@ -117,9 +117,9 @@ class LandmarkBase : public NodeBase, public std::enable_shared_from_this<Landma namespace wolf{ template<typename classType, typename... T> -std::shared_ptr<LandmarkBase> LandmarkBase::emplace(MapBasePtr _map_ptr, T&&... all) +std::shared_ptr<classType> LandmarkBase::emplace(MapBasePtr _map_ptr, T&&... all) { - LandmarkBasePtr lmk = std::make_shared<classType>(std::forward<T>(all)...); + std::shared_ptr<classType> lmk = std::make_shared<classType>(std::forward<T>(all)...); lmk->link(_map_ptr); return lmk; } diff --git a/include/core/processor/processor_base.h b/include/core/processor/processor_base.h index 00722d20b22fba998db5c0d85fe33391be9c8b94..95d96f22fe0db0dfcb2a8bf804367831c9c45147 100644 --- a/include/core/processor/processor_base.h +++ b/include/core/processor/processor_base.h @@ -304,7 +304,7 @@ class ProcessorBase : public NodeBase, public std::enable_shared_from_this<Proce void link(SensorBasePtr); template<typename classType, typename... T> - static std::shared_ptr<ProcessorBase> emplace(SensorBasePtr _sen_ptr, T&&... all); + static std::shared_ptr<classType> emplace(SensorBasePtr _sen_ptr, T&&... all); void setVotingAuxActive(bool _voting_active = true); }; @@ -336,9 +336,9 @@ inline void ProcessorBase::setVotingAuxActive(bool _voting_active) namespace wolf { template<typename classType, typename... T> -std::shared_ptr<ProcessorBase> ProcessorBase::emplace(SensorBasePtr _sen_ptr, T&&... all) +std::shared_ptr<classType> ProcessorBase::emplace(SensorBasePtr _sen_ptr, T&&... all) { - ProcessorBasePtr prc = std::make_shared<classType>(std::forward<T>(all)...); + std::shared_ptr<classType> prc = std::make_shared<classType>(std::forward<T>(all)...); prc->link(_sen_ptr); return prc; } diff --git a/include/core/sensor/sensor_base.h b/include/core/sensor/sensor_base.h index fb7444439d51bb68ef0c27d3a48cd7d860973299..78e15380b96fc05bbd818b25aa4211bdeff4e44e 100644 --- a/include/core/sensor/sensor_base.h +++ b/include/core/sensor/sensor_base.h @@ -199,7 +199,7 @@ class SensorBase : public NodeBase, public std::enable_shared_from_this<SensorBa void link(HardwareBasePtr); template<typename classType, typename... T> - static std::shared_ptr<SensorBase> emplace(HardwareBasePtr _hwd_ptr, T&&... all); + static std::shared_ptr<classType> emplace(HardwareBasePtr _hwd_ptr, T&&... all); protected: SizeEigen computeCalibSize() const; @@ -218,9 +218,9 @@ class SensorBase : public NodeBase, public std::enable_shared_from_this<SensorBa namespace wolf{ template<typename classType, typename... T> -std::shared_ptr<SensorBase> SensorBase::emplace(HardwareBasePtr _hwd_ptr, T&&... all) +std::shared_ptr<classType> SensorBase::emplace(HardwareBasePtr _hwd_ptr, T&&... all) { - SensorBasePtr sen = std::make_shared<classType>(std::forward<T>(all)...); + std::shared_ptr<classType> sen = std::make_shared<classType>(std::forward<T>(all)...); sen->link(_hwd_ptr); return sen; } diff --git a/test/gtest_emplace.cpp b/test/gtest_emplace.cpp index 7e32bf8fad08c13274168d176c8767c51f642ae7..f8901a4d9e75edc815913289b697d2a39dd455fe 100644 --- a/test/gtest_emplace.cpp +++ b/test/gtest_emplace.cpp @@ -55,6 +55,11 @@ TEST(Emplace, Processor) ASSERT_EQ(P, P->getHardware()->getSensorList().front()->getProcessorList().front()->getSensor()->getProblem()); ASSERT_EQ(sen, sen->getProcessorList().front()->getSensor()); ASSERT_EQ(prc, sen->getProcessorList().front()); + + SensorBasePtr sen2 = SensorBase::emplace<SensorBase>(P->getHardware(), "Dummy", nullptr, nullptr, nullptr, 2, false); + ProcessorOdom2DPtr prc2 = ProcessorOdom2D::emplace<ProcessorOdom2D>(sen2, std::make_shared<ProcessorParamsOdom2D>()); + ASSERT_EQ(sen2, sen2->getProcessorList().front()->getSensor()); + ASSERT_EQ(prc2, sen2->getProcessorList().front()); } TEST(Emplace, Capture) @@ -119,7 +124,7 @@ TEST(Emplace, EmplaceDerived) auto sen = SensorBase::emplace<SensorOdom2D>(P->getHardware(), Eigen::VectorXs(3), IntrinsicsOdom2D()); auto cov = Eigen::MatrixXs::Identity(2,2); auto cpt = CaptureBase::emplace<CaptureOdom2D>(frm, TimeStamp(0), sen, Eigen::VectorXs(2), cov, frm); - auto cpt2 = std::static_pointer_cast<CaptureOdom2D>(cpt); + // auto cpt2 = std::static_pointer_cast<CaptureOdom2D>(cpt); auto m = Eigen::Matrix<Scalar,9,6>(); for(int i = 0; i < 9; i++) for(int j = 0; j < 6; j++) @@ -133,6 +138,20 @@ TEST(Emplace, Nullpointer) { CaptureBase::emplace<wolf::CaptureBase>(nullptr, "DUMMY", 1.2, nullptr); } +TEST(Emplace, ReturnDerived) +{ + ProblemPtr P = Problem::create("POV", 3); + + ASSERT_NE(P->getTrajectory(), nullptr); + auto frm = FrameBase::emplace<FrameBase>(P->getTrajectory(), KEY, TimeStamp(0), std::make_shared<StateBlock>(2,true), std::make_shared<StateBlock>(2,true)); + auto cpt = CaptureBase::emplace<CaptureBase>(frm, "Dummy", TimeStamp(0), nullptr, nullptr, nullptr, nullptr); + auto cov = Eigen::MatrixXs::Identity(2,2); + auto ftr = FeatureBase::emplace<FeatureOdom2D>(cpt, Eigen::VectorXs(2), cov); + auto cnt = FactorBase::emplace<FactorOdom2D>(ftr, ftr, frm); + + FactorOdom2DPtr fac = FactorBase::emplace<FactorOdom2D>(ftr, ftr, frm); + +} int main(int argc, char **argv) { testing::InitGoogleTest(&argc, argv);