blob: a57b045e12da54c6704eafdedcd0e8e43b4f5a8f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
#pragma once
#include "modeling/Rack.h"
#include "modeling/TypeIndex.h"
#include <vector>
namespace Modeling
{
/*
The Room class models the rooms that can be created in the simulation. It contains a list of all entities in the room.
*/
template<typename ...EntityTypes>
class Room
{
//static_assert(std::is_base_of<Entity, EntityTypes>..., "Each type must be derived from Entity!");
public:
/*
Initializes the room with the given name.
*/
explicit Room(int id) : id(id) {}
/*
Adds the entity to the list of entities in this room.
*/
template<typename EntityType>
void addEntity(EntityType& e)
{
std::get<indexOfType<EntityType, EntityTypes...>::value>(entities).push_back(e);
}
/*
Returns all entities of the given type.
*/
template<typename EntityType>
std::vector<EntityType>& getEntitiesOfType()
{
return std::get<indexOfType<EntityType, EntityTypes...>::value>(entities);
}
// The id of this room corresponding to its id in the database.
const int id;
private:
// A vector for each type of entity
std::tuple<std::vector<EntityTypes>...> entities;
};
using ServerRoom = Room<Modeling::Rack>;
using Hallway = Room<>;
using PowerRoom = Room<>;
}
|