7#include <unordered_map>
17template <
class StorageT>
25 std::shared_ptr<StorageT> & root)
27 sparta_assert(root !=
nullptr,
"Unexpected null statistics hierarchy root encountered");
28 if (roots_.count(storage_name) > 0) {
29 throw SpartaException(
"Statistic hiearchy with root named '") << storage_name
30 <<
"' already exists in this statistics set";
32 roots_[storage_name] = root;
37 std::set<std::string> names;
38 for (
const auto & root : roots_) {
39 names.insert(root.first);
41 const std::vector<std::string> more_names = getLazyLoadedRootNames_();
42 names.insert(more_names.begin(), more_names.end());
43 return std::vector<std::string>(names.begin(), names.end());
51 const std::string & report_filename)
const
53 root_names_to_report_filenames_[root_name] = report_filename;
61 onNamedRootRequest_(root_name);
62 auto iter = roots_.find(root_name);
63 if (iter == roots_.end()) {
68 getReportFilenameForRoot_(root_name);
69 if (report_filename.
isValid()) {
75 return iter->second.get();
80 const std::string & root_name)
const
83 auto iter = root_names_to_report_filenames_.find(root_name);
84 if (iter != root_names_to_report_filenames_.end()) {
85 report_filename = iter->second;
87 return report_filename;
90 virtual void onNamedRootRequest_(
const std::string & root_name) {
94 virtual std::vector<std::string> getLazyLoadedRootNames_()
const {
98 mutable std::unordered_map<
100 std::string> root_names_to_report_filenames_;
104 std::shared_ptr<StorageT>> roots_;
#define sparta_assert(...)
Simple variadic assertion that will throw a sparta_exception if the condition fails.
Used to construct and throw a standard C++ exception. Inherits from std::exception.
Utility class that holds onto statistics node hierarchies, accessible by a name that you choose.
void mapRootNameToReportFilename(const std::string &root_name, const std::string &report_filename) const
std::vector< std::string > getRootNames() const
Access the root node names in this set.
StorageT * getRootByName(const std::string &root_name)
void addHierarchyRoot(const std::string &storage_name, std::shared_ptr< StorageT > &root)
Append a statistics hierarchy root node to this set.
Provides a wrapper around a value to ensure that the value is assigned.
bool isValid() const
Is this value valid.
Macros for handling exponential backoff.