Safir SDK Core
Loading...
Searching...
No Matches
EntityId.h
Go to the documentation of this file.
1/******************************************************************************
2*
3* Copyright Saab AB, 2008-2013 (http://safirsdkcore.com)
4*
5* Created by: Lars Hagström / stlrha
6*
7*******************************************************************************
8*
9* This file is part of Safir SDK Core.
10*
11* Safir SDK Core is free software: you can redistribute it and/or modify
12* it under the terms of version 3 of the GNU General Public License as
13* published by the Free Software Foundation.
14*
15* Safir SDK Core is distributed in the hope that it will be useful,
16* but WITHOUT ANY WARRANTY; without even the implied warranty of
17* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18* GNU General Public License for more details.
19*
20* You should have received a copy of the GNU General Public License
21* along with Safir SDK Core. If not, see <http://www.gnu.org/licenses/>.
22*
23******************************************************************************/
24
25#ifndef __DOTS_ENTITY_ID_H__
26#define __DOTS_ENTITY_ID_H__
27
28#include <functional>
31
32namespace Safir
33{
34namespace Dob
35{
36namespace Typesystem
37{
43 {
44 public:
48 EntityId(): m_typeId(0),m_instanceId() {}
49
58 const Dob::Typesystem::InstanceId& instanceId)
59 : m_typeId(typeId),m_instanceId(instanceId) {}
60
61
70 void RemoveString() {m_instanceId.RemoveString();}
71
72
78 const Dob::Typesystem::InstanceId & GetInstanceId() const {return m_instanceId;}
79
85 void SetInstanceId(const Dob::Typesystem::InstanceId & instanceId) {m_instanceId = instanceId;}
86
92 Dob::Typesystem::TypeId GetTypeId() const {return m_typeId;}
93
99 void SetTypeId(const Dob::Typesystem::TypeId typeId) {m_typeId = typeId;}
100
107 bool operator ==(const EntityId & other) const
108 {
109 return m_typeId == other.m_typeId && m_instanceId == other.m_instanceId;
110 }
111
118 bool operator !=(const EntityId & other) const
119 {
120 return !(*this==other);
121 }
122
130 bool operator < (const EntityId & other) const
131 {
132 if (m_typeId == other.m_typeId)
133 {
134 return m_instanceId < other.m_instanceId;
135 }
136 else
137 {
138 return m_typeId < other.m_typeId;
139 }
140 }
141
157 DOTS_CPP_API const std::wstring ToString() const;
158
168 DOTS_CPP_API const std::wstring ToStringNumeric() const;
169 private:
170
172 Dob::Typesystem::InstanceId m_instanceId;
173 };
174
175 static inline std::wostream & operator << (std::wostream & out, const EntityId & entityId)
176 {return out << entityId.ToString();}
177
178 template <class T>
179 static inline void hash_combine(std::size_t& seed, const T& v)
180 {
181 std::hash<T> hasher;
182 seed ^= hasher(v) + 0x9e3779b9 + (seed<<6) + (seed>>2);
183 }
184
185 //Make it possible to use EntityId as key in a dictionaries.
186 inline std::size_t hash_value(const Safir::Dob::Typesystem::EntityId& eid)
187 {
188 size_t result = std::hash<Dob::Typesystem::TypeId>()(eid.GetTypeId());
189 hash_combine(result, std::hash<InstanceId::UnderlyingType>()(eid.GetInstanceId().GetRawValue()));
190 return result;
191 }
192}
193}
194}
195
196#endif
This namespace contains all the functionality and definitions of the SAFIR SDK.
Definition Backdoor.h:31
static void hash_combine(std::size_t &seed, const T &v)
Definition EntityId.h:179
std::size_t hash_value(const Safir::Dob::Typesystem::ChannelId &val)
Definition ChannelId.h:228
static std::wostream & operator<<(std::wostream &out, const ChannelId &channelId)
Definition ChannelId.h:224
DotsC_TypeId TypeId
A unique type identifier.
Definition Defs.h:218
Class containing the identity of an entity.
Definition EntityId.h:43
bool operator<(const EntityId &other) const
Less-than operator.
Definition EntityId.h:130
void RemoveString()
Remove the included string from the instance id of the entity id.
Definition EntityId.h:70
EntityId()
Default constructor.
Definition EntityId.h:48
const Dob::Typesystem::InstanceId & GetInstanceId() const
Get the Instance number out of the EntityId.
Definition EntityId.h:78
Dob::Typesystem::TypeId GetTypeId() const
Get the type id out of the EntityId.
Definition EntityId.h:92
void SetTypeId(const Dob::Typesystem::TypeId typeId)
Set the type id of the EntityId.
Definition EntityId.h:99
DOTS_CPP_API const std::wstring ToStringNumeric() const
Convert an entity id to a string that has only numeric parts.
bool operator!=(const EntityId &other) const
Inequality operator.
Definition EntityId.h:118
EntityId(const Dob::Typesystem::TypeId typeId, const Dob::Typesystem::InstanceId &instanceId)
Constructor with type id and instance arguments.
Definition EntityId.h:57
bool operator==(const EntityId &other) const
Equality operator.
Definition EntityId.h:107
void SetInstanceId(const Dob::Typesystem::InstanceId &instanceId)
Set the instance number of the EntityId.
Definition EntityId.h:85
DOTS_CPP_API const std::wstring ToString() const
Convert an entity id to a string.
Class containing the identity of an instance.
Definition InstanceId.h:49
void RemoveString()
Remove the included string from the instance id.
Definition InstanceId.h:117
UnderlyingType GetRawValue() const
Get the raw 64 bit integer identifier.
Definition InstanceId.h:174
#define DOTS_CPP_API
Definition Defs.h:33