26 #ifndef PAL_STATISTICS_UTILS_H 27 #define PAL_STATISTICS_UTILS_H 29 #include <boost/lockfree/queue.hpp> 30 #include <boost/bimap.hpp> 31 #include <boost/bimap/multiset_of.hpp> 32 #include <boost/bimap/set_of.hpp> 33 #include <boost/thread/lock_guard.hpp> 34 #include <boost/thread/mutex.hpp> 35 #include <boost/variant.hpp> 40 #include <pal_statistics_msgs/Statistics.h> 41 #include <pal_statistics_msgs/StatisticsNames.h> 42 #include <pal_statistics_msgs/StatisticsValues.h> 67 BaseType::reserve(missing_size);
68 reserved_size += missing_size;
74 return BaseType::bounded_push(t);
80 return BaseType::pop(ret);
98 const boost::weak_ptr<StatisticsRegistry> &obj);
106 boost::weak_ptr<StatisticsRegistry>
obj_;
122 bool remove(
const std::string &name);
123 bool remove(IdType id);
126 bool enable(
const std::string &name);
127 bool enable(IdType
id);
130 bool disable(
const std::string &name);
131 bool disable(IdType
id);
139 std::vector<Registration>::iterator find(
const std::string &name);
140 std::vector<Registration>::iterator find(IdType
id);
154 throw std::runtime_error(
"VariableHolder default constructor should never be called");
162 VariableHolder(
const boost::function<
double()> &
function) : v_ptr_(nullptr), v_func_(function)
171 *
this = std::move(other);
176 v_ptr_ = std::move(other.
v_ptr_);
177 v_func_ = std::move(other.
v_func_);
206 int registerVariable(
const std::string &name,
VariableHolder &&holder,
bool enabled =
true);
209 void unregisterVariable(
const IdType &
id);
211 void setEnabled(
const IdType &
id,
bool enabled);
214 void unregisterVariable(
const std::string &name);
221 void fillMsg(pal_statistics_msgs::StatisticsNames &names, pal_statistics_msgs::StatisticsValues &value);
231 bool smartFillMsg(pal_statistics_msgs::StatisticsNames &names, pal_statistics_msgs::StatisticsValues &values);
237 bool hasPendingData()
const;
244 void deleteElement(
size_t index);
245 void registrationsChanged();
252 typedef boost::bimap<boost::bimaps::multiset_of<std::string>, boost::bimaps::set_of<IdType>>
NameIdBiMap;
265 : names(capacity, IdType(0)), values(capacity, 0.)
280 #endif // PAL_STATISTICS_UTILS_H std::vector< VariableHolder > references_
The RegistrationList class.
std::vector< bool > enabled_
VariableHolder(const double *const pointer)
VariableHolder(const VariableHolder &&other)
The StatisticsRegistry class reads the value of registered variables and publishes them on the specif...
boost::bimap< boost::bimaps::multiset_of< std::string >, boost::bimaps::set_of< IdType > > NameIdBiMap
boost::function< double()> v_func_
bool bounded_push(T const &t)
NameValues(size_t capacity)
std::vector< double > values
boost::lockfree::queue< T > BaseType
std::vector< IdType > names
void set_capacity(typename BaseType::size_type n)
std::vector< std::string > names_
VariableHolder(const boost::function< double()> &function)
unsigned int names_version_
The Registration class is a handle to a registered variable, when out of scope unregisters the variab...
void operator=(const VariableHolder &&other)
bool registrations_changed_
std::vector< Registration > registrations_
std::atomic< size_t > reserved_size
std::pair< NameValues, ros::Time > LastValuesStamped
std::vector< IdType > ids_
The RegistrationsRAII class holds handles to registered variables and when it is destroyed, unregisters them automatically.
unsigned int overwritten_data_count_
boost::weak_ptr< StatisticsRegistry > obj_
Simple wrapper around boost lockfree queue to keep track of the reserved memory Boost's implementatio...
StaticCircularBuffer< LastValuesStamped > last_values_buffer_