From 6ef159334ea6f6b51d44ae63f0fc44879cc1ece1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Joan=20Vallv=C3=A9=20Navarro?= <jvallve@iri.upc.edu>
Date: Mon, 27 May 2019 10:56:02 +0200
Subject: [PATCH] addXXX is now protected, added corr. friends

---
 include/core/capture/capture_base.h       | 6 +++---
 include/core/feature/feature_base.h       | 8 ++++++--
 include/core/frame/frame_base.h           | 7 ++++++-
 include/core/hardware/hardware_base.h     | 6 +++++-
 include/core/landmark/landmark_base.h     | 4 ++--
 include/core/map/map_base.h               | 6 +++++-
 include/core/sensor/sensor_base.h         | 7 ++++++-
 include/core/trajectory/trajectory_base.h | 6 ++++++
 src/capture/capture_base.cpp              | 9 ---------
 9 files changed, 39 insertions(+), 20 deletions(-)

diff --git a/include/core/capture/capture_base.h b/include/core/capture/capture_base.h
index 7864c46b9..a8d5d971f 100644
--- a/include/core/capture/capture_base.h
+++ b/include/core/capture/capture_base.h
@@ -19,6 +19,8 @@ namespace wolf{
 //class CaptureBase
 class CaptureBase : public NodeBase, public std::enable_shared_from_this<CaptureBase>
 {
+    friend FactorBase;
+
     private:
         FrameBaseWPtr   frame_ptr_;
         FeatureBasePtrList feature_list_;
@@ -61,10 +63,7 @@ class CaptureBase : public NodeBase, public std::enable_shared_from_this<Capture
         void unlinkFromFrame(){frame_ptr_.reset();}
 
         virtual void setProblem(ProblemPtr _problem) final;
-
-        FeatureBasePtr addFeature(FeatureBasePtr _ft_ptr);
         FeatureBasePtrList& getFeatureList();
-        void addFeatureList(FeatureBasePtrList& _new_ft_list);
 
         void getFactorList(FactorBasePtrList& _fac_list);
 
@@ -106,6 +105,7 @@ class CaptureBase : public NodeBase, public std::enable_shared_from_this<Capture
     protected:
         SizeEigen computeCalibSize() const;
 
+        FeatureBasePtr addFeature(FeatureBasePtr _ft_ptr);
     private:
         void updateCalibSize();
 };
diff --git a/include/core/feature/feature_base.h b/include/core/feature/feature_base.h
index 72a2be8a4..69d4d4507 100644
--- a/include/core/feature/feature_base.h
+++ b/include/core/feature/feature_base.h
@@ -18,6 +18,8 @@ namespace wolf {
 //class FeatureBase
 class FeatureBase : public NodeBase, public std::enable_shared_from_this<FeatureBase>
 {
+    friend FactorBase;
+
     private:
         CaptureBaseWPtr capture_ptr_;
         FactorBasePtrList factor_list_;
@@ -85,7 +87,6 @@ class FeatureBase : public NodeBase, public std::enable_shared_from_this<Feature
         CaptureBasePtr getCapture() const;
         void setCapture(CaptureBasePtr _cap_ptr){capture_ptr_ = _cap_ptr;}
 
-        FactorBasePtr addFactor(FactorBasePtr _co_ptr);
         FactorBasePtrList& getFactorList();
 
         virtual FactorBasePtr addConstrainedBy(FactorBasePtr _fac_ptr);
@@ -99,8 +100,11 @@ class FeatureBase : public NodeBase, public std::enable_shared_from_this<Feature
         template<typename classType, typename... T>
         static std::shared_ptr<FeatureBase> emplace(CaptureBasePtr _cpt_ptr, T&&... all);
 
-    private:
+
+    protected:
+
         Eigen::MatrixXs computeSqrtUpper(const Eigen::MatrixXs& _M) const;
+        FactorBasePtr addFactor(FactorBasePtr _co_ptr);
 };
 
 }
diff --git a/include/core/frame/frame_base.h b/include/core/frame/frame_base.h
index 44e1cfbd2..b713fb93b 100644
--- a/include/core/frame/frame_base.h
+++ b/include/core/frame/frame_base.h
@@ -30,6 +30,9 @@ typedef enum
 //class FrameBase
 class FrameBase : public NodeBase, public std::enable_shared_from_this<FrameBase>
 {
+    friend CaptureBase;
+    friend FactorBase;
+
     private:
         TrajectoryBaseWPtr trajectory_ptr_;
         CaptureBasePtrList capture_list_;
@@ -133,7 +136,6 @@ class FrameBase : public NodeBase, public std::enable_shared_from_this<FrameBase
         FrameBasePtr getNextFrame() const;
 
         CaptureBasePtrList& getCaptureList();
-        CaptureBasePtr addCapture(CaptureBasePtr _capt_ptr);
         CaptureBasePtr getCaptureOf(const SensorBasePtr _sensor_ptr);
         CaptureBasePtr getCaptureOf(const SensorBasePtr _sensor_ptr, const std::string& type);
         CaptureBasePtrList getCapturesOf(const SensorBasePtr _sensor_ptr);
@@ -150,6 +152,9 @@ class FrameBase : public NodeBase, public std::enable_shared_from_this<FrameBase
         template<typename classType, typename... T>
         static std::shared_ptr<FrameBase> emplace(TrajectoryBasePtr _ptr, T&&... all);
 
+    protected:
+
+        CaptureBasePtr addCapture(CaptureBasePtr _capt_ptr);
     public:
         static FrameBasePtr create_PO_2D (const FrameType & _tp,
                                           const TimeStamp& _ts,
diff --git a/include/core/hardware/hardware_base.h b/include/core/hardware/hardware_base.h
index 1b4149a6d..07c116e81 100644
--- a/include/core/hardware/hardware_base.h
+++ b/include/core/hardware/hardware_base.h
@@ -16,6 +16,8 @@ namespace wolf {
 //class HardwareBase
 class HardwareBase : public NodeBase, public std::enable_shared_from_this<HardwareBase>
 {
+    friend SensorBase;
+
     private:
         SensorBasePtrList sensor_list_;
 
@@ -23,8 +25,10 @@ class HardwareBase : public NodeBase, public std::enable_shared_from_this<Hardwa
         HardwareBase();
         virtual ~HardwareBase();
 
-        virtual SensorBasePtr addSensor(SensorBasePtr _sensor_ptr);
         SensorBasePtrList& getSensorList();
+
+    protected:
+        virtual SensorBasePtr addSensor(SensorBasePtr _sensor_ptr);
 };
 
 } // namespace wolf
diff --git a/include/core/landmark/landmark_base.h b/include/core/landmark/landmark_base.h
index 839ee0f97..a772f69dd 100644
--- a/include/core/landmark/landmark_base.h
+++ b/include/core/landmark/landmark_base.h
@@ -44,8 +44,8 @@ class LandmarkBase : public NodeBase, public std::enable_shared_from_this<Landma
          * \param _o_ptr StateBlock pointer to the orientation (default: nullptr)
          *
          **/
-    LandmarkBase(const std::string& _type, StateBlockPtr _p_ptr, StateBlockPtr _o_ptr = nullptr);
-    LandmarkBase(MapBaseWPtr _ptr, const std::string& _type, StateBlockPtr _p_ptr, StateBlockPtr _o_ptr = nullptr);
+        LandmarkBase(const std::string& _type, StateBlockPtr _p_ptr, StateBlockPtr _o_ptr = nullptr);
+        LandmarkBase(MapBaseWPtr _ptr, const std::string& _type, StateBlockPtr _p_ptr, StateBlockPtr _o_ptr = nullptr);
         virtual ~LandmarkBase();
         virtual void remove();
         virtual YAML::Node saveToYaml() const;
diff --git a/include/core/map/map_base.h b/include/core/map/map_base.h
index 90ad78545..ee6d24528 100644
--- a/include/core/map/map_base.h
+++ b/include/core/map/map_base.h
@@ -19,6 +19,8 @@ namespace wolf {
 //class MapBase
 class MapBase : public NodeBase, public std::enable_shared_from_this<MapBase>
 {
+    friend LandmarkBase;
+
     private:
         LandmarkBasePtrList landmark_list_;
 
@@ -26,8 +28,10 @@ class MapBase : public NodeBase, public std::enable_shared_from_this<MapBase>
         MapBase();
         ~MapBase();
         
+    protected:
         virtual LandmarkBasePtr addLandmark(LandmarkBasePtr _landmark_ptr);
-        virtual void addLandmarkList(LandmarkBasePtrList& _landmark_list);
+
+    public:
         LandmarkBasePtrList& getLandmarkList();
         
         void load(const std::string& _map_file_yaml);
diff --git a/include/core/sensor/sensor_base.h b/include/core/sensor/sensor_base.h
index 2e05d2fe5..0f1678fd1 100644
--- a/include/core/sensor/sensor_base.h
+++ b/include/core/sensor/sensor_base.h
@@ -29,6 +29,9 @@ struct IntrinsicsBase: public ParamsBase
 
 class SensorBase : public NodeBase, public std::enable_shared_from_this<SensorBase>
 {
+    friend Problem;
+    friend ProcessorBase;
+
     private:
         HardwareBaseWPtr hardware_ptr_;
         ProcessorBasePtrList processor_list_;
@@ -95,9 +98,11 @@ class SensorBase : public NodeBase, public std::enable_shared_from_this<SensorBa
         virtual void setProblem(ProblemPtr _problem) final;
 
         HardwareBasePtr getHardware();
+    protected:
         void setHardware(const HardwareBasePtr _hw_ptr);
-
         ProcessorBasePtr addProcessor(ProcessorBasePtr _proc_ptr);
+
+    public:
         ProcessorBasePtrList& getProcessorList();
 
         CaptureBasePtr lastKeyCapture(void);
diff --git a/include/core/trajectory/trajectory_base.h b/include/core/trajectory/trajectory_base.h
index 0ee9c37d5..339a41b3d 100644
--- a/include/core/trajectory/trajectory_base.h
+++ b/include/core/trajectory/trajectory_base.h
@@ -20,6 +20,8 @@ namespace wolf {
 //class TrajectoryBase
 class TrajectoryBase : public NodeBase, public std::enable_shared_from_this<TrajectoryBase>
 {
+    friend FrameBase;
+
     private:
         std::list<FrameBasePtr> frame_list_;
 
@@ -47,6 +49,10 @@ class TrajectoryBase : public NodeBase, public std::enable_shared_from_this<Traj
         void sortFrame(FrameBasePtr _frm_ptr);
         void updateLastFrames();
 
+    protected:
+        FrameBasePtr addFrame(FrameBasePtr _frame_ptr);
+
+    public:
         // factors
         void getFactorList(FactorBasePtrList & _fac_list);
 
diff --git a/src/capture/capture_base.cpp b/src/capture/capture_base.cpp
index 78904aa8b..d95ef15d9 100644
--- a/src/capture/capture_base.cpp
+++ b/src/capture/capture_base.cpp
@@ -102,16 +102,7 @@ FeatureBasePtr CaptureBase::addFeature(FeatureBasePtr _ft_ptr)
     return _ft_ptr;
 }
 
-void CaptureBase::addFeatureList(FeatureBasePtrList& _new_ft_list)
 {
-    for (FeatureBasePtr feature_ptr : _new_ft_list)
-    {
-        feature_ptr->setCapture(shared_from_this());
-        if (getProblem() != nullptr)
-            feature_ptr->setProblem(getProblem());
-        // feature_list_.push_back(feature_ptr);
-    }
-   feature_list_.splice(feature_list_.end(), _new_ft_list);
 }
 
 void CaptureBase::getFactorList(FactorBasePtrList& _fac_list)
-- 
GitLab