1 | /** |
2 | * Copyright (c) 2006-2023 LOVE Development Team |
3 | * |
4 | * This software is provided 'as-is', without any express or implied |
5 | * warranty. In no event will the authors be held liable for any damages |
6 | * arising from the use of this software. |
7 | * |
8 | * Permission is granted to anyone to use this software for any purpose, |
9 | * including commercial applications, and to alter it and redistribute it |
10 | * freely, subject to the following restrictions: |
11 | * |
12 | * 1. The origin of this software must not be misrepresented; you must not |
13 | * claim that you wrote the original software. If you use this software |
14 | * in a product, an acknowledgment in the product documentation would be |
15 | * appreciated but is not required. |
16 | * 2. Altered source versions must be plainly marked as such, and must not be |
17 | * misrepresented as being the original software. |
18 | * 3. This notice may not be removed or altered from any source distribution. |
19 | **/ |
20 | |
21 | #ifndef LOVE_TYPES_H |
22 | #define LOVE_TYPES_H |
23 | |
24 | #include "int.h" |
25 | |
26 | // STD |
27 | #include <bitset> |
28 | #include <vector> |
29 | |
30 | namespace love |
31 | { |
32 | |
33 | class Type |
34 | { |
35 | public: |
36 | static const uint32 MAX_TYPES = 128; |
37 | |
38 | Type(const char *name, Type *parent); |
39 | Type(const Type&) = delete; |
40 | |
41 | static Type *byName(const char *name); |
42 | |
43 | void init(); |
44 | uint32 getId(); |
45 | const char *getName() const; |
46 | |
47 | bool isa(const uint32 &other) |
48 | { |
49 | if (!inited) |
50 | init(); |
51 | return bits[other]; |
52 | } |
53 | |
54 | bool isa(const Type &other) |
55 | { |
56 | if (!inited) |
57 | init(); |
58 | // Note that if this type implements the other |
59 | // calling init above will also have inited |
60 | // the other. |
61 | return bits[other.id]; |
62 | } |
63 | |
64 | private: |
65 | const char * const name; |
66 | Type * const parent; |
67 | uint32 id; |
68 | bool inited; |
69 | std::bitset<MAX_TYPES> bits; |
70 | }; |
71 | |
72 | } // love |
73 | |
74 | #endif // LOVE_TYPES_H |
75 | |