Skip to content

Commit

Permalink
Bug: Initialise the pcp::metrics_description::most_recent_cluster mem…
Browse files Browse the repository at this point in the history
…ber; also switched to exceptions, since these are handlable, and not fatal.
  • Loading branch information
pcolby committed Dec 17, 2013
1 parent f9839fc commit f7da268
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions include/pcp-cpp/metric_description.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#define __PCP_CPP_METRIC_DESCRIPTION_HPP__

#include "config.hpp"
#include "exception.hpp"
#include "types.hpp"

#include <assert.h>
Expand Down Expand Up @@ -152,6 +153,14 @@ class metric_cluster : public std::map<item_id_type, metric_description> {

class metrics_description : public std::map<cluster_id_type, metric_cluster> {
public:

explicit metrics_description() :
std::map<cluster_id_type, metric_cluster>(),
most_recent_cluster(end())
{

}

metrics_description& operator()(const cluster_id_type cluster_id,
const std::string &cluster_name = std::string())
{
Expand All @@ -171,7 +180,9 @@ class metrics_description : public std::map<cluster_id_type, metric_cluster> {
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);
Expand All @@ -189,7 +200,9 @@ class metrics_description : public std::map<cluster_id_type, metric_cluster> {
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);
Expand All @@ -207,7 +220,9 @@ class metrics_description : public std::map<cluster_id_type, metric_cluster> {
void * const opaque = NULL,
const metric_flags flags = static_cast<metric_flags>(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);
Expand Down

0 comments on commit f7da268

Please sign in to comment.