YARP
Yet Another Robot Platform
FrameTransformContainer.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3  * SPDX-License-Identifier: LGPL-2.1-or-later
4  */
5 
6 #ifndef YARP_DEV_FRAMETRANSFORM_UTILS_H
7 #define YARP_DEV_FRAMETRANSFORM_UTILS_H
8 
9 
10 #include <yarp/os/Network.h>
12 #include <yarp/sig/Vector.h>
13 #include <yarp/os/PeriodicThread.h>
14 #include <yarp/dev/PolyDriver.h>
16 #include <mutex>
17 #include <map>
18 
31 {
32  using ContainerType = std::vector<yarp::math::FrameTransform>;
33 
34 public:
35  struct Iterator
36  {
37  using iterator_category = std::forward_iterator_tag;
38  using difference_type = ContainerType::difference_type;
40  using pointer = ContainerType::iterator;
42 
43  //constructor
44  Iterator(ContainerType& data, ContainerType::iterator ptr) :
45  m_data(data),
46  m_ptr(ptr)
47  {
48  while (m_ptr != m_data.end() && !m_ptr->isValid()) {
49  ++m_ptr;
50  }
51  }
52 
53  reference operator*() const { return *m_ptr; }
54  pointer operator->() { return m_ptr; }
55 
56  // Prefix increment
58  {
59  do {
60  ++m_ptr;
61  } while (m_ptr != m_data.end() && !m_ptr->isValid());
62  return *this;
63  }
64 
65  // Postfix increment
66  Iterator operator++(int) { Iterator tmp = *this; ++(*this); return tmp; }
67 
68  friend bool operator== (const Iterator& a, const Iterator& b) { return a.m_ptr == b.m_ptr; };
69  friend bool operator!= (const Iterator& a, const Iterator& b) { return a.m_ptr != b.m_ptr; };
70 
71  private:
72  ContainerType::iterator m_ptr;
73  ContainerType& m_data;
74  };
75 
76 public:
78  {
79  return Iterator(m_transforms, m_transforms.begin());
80  }
81 
83  {
84  return Iterator(m_transforms, m_transforms.end());
85  }
86 
87 protected:
88  ContainerType m_transforms;
90 
91 public:
92  mutable std::recursive_mutex m_trf_mutex;
93 
94 public:
95  //non-static transforms older than value (seconds) will be removed by method checkAndRemoveExpired()
96  double m_timeout = 0.2;
97  bool m_verbose_debug = false;
98  std::string m_name;
99 
100 public:
103 
104  //IFrameTransformStorageSet interface
105  bool setTransforms(const std::vector<yarp::math::FrameTransform>& transforms) override;
106  bool setTransform(const yarp::math::FrameTransform& transform) override;
107 
108  //IFrameTransformStorageGet interface
109  bool getTransforms(std::vector<yarp::math::FrameTransform>& transforms) const override;
110 
111  //IFrameTransformStorageUtils interface
112  bool deleteTransform(std::string t1, std::string t2) override;
113  bool clearAll() override;
114 
115  bool size(size_t& size) const;
116 
117 public:
118  //other
119  bool checkAndRemoveExpired();
120  bool checkAndRemoveExpired() const;
121 };
122 
123 #endif // YARP_DEV_FRAMETRANSFORM_UTILS_H
contains the definition of a Vector type
FrameTransformContainer: A class that contains a vector of frame transformations and exposes yarp::de...
void invalidateTransform(yarp::math::FrameTransform &trf)
bool setTransform(const yarp::math::FrameTransform &transform) override
Save a frame transform in a storage.
bool getTransforms(std::vector< yarp::math::FrameTransform > &transforms) const override
Obtains all frame transforms saved in a storage.
bool size(size_t &size) const
bool setTransforms(const std::vector< yarp::math::FrameTransform > &transforms) override
Save some frame transforms in a storage.
bool deleteTransform(std::string t1, std::string t2) override
Delete a single transform in the storage.
std::recursive_mutex m_trf_mutex
bool clearAll() override
Delete all transforms in a storage.
std::forward_iterator_tag iterator_category
friend bool operator!=(const Iterator &a, const Iterator &b)
ContainerType::difference_type difference_type
friend bool operator==(const Iterator &a, const Iterator &b)
Iterator(ContainerType &data, ContainerType::iterator ptr)