21 #ifndef OPHIDIAN_SRC_ENTITY_SYSTEM_ENTITY_H
22 #define OPHIDIAN_SRC_ENTITY_SYSTEM_ENTITY_H
26 #include <boost/serialization/strong_typedef.hpp>
29 namespace entity_system{
32 #define ENTITY_SYSTEM_STRONG_TYPEDEF(T, D) \
34 : boost::totally_ordered1< D \
35 , boost::totally_ordered2< D, T \
39 explicit D(const T t_) : t(t_) {}; \
40 D(): t(std::numeric_limits<T>::max()) {}; \
41 D(const D & t_) : t(t_.t){} \
42 D & operator=(const D & rhs) { t = rhs.t; return *this;} \
43 D & operator=(const T & rhs) { t = rhs; return *this;} \
44 operator const T & () const {return t; } \
45 operator T & () { return t; } \
46 bool operator==(const D & rhs) const { return t == rhs.t; } \
47 bool operator<(const D & rhs) const { return t < rhs.t; } \
50 ENTITY_SYSTEM_STRONG_TYPEDEF(uint32_t, entity)
51 ENTITY_SYSTEM_STRONG_TYPEDEF(uint32_t, entity_index)
53 static const entity_index invalid_entity_index = static_cast<entity_index>(std::numeric_limits<uint32_t>::max());
54 static const entity invalid_entity = static_cast<entity>(std::numeric_limits<uint32_t>::max());
62 template<>
struct hash<ophidian::entity_system::entity>
64 std::size_t operator()(
const ophidian::entity_system::entity & e)
const{
65 return std::hash<std::uint32_t>()(e);
69 template<>
struct hash<std::pair<ophidian::entity_system::entity,ophidian::entity_system::entity>>
71 std::size_t operator () (
const std::pair<ophidian::entity_system::entity,ophidian::entity_system::entity> &p)
const {
72 return std::hash<uint32_t>{}(p.first) ^ std::hash<uint32_t>{}(p.second);
77 #endif //OPHIDIAN_SRC_ENTITY_SYSTEM_ENTITY_H