Simulant  21.12-574
A portable game engine for Windows, OSX, Linux, Dreamcast, and PSP
identifiable.h
1 /* * Copyright (c) 2011-2017 Luke Benstead https://simulant-engine.appspot.com
2  *
3  * This file is part of Simulant.
4  *
5  * Simulant is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Lesser General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * Simulant is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with Simulant. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef IDENTIFIABLE_H
20 #define IDENTIFIABLE_H
21 
22 namespace smlt {
23 namespace generic {
24 
25 template<typename IDType>
26 class Identifiable {
27 public:
28  typedef IDType id_type;
29 
30  Identifiable(IDType id):
31  id_(id) {}
32 
33  virtual ~Identifiable() {}
34 
35  IDType id() const { return id_; }
36 
37  virtual bool operator==(const Identifiable<IDType>& rhs) const {
38  return id() == rhs.id();
39  }
40 
41  virtual bool operator<(const Identifiable<IDType>& rhs) const {
42  return id() < rhs.id();
43  }
44 
45  /*
46  * Private, do not use in user code! This exists so we can set the pointer
47  * of this object on the ID after creation
48  */
49 
50  template<typename ResourceTypePtr>
51  void _bind_id_pointer(ResourceTypePtr ptr) {
52  id_._bind(ptr);
53  }
54 
55  /* INTERNAL USE ONLY */
56  Identifiable() = default;
57  void _overwrite_id(IDType new_id) {
58  id_ = new_id;
59  }
60 
61 private:
62  IDType id_;
63 };
64 
65 }
66 }
67 
68 #endif // IDENTIFIABLE_H
smlt
Definition: animation.cpp:25
smlt::generic::Identifiable
Definition: identifiable.h:26