Utopia  2
Framework for studying models of complex & adaptive systems.
entity.hh
Go to the documentation of this file.
1 #ifndef UTOPIA_CORE_ENTITY_HH
2 #define UTOPIA_CORE_ENTITY_HH
3 
4 #include "state.hh"
5 #include "tags.hh"
6 #include "space.hh"
7 #include "types.hh"
8 
9 
10 namespace Utopia {
17 
22 template<typename EntityContainerType>
23 struct NoCustomLinks {};
24 
25 
27 
44 template<typename StateType,
45  Update update_mode,
46  bool use_def_state_constr=false,
47  typename EntityTags=EmptyTag,
48  template<class> class CustomLinkContainers=NoCustomLinks>
49 struct EntityTraits {
51  using State = StateType;
52 
54  static constexpr Update mode = update_mode;
55 
57  static constexpr bool use_default_state_constructor = use_def_state_constr;
58 
60  using Tags = EntityTags;
61 
63  template<class EntityContainerType>
64  using CustomLinks = CustomLinkContainers<EntityContainerType>;
65 };
66 
67 
69 
79 template<typename Derived, typename _Traits>
80 class Entity :
81  public StateContainer<typename _Traits::State, _Traits::mode>,
82  public _Traits::Tags
83 {
84 public:
86 
90  using Traits = _Traits;
91 
94 
96  using State = typename Traits::State;
97 
99  static constexpr Update mode = Traits::mode;
100 
102  using Tags = typename Traits::Tags;
103 
105 
110  typename Traits::template CustomLinks<EntityContainer<Derived>>;
111 
112 
113 private:
115  const IndexType _id;
116 
119 
120 
121 public:
123  Entity(const IndexType id, const State initial_state)
124  :
125  // Store arguments and initialize Tags via default constructor
126  StateContainer<State, mode>(initial_state),
127  Tags(),
128  _id(id),
129  // Initialize custom links empty, i.e. with its default constructor
130  _custom_links()
131  {}
132 
134  const IndexType& id() const {
135  return _id;
136  }
137 
140  return _custom_links;
141  }
142 
145  return _custom_links;
146  }
147 };
148 
149 
150 // end group Entity
155 } // namespace Utopia
156 
157 #endif // UTOPIA_CORE_ENTITY_HH
Definition: tags.hh:6
An entity is a slightly specialized state container.
Definition: entity.hh:83
CustomLinkContainers & custom_links()
Return reference to custom link containers.
Definition: entity.hh:139
typename Traits::Tags Tags
The tags associated with this entity.
Definition: entity.hh:102
const CustomLinkContainers & custom_links() const
Return const reference to custom link containers.
Definition: entity.hh:144
Entity(const IndexType id, const State initial_state)
Construct an entity.
Definition: entity.hh:123
typename Traits::State State
The type of the state of this entity.
Definition: entity.hh:96
_Traits Traits
The traits of this entity.
Definition: entity.hh:90
static constexpr Update mode
Whether this entity is updated synchronously.
Definition: entity.hh:99
CustomLinkContainers _custom_links
Container for storing the custom links of this entity.
Definition: entity.hh:118
const IndexType & id() const
Return const reference to entity ID.
Definition: entity.hh:134
typename Traits::template CustomLinks< EntityContainer< Derived > > CustomLinkContainers
A construct that has as members containers for custom-linked entities.
Definition: entity.hh:110
const IndexType _id
ID of this entity.
Definition: entity.hh:115
Container for states.
Definition: state.hh:37
Update
Update modes when applying rules.
Definition: state.hh:20
Definition: agent.hh:11
std::size_t IndexType
Type for indices, i.e. values used for container indexing, agent IDs, ...
Definition: types.hh:40
The entity traits struct gathers types to be used for specializing an entity.
Definition: entity.hh:49
CustomLinkContainers< EntityContainerType > CustomLinks
Template template parameter to specify type of custom links.
Definition: entity.hh:64
EntityTags Tags
Custom entity tags.
Definition: entity.hh:60
static constexpr bool use_default_state_constructor
Whether to use the default constructor for constructing a entity state.
Definition: entity.hh:57
static constexpr Update mode
Whether the entitys should be synchronously updated.
Definition: entity.hh:54
StateType State
Type of the entitys' state container.
Definition: entity.hh:51