TurtleBrains  0.3.5
High quality, portable, C++ framework for rapid 2D game development.
tb_resource_handle.hpp
1 
10 #ifndef _TurtleBraines_ResourceHandle_hpp
11 #define _TurtleBraines_ResourceHandle_hpp
12 
13 #include <turtle_brains/core/tb_types.hpp>
14 
15 namespace TurtleBrains
16 {
17  namespace Core
18  {
19 
24  template <typename Type> class ResourceHandle
25  {
26  public:
30  ResourceHandle(void);
31 
35  ~ResourceHandle(void);
36 
44  bool IsValid(void) const;
45 
49  operator bool() const;
50 
57  bool operator==(const ResourceHandle& other) const;
58 
65  bool operator!=(const ResourceHandle& other) const;
66 
67  bool operator<(const ResourceHandle& other) const
68  {
69  return mValue < other.mValue;
70  }
71 
72  //Was unable to make this private because the template friend class was not working. I believe it requires
73  //The friend class to have been declared already, which would create circular dependencies.
74  //private:
75  //template <typename ResourceType, typename HandleType> friend class TurtleBrains::Core::ResourceCache;
76 
83  ResourceHandle(const tbCore::uint32 value);
84 
92  //operator size_t() const;
93 
101  };
102 
103  }; /* namespace Core */
104 }; /* namespace TurtleBrains */
105 
106 namespace tbCore = TurtleBrains::Core;
107 
108 //-------------------------------------------------------------------------------------------------------------------//
109 //-------------------------------------------------------------------------------------------------------------------//
110 //-------------------------------------------------------------------------------------------------------------------//
111 
113  mValue(static_cast<tbCore::uint32>(~0))
114 {
115 }
116 
117 //-------------------------------------------------------------------------------------------------------------------//
118 
120 {
121 }
122 
123 //-------------------------------------------------------------------------------------------------------------------//
124 
125 template<typename Type> bool TurtleBrains::Core::ResourceHandle<Type>::IsValid(void) const
126 {
127  return mValue != static_cast<tbCore::uint32>(~0);
128 }
129 
130 //-------------------------------------------------------------------------------------------------------------------//
131 
132 template<typename Type> TurtleBrains::Core::ResourceHandle<Type>::operator bool() const
133 {
134  return IsValid();
135 }
136 
137 //-------------------------------------------------------------------------------------------------------------------//
138 
139 template<typename Type> bool TurtleBrains::Core::ResourceHandle<Type>::operator==(const ResourceHandle& other) const
140 {
141  return mValue == other.mValue;
142 }
143 
144 //-------------------------------------------------------------------------------------------------------------------//
145 
146 template<typename Type> bool TurtleBrains::Core::ResourceHandle<Type>::operator!=(const ResourceHandle& other) const
147 {
148  return mValue != other.mValue;
149 }
150 
151 //-------------------------------------------------------------------------------------------------------------------//
152 
154  mValue(value)
155 {
156 }
157 
158 //-------------------------------------------------------------------------------------------------------------------//
159 
160 //template<typename Type> TurtleBrains::Core::ResourceHandle<Type>::operator size_t() const
161 //{
162 // return static_cast<size_t>(mValue);
163 //}
164 
165 //-------------------------------------------------------------------------------------------------------------------//
166 
167 #endif /* _TurtleBraines_ResourceHandle_hpp */
tbCore::uint32 mValue
Definition: tb_resource_handle.hpp:100
Here is some information about the primary namespace.
Definition: tb_application_dialog.hpp:21
bool operator!=(const ResourceHandle &other) const
Definition: tb_resource_handle.hpp:146
Definition: tb_resource_handle.hpp:24
bool IsValid(void) const
Definition: tb_resource_handle.hpp:125
~ResourceHandle(void)
Definition: tb_resource_handle.hpp:119
uint32_t uint32
Unsigned integer with a size of 32 bits. Supports values from 0 to 4294967295, (2^32 - 1)...
Definition: tb_types.hpp:28
Contains core functionality for each component of the API.
Definition: tb_debug_logger.hpp:88
bool operator==(const ResourceHandle &other) const
Definition: tb_resource_handle.hpp:139
ResourceHandle(void)
Definition: tb_resource_handle.hpp:112