nomlib
Loading...
Searching...
No Matches
ObjectTypeInfo.hpp
1/******************************************************************************
2
3 nomlib - C++11 cross-platform game engine
4
5Copyright (c) 2013, 2014 Jeffrey Carpenter <i8degrees@gmail.com>
6All rights reserved.
7
8Redistribution and use in source and binary forms, with or without
9modification, are permitted provided that the following conditions are met:
10
111. Redistributions of source code must retain the above copyright notice, this
12 list of conditions and the following disclaimer.
132. Redistributions in binary form must reproduce the above copyright notice,
14 this list of conditions and the following disclaimer in the documentation
15 and/or other materials provided with the distribution.
16
17THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
21ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28******************************************************************************/
29#ifndef NOMLIB_CORE_OBJECT_TYPE_INFO_HPP
30#define NOMLIB_CORE_OBJECT_TYPE_INFO_HPP
31
32#include <typeinfo> // std::type_info (typeid)
33#include <typeindex> // std::type_index
34
35#include "nomlib/config.hpp"
36
37namespace nom {
38
41{
42 public:
43 typedef ObjectTypeInfo self_type;
44 typedef std::type_index value_type;
45
49
52
54 ObjectTypeInfo( const self_type& copy );
55
57 self_type& operator =( const self_type& other );
58
62 ObjectTypeInfo( const value_type& object );
63
72 const std::string name( void ) const;
73
83 size_t hash_code( void ) const;
84
86 void set_type( const ObjectTypeInfo::value_type& object );
87
94 bool operator ==( const self_type& rhs ) const;
95
97 bool operator !=( const self_type& rhs ) const;
98
99 private:
101 const value_type& type( void ) const;
102
104 value_type type_;
105};
106
122
127template<typename T>
129{
130 typedef T type;
131};
132
142template<class T>
143static ObjectTypeInfo ObjectType()
144{
145 return ObjectTypeInfo( typeid( RTTIObject<T> ) );
146}
147
149#define NOM_OBJECT_TYPE_INFO( type ) \
150 ( ObjectType<type>() )
151
152} // namespace nom
153
154#endif // include guard defined
Run-time type information (RTTI) container class.
const value_type & type(void) const
Getter for the internal container type used.
ObjectTypeInfo(void)
Default constructor; initializes the object's type info as itself (this should be regarded as an inva...
value_type type_
Type information container.
size_t hash_code(void) const
Get the object's type hash code.
self_type & operator=(const self_type &other)
Copy assignment operator.
~ObjectTypeInfo(void)
Destructor.
const std::string name(void) const
Get the object type's name.
ObjectTypeInfo(const value_type &object)
Constructor for a complete object initialization.
ObjectTypeInfo(const self_type &copy)
Copy constructor.
bool operator!=(const self_type &rhs) const
In-equality comparison operator.
bool operator==(const self_type &rhs) const
Equality comparison operator.
void set_type(const ObjectTypeInfo::value_type &object)
Setter for the object's type.
Helper method for our factory API.