CORGI
An open source project by
FPL
.
Main Page
Programmer's Guide
API reference
Readme
Contributing
Modules
Class List
File List
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Groups
Pages
component_id_lookup.h
Go to the documentation of this file.
1
// Copyright 2015 Google Inc. All rights reserved.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
15
#ifndef CORGI_COMPONENT_ID_LOOKUP_H_
16
#define CORGI_COMPONENT_ID_LOOKUP_H_
17
18
#include "
corgi/entity_common.h
"
19
20
namespace
corgi {
21
22
/// @file
23
/// @addtogroup corgi_component
24
/// @{
25
///
26
/// @struct ComponentIdLookup
27
///
28
/// @brief A templated struct for holding type-dependent data.
29
///
30
/// @note This is typically declared via a macro
31
/// (e.g. CORGI_REGISTER_COMPONENT).
32
///
33
/// @tparam T The type of the data structure stored by the Component.
34
/// (i.e. The type that the Component was specialized for.)
35
template
<
typename
T>
36
struct
ComponentIdLookup
{};
37
38
/// @def CORGI_REGISTER_COMPONENT(ComponentType, DataType)
39
/// Each Component needs to use this macro in its header, in order to
40
/// declare the necessary constants for lookups.
41
///
42
/// @note Since the macro includes its own namespace defintions, this should
43
/// ideally be called outside of any namespaces.
44
///
45
/// @param ComponentType The name of the Component class.
46
/// @param DataType The name of the struct that holds the Component data.
47
/// (i.e. The type that the Component was specialized for.)
48
#define CORGI_REGISTER_COMPONENT(ComponentType, DataType) \
49
CORGI_REGISTER_COMPONENT_ID_LOOKUP(ComponentType) \
50
CORGI_REGISTER_COMPONENT_ID_LOOKUP(DataType)
51
52
/// @def CORGI_DEFINE_COMPONENT(ComponentType, DataType)
53
/// Handles defining the storage location for the Component for a
54
/// given Component type and data type. It should be placed at the
55
/// top of the .cpp file for that Component (after the includes but
56
/// before the namespaces).
57
///
58
/// @param ComponentType The name of the Component class.
59
/// @param DataType The name of the struct that holds the Component data.
60
/// (i.e. The type that the Component was specialized for.)
61
#define CORGI_DEFINE_COMPONENT(ComponentType, DataType) \
62
CORGI_DEFINE_COMPONENT_ID_LOOKUP(ComponentType) \
63
CORGI_DEFINE_COMPONENT_ID_LOOKUP(DataType)
64
65
/// @def CORGI_REGISTER_COMPONENT_ID_LOOKUP(DataType)
66
/// This macro handles the lower level job of generating code to associate data
67
/// with a type. It is usually invoked by CORGI_REGISTER_COMPONENT, rather
68
/// than invoking it directly. (Since registration of a Component requires
69
/// multiple datatype/ID registrations.)
70
///
71
/// @param DataType The name of the struct that holds the Component data.
72
/// (i.e. The type that the Component was specialized for.)
73
#define CORGI_REGISTER_COMPONENT_ID_LOOKUP(DataType) \
74
namespace corgi { \
75
template <> \
76
struct ComponentIdLookup<DataType> { \
77
static ComponentId component_id; \
78
}; \
79
}
80
81
/// @def CORGI_DEFINE_COMPONENT_ID_LOOKUP(DataType)
82
/// This macro handles defining the storage location for the Component ID
83
/// for a given data type. It is usually invoked by
84
/// CORGI_DEFINE_COMPONENT, rather than invoking it directly.
85
///
86
/// @param DataType The name of the struct that holds the Component data.
87
/// (i.e. The type that the Component was specialized for.)
88
#define CORGI_DEFINE_COMPONENT_ID_LOOKUP(DataType) \
89
namespace corgi { \
90
ComponentId ComponentIdLookup<DataType>::component_id = kInvalidComponent; \
91
}
92
93
/// @}
94
95
}
// corgi
96
97
#endif // CORGI_COMPONENT_ID_LOOKUP_H_
entity_common.h
corgi::ComponentIdLookup
A templated struct for holding type-dependent data.
Definition:
component_id_lookup.h:36