Utopia  2
Framework for studying models of complex & adaptive systems.
entity.hh
Go to the documentation of this file.
1 #ifndef UTOPIA_CORE_GRAPH_ENTITY_HH
2 #define UTOPIA_CORE_GRAPH_ENTITY_HH
3 
4 #include "../tags.hh"
5 #include "../types.hh"
6 #include "../entity.hh"
7 
8 namespace Utopia {
16 
19 template<typename StateType,
20  typename GraphEntityTags=EmptyTag,
21  template<class> class CustomLinkContainers=NoCustomLinks>
22 using GraphEntityTraits = EntityTraits<StateType,
24  false, // use_def_state_constr
25  GraphEntityTags,
26  CustomLinkContainers>;
27 
28 
30 
39 template<typename Traits>
40 class GraphEntity :
41  public Entity<GraphEntity<Traits>, Traits>
42 {
43 public:
46 
48  using State = typename Traits::State;
49 
50 private:
52  static inline IndexType id_counter = 0;
53 
54 public:
57  :
59  {};
60 
62  GraphEntity(const State& initial_state)
63  :
64  Entity<Self, Traits>(id_counter++, initial_state)
65  {};
66 
69  Entity<Self, Traits>(id_counter++, ge.state)
70  {};
71 
74  std::swap(this->state, ge.state);
75  std::swap(this->custom_links(), ge.custom_links());
76  return *this;
77  }
78 
81  return id_counter;
82  }
83 };
84 
85 // end group GraphEntity
90 } // namespace Utopia
91 
92 #endif // UTOPIA_CORE_GRAPH_ENTITY_HH
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
Traits Traits
The traits of this entity.
Definition: entity.hh:90
A graph entity is a slightly specialized state container.
Definition: entity.hh:42
IndexType get_id_counter()
Get the id counter.
Definition: entity.hh:80
GraphEntity(const State &initial_state)
Construct a graph entity with initial state.
Definition: entity.hh:62
typename Traits::State State
The type of the state.
Definition: entity.hh:48
GraphEntity(const GraphEntity &ge)
Copy-construct a graph entity.
Definition: entity.hh:68
GraphEntity()
Construct a graph entity with empty initial state.
Definition: entity.hh:56
GraphEntity & operator=(GraphEntity ge)
Copy-assign a graph entity.
Definition: entity.hh:73
static IndexType id_counter
The id counter that counts how many graph entities exist.
Definition: entity.hh:52
void swap(WriteTask< BGB, DW, DB, AWG, AWD > &lhs, WriteTask< BGB, DW, DB, AWG, AWD > &rhs)
Swaps the state of lhs and rhs.
Definition: write_task.hh:240
@ manual
User chooses update type when calling apply_rule()
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