CellModules
basecell.hpp
Go to the documentation of this file.
1#ifndef MECACELL_BASECELL_HPP
2#define MECACELL_BASECELL_HPP
3
4/*----------------------------------------------------------------------------*\
5| |
6| MecaCell::BaseCell |
7| |
8\*----------------------------------------------------------------------------*/
21template <class Derived, template <class> class Body = ContactSurfaceBody>
22class BaseCell {
23 public:
24 using body_t = Body<Derived>;
26 using vec_t = decltype((body_t) nullptr->getPosition());
27
28 friend body_t;
30
31 protected:
32 body_t body; // body contains cell physics implementation
33 bool dead = false; // when a cell is dead it is flagged for destruction
34
35 public:
36 /*----------------------------------------------------------------------------*\
37 | CONSTRUCTORS |
38 \*----------------------------------------------------------------------------*/
39 BaseCell(const Derived &c) : body(static_cast<Derived *>(this)) {}
40 BaseCell(const vec_t &pos) : body(static_cast<Derived *>(this), pos) {}
41
42 /*----------------------------------------------------------------------------*\
43 | ID |
44 \*----------------------------------------------------------------------------*/
45 // A cell should have a unique id in its world, mostly for determinism & debugging
46 // purposes. Usually matches the order of insertion in the world.
47 size_t id = 0;
48 size_t getId() { return id; }
49
50 /*----------------------------------------------------------------------------*\
51 | UTILITIES |
52 \*----------------------------------------------------------------------------*/
53 void die() { dead = true; } // flag the cell for destruction
54 bool isDead() { return dead; } // simple getter
55 vec_t getPosition() { return body.getPosition(); }
56};
57
58#endif
MecaCell::Vec pos
Definition: CellBody.hpp:34
CellPlugin< cell_t > embedded_plugin_t
Definition: CellBody.hpp:39
Basis for every cell a user might want to use.
Definition: basecell.hpp:22
void die()
Definition: basecell.hpp:53
body_t body
Definition: basecell.hpp:32
typename body_t::embedded_plugin_t embedded_plugin_t
Definition: basecell.hpp:25
friend body_t
Definition: basecell.hpp:28
size_t id
Definition: basecell.hpp:47
friend embedded_plugin_t
Definition: basecell.hpp:29
bool dead
Definition: basecell.hpp:33
Body< Derived > body_t
Definition: basecell.hpp:24
decltype((body_t) nullptr->getPosition()) vec_t
Definition: basecell.hpp:26
size_t getId()
Definition: basecell.hpp:48
vec_t getPosition()
Definition: basecell.hpp:55
bool isDead()
Definition: basecell.hpp:54
BaseCell(const Derived &c)
Definition: basecell.hpp:39
BaseCell(const vec_t &pos)
Definition: basecell.hpp:40