Program Listing for File base_cache.hpp
↰ Return to documentation for file (cosm/arena/repr/base_cache.hpp
)
#pragma once
/*******************************************************************************
* Includes
******************************************************************************/
#include <algorithm>
#include <memory>
#include "rcppsw/patterns/prototype/clonable.hpp"
#include "rcppsw/spatial/euclidean_dist.hpp"
#include "rcppsw/types/timestep.hpp"
#include "rcppsw/math/rng.hpp"
#include "cosm/repr/colored_entity.hpp"
#include "cosm/repr/unicell_immovable_entity2D.hpp"
#include "cosm/ds/block3D_ht.hpp"
#include "cosm/ds/block3D_vector.hpp"
/*******************************************************************************
* Namespaces
******************************************************************************/
namespace cosm::arena::repr {
/*******************************************************************************
* Class Definitions
******************************************************************************/
class base_cache : public crepr::unicell_immovable_entity2D,
public rer::client<base_cache>,
public crepr::colored_entity,
public rpprototype::clonable<base_cache> {
public:
struct params {
/* clang-format off */
rspatial::euclidean_dist dimension; /* caches are square */
rtypes::discretize_ratio resolution;
rmath::vector2d center;
const cds::block3D_vectorno&& blocks;
rtypes::type_uuid id;
/* clang-format on */
};
static constexpr const size_t kMinBlocks = 2;
explicit base_cache(const params& p);
~base_cache(void) override = default;
bool operator==(const base_cache& other) const = delete;
bool idcmp(const base_cache& other) const { return this->id() == other.id(); }
bool dloccmp(base_cache& other) {
return this->dcenter2D() == other.dcenter2D();
}
void blocks_map_enable(void);
bool contains_block(const crepr::sim_block3D* c_block) const RCPPSW_PURE;
size_t n_blocks(void) const { return m_blocks_vec.size(); }
cds::block3D_vectorno& blocks(void) { return m_blocks_vec; }
const cds::block3D_vectorno& blocks(void) const { return m_blocks_vec; }
void block_add(crepr::sim_block3D* block);
void block_remove(const crepr::sim_block3D* victim);
crepr::sim_block3D* block_select(rmath::rng* rng);
std::unique_ptr<base_cache> clone(void) const override final;
rtypes::timestep creation_ts(void) const { return m_creation; }
void creation_ts(const rtypes::timestep& ts) { m_creation = ts; }
private:
/* clang-format off */
static int m_next_id;
const rtypes::discretize_ratio mc_resolution;
bool m_map_en{false};
rtypes::timestep m_creation{0};
cds::block3D_htno m_blocks_map{};
cds::block3D_vectorno m_blocks_vec{};
/* clang-format on */
};
} /* namespace cosm::arena::repr */