Program Listing for File creatable_collector_set.hpp

Return to documentation for file (rcppsw/metrics/creatable_collector_set.hpp)

#pragma once

/*******************************************************************************
 * Includes
 ******************************************************************************/
#include <tuple>
#include <set>
#include <typeindex>
#include <string>
#include <memory>

#include "rcppsw/metrics/output_mode.hpp"
#include "rcppsw/metrics/base_sink.hpp"

/*******************************************************************************
 * Namespaces/Decls
 ******************************************************************************/
namespace rcppsw::metrics {

/*******************************************************************************
 * Class Definitions
 ******************************************************************************/
template<typename TSink>
struct collector_registration_spec {
  bool                   is_enabled{false};
  std::unique_ptr<TSink> sink{};
};

struct creatable_collector_spec {
  creatable_collector_spec(const std::type_index& collector_id_in,
                           const std::string& input_name_in,
                           const std::string& scoped_name_in,
                           const rmetrics::output_mode& valid_modes_in,
                           const std::type_index& sink_id_in)
      : collector_id(collector_id_in),
        input_name(input_name_in),
        scoped_name(scoped_name_in),
        valid_modes(valid_modes_in),
        sink_id(sink_id_in) {}

  explicit creatable_collector_spec(const std::type_index& collector_id_in)
      : collector_id(collector_id_in) {}

  /* clang-format off */
  std::type_index       collector_id;
  std::string           input_name{};
  std::string           scoped_name{};
  rmetrics::output_mode valid_modes{rmetrics::output_mode::ekNONE};
  std::type_index       sink_id{typeid(nullptr)};
  /* clang-format on */
};

namespace detail {

struct creatable_collector_set_comparator {
  bool operator()(const creatable_collector_spec& lhs,
                  const creatable_collector_spec& rhs) const {
    return lhs.collector_id < rhs.collector_id;
  }
};

} /* namespace detail */

using creatable_collector_set = std::multiset<creatable_collector_spec,
                                              detail::creatable_collector_set_comparator>;

} /* namespace rcppsw::metrics */