Commit 65f228e4 authored by Simon Spannagel's avatar Simon Spannagel
Browse files

Clipboard: add convenience function to count objects

parent 832f7815
......@@ -59,6 +59,12 @@ namespace corryvreckan {
*/
template <typename T> std::shared_ptr<std::vector<T*>> getData(const std::string& key = "") const;
/**
* @brief Method to count the number of objects of a given type on the clipboard
* @param key Identifying key of objects to be counted. An empty key will count all objects available.
*/
template <typename T> size_t countObjects(const std::string& key = "") const;
/**
* @brief Check whether an event has been defined
* @return true if an event has been defined, false otherwise
......
......@@ -29,4 +29,21 @@ namespace corryvreckan {
return std::static_pointer_cast<std::vector<T*>>(m_data.at(typeid(T)).at(key));
}
template <typename T> size_t Clipboard::countObjects(const std::string& key) const {
size_t number_of_objects = 0;
// Check if we have anything of this type:
if(m_data.count(typeid(T)) != 0) {
// Decide whether we should count all or just the ones identidied by a key:
if(key.empty()) {
for(const auto& block : m_data.at(typeid(T))) {
number_of_objects += std::static_pointer_cast<std::vector<T*>>(block.second)->size();
}
} else if(m_data.at(typeid(T)).count(key) != 0) {
number_of_objects = std::static_pointer_cast<std::vector<T*>>(m_data.at(typeid(T)).at(key))->size();
}
}
return number_of_objects;
}
} // namespace corryvreckan
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment