15 : name_(name), id_(id), obj_(obj)
30 lock->unregisterVariable(
id_);
34 : last_id_(0), names_version_(0), buffer_size_(internal_buffer_capacity), all_enabled_(true), registrations_changed_(true)
41 for (
size_t i = 0; i <
ids_.size(); ++i)
54 for (
size_t i = 0; i <
ids_.size(); ++i)
67 size_t count =
name_id_.left.count(name);
71 "You asked to unregister " 73 <<
" but there are multiple variables registered with that name. This can have undefined behaviour, unregistering all");
77 ROS_ERROR_STREAM(
"Tried to unregister variable " << name <<
" but it is not registered.");
94 auto &last_values = last_values_stamped.first;
96 assert(last_values.names.capacity() >=
ids_.size());
97 assert(last_values.values.capacity() >=
ids_.size());
102 last_values.names =
ids_;
104 for (
size_t i = 0; i < ref_size; ++i)
110 last_values.values.resize(ref_size);
114 last_values.names.clear();
115 last_values.values.clear();
117 size_t id_size =
ids_.size();
118 for (
size_t i = 0; i < id_size; ++i)
124 last_values.names.emplace_back(
ids_[i]);
125 last_values.values.emplace_back(
references_[i].getValue());
140 names.names[i] =
name_id_.right.find(
id)->second;;
143 value.header = names.header;
145 value.names_version = names.names_version;
162 for (
size_t i = 0; i <
enabled_.size(); ++i)
195 ROS_ERROR_STREAM(
"Didn't find index " << index <<
" in <name, index> multimap");
203 std::swap(
ids_[index],
ids_.back());
223 bool needs_more_capacity = (
names_.size() ==
names_.capacity());
225 name_id_.left.insert(std::make_pair(name,
id));
231 if (needs_more_capacity )
244 for (
auto it = registrations_.begin(); it != registrations_.end(); ++it)
246 if ((*it).name_ == name)
251 throw std::runtime_error(
"Unable to find registration with name " + name);
256 for (
auto it = registrations_.begin(); it != registrations_.end(); ++it)
263 throw std::runtime_error(
"Unable to find registration with id " + std::to_string(
id));
274 boost::unique_lock<boost::mutex> guard(mutex_);
275 registrations_.push_back(std::move(registration));
280 boost::unique_lock<boost::mutex> guard(mutex_);
283 registrations_.erase(find(name));
295 boost::unique_lock<boost::mutex> guard(mutex_);
298 registrations_.erase(find(
id));
309 registrations_.clear();
315 return reg.
obj_.lock()->enable(reg.
id_);
321 return reg.
obj_.lock()->enable(reg.
id_);
327 for (
auto it = registrations_.begin(); it != registrations_.end(); ++it)
329 result &= (*it).obj_.lock()->enable((*it).id_);
337 return reg.
obj_.lock()->disable(reg.
id_);
343 return reg.
obj_.lock()->disable(reg.
id_);
349 for (
auto it = registrations_.begin(); it != registrations_.end(); ++it)
351 result |= (*it).obj_.lock()->disable((*it).id_);
std::vector< Registration >::iterator find(const std::string &name)
std::vector< VariableHolder > references_
int registerVariable(const std::string &name, VariableHolder &&holder, bool enabled=true)
std::vector< bool > enabled_
bool remove(const std::string &name)
Registration(const std::string &name, IdType id, const boost::weak_ptr< StatisticsRegistry > &obj)
void deleteElement(size_t index)
void setEnabled(const IdType &id, bool enabled)
std::vector< std::string > names_
bool smartFillMsg(pal_statistics_msgs::StatisticsNames &names, pal_statistics_msgs::StatisticsValues &values)
smartFillMsg Attempts to minimize the amount of string copies
void registrationsChanged()
unsigned int names_version_
void unregisterVariable(const IdType &id)
The Registration class is a handle to a registered variable, when out of scope unregisters the variab...
void fillMsg(pal_statistics_msgs::StatisticsNames &names, pal_statistics_msgs::StatisticsValues &value)
fills message with the last captured values.
bool registrations_changed_
void pop_front()
pop_front Reduces buffer size by one, advancing the begin iterator
T & push_back()
push_back Increases the buffer size (not capacity) by one, and returns a reference to the last item i...
std::pair< NameValues, ros::Time > LastValuesStamped
bool enable(const std::string &name)
std::vector< IdType > ids_
unsigned int overwritten_data_count_
boost::weak_ptr< StatisticsRegistry > obj_
void add(Registration &®istration)
bool disable(const std::string &name)
StaticCircularBuffer< LastValuesStamped > last_values_buffer_
#define ROS_ERROR_STREAM(args)
void set_capacity(size_t max_size, const T &val)
set_capacity Allocates memory for max_size copies of val
RegistrationList(size_t internal_buffer_capacity=100)
bool hasPendingData() const
void clear()
clear Change the size of the buffer to 0 (not capacity) Only modifies internal iterators ...