Program Listing for File block_metadata.hpp
↰ Return to documentation for file (cosm/repr/block_metadata.hpp
)
#pragma once
/*******************************************************************************
* Includes
******************************************************************************/
#include "rcppsw/math/vector2.hpp"
#include "rcppsw/patterns/prototype/clonable.hpp"
#include "rcppsw/types/timestep.hpp"
#include "rcppsw/types/type_uuid.hpp"
#include "cosm/cosm.hpp"
#include "cosm/foraging/metrics/block_transportee_metrics.hpp"
#include "cosm/repr/block_type.hpp"
#include "cosm/repr/colored_entity.hpp"
/*******************************************************************************
* Namespaces
******************************************************************************/
namespace cosm::repr {
/*******************************************************************************
* Class Definitions
******************************************************************************/
class block_metadata final : public cfmetrics::block_transportee_metrics,
public colored_entity {
public:
explicit block_metadata(const rutils::color& color,
const crepr::block_type& type)
: colored_entity(color), m_type(type) {}
~block_metadata(void) override = default;
/* transport metrics */
void reset_metrics(void) override final {
m_transporters = 0;
m_first_pickup_time = rtypes::timestep(0);
m_first_pickup = false;
m_dist_time = rtypes::timestep(0);
m_dest_drop_time = rtypes::timestep(0);
}
size_t total_transporters(void) const override { return m_transporters; }
rtypes::timestep total_transport_time(void) const override RCPPSW_PURE {
return m_dest_drop_time - m_first_pickup_time;
}
rtypes::timestep initial_wait_time(void) const override RCPPSW_PURE {
return m_first_pickup_time - m_dist_time;
}
crepr::block_type type(void) const override { return m_type; }
void robot_pickup_event(const rtypes::type_uuid& robot_id) {
++m_transporters;
m_robot_id = robot_id;
}
void first_pickup_time(const rtypes::timestep& t) {
if (!m_first_pickup) {
m_first_pickup_time = t;
m_first_pickup = true;
}
}
void dest_drop_time(const rtypes::timestep& t) { m_dest_drop_time = t; }
void distribution_time(const rtypes::timestep& t) { m_dist_time = t; }
const rtypes::type_uuid& robot_id(void) const { return m_robot_id; }
void robot_id(const rtypes::type_uuid& id) { m_robot_id = id; }
void robot_id_reset(void) { m_robot_id = rtypes::constants::kNoUUID; }
void metrics_copy(const block_metadata* const other) {
this->m_transporters = other->m_transporters;
this->m_first_pickup_time = other->m_first_pickup_time;
this->m_first_pickup = other->m_first_pickup;
this->m_dist_time = other->m_dist_time;
this->m_dest_drop_time = other->m_dest_drop_time;
}
private:
/* clang-format off */
rtypes::type_uuid m_robot_id{rtypes::constants::kNoUUID};
size_t m_transporters{0};
bool m_first_pickup{false};
rtypes::timestep m_first_pickup_time{0};
rtypes::timestep m_dist_time{0};
rtypes::timestep m_dest_drop_time{0};
crepr::block_type m_type;
/* clang-format on */
};
} /* namespace cosm::repr */