diff --git a/include/pcp-cpp/metric_description.hpp b/include/pcp-cpp/metric_description.hpp index 87fb0ab..46952a3 100644 --- a/include/pcp-cpp/metric_description.hpp +++ b/include/pcp-cpp/metric_description.hpp @@ -7,6 +7,7 @@ #define __PCP_CPP_METRIC_DESCRIPTION_HPP__ #include "config.hpp" +#include "exception.hpp" #include "types.hpp" #include @@ -152,6 +153,14 @@ class metric_cluster : public std::map { class metrics_description : public std::map { public: + + explicit metrics_description() : + std::map(), + most_recent_cluster(end()) + { + + } + metrics_description& operator()(const cluster_id_type cluster_id, const std::string &cluster_name = std::string()) { @@ -171,7 +180,9 @@ class metrics_description : public std::map { const std::string &verbose_description = std::string(), void * const opaque = NULL) { - assert(most_recent_cluster != end()); + if (most_recent_cluster == end()) { + throw pcp::exception(PM_ERR_GENERIC, "no cluster to add metric to"); + } most_recent_cluster->second(item_id, metric_name, type, semantic, units, domain, short_description, verbose_description, opaque, flags); @@ -189,7 +200,9 @@ class metrics_description : public std::map { const std::string &verbose_description = std::string(), void * const opaque = NULL) { - assert(most_recent_cluster != end()); + if (most_recent_cluster == end()) { + throw pcp::exception(PM_ERR_GENERIC, "no cluster to add metric to"); + } most_recent_cluster->second(item_id, metric_name, type, semantic, units, domain, short_description, verbose_description, opaque, flags); @@ -207,7 +220,9 @@ class metrics_description : public std::map { void * const opaque = NULL, const metric_flags flags = static_cast(0)) { - assert(most_recent_cluster != end()); + if (most_recent_cluster == end()) { + throw pcp::exception(PM_ERR_GENERIC, "no cluster to add metric to"); + } most_recent_cluster->second(item_id, metric_name, type, semantic, units, domain, short_description, verbose_description, opaque, flags);