BALL
1.4.2
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
•
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
include
BALL
CONCEPT
embeddable.h
Go to the documentation of this file.
1
// -*- Mode: C++; tab-width: 2; -*-
2
// vi: set ts=2:
3
//
4
5
#ifndef BALL_CONCEPT_EMBEDDABLE_H
6
#define BALL_CONCEPT_EMBEDDABLE_H
7
8
#ifndef BALL_COMMON_H
9
# include <
BALL/common.h
>
10
#endif
11
12
#ifndef BALL_DATATYPE_STRINGHASHMAP_H
13
# include <
BALL/DATATYPE/stringHashMap.h
>
14
#endif
15
16
#ifndef BALL_DATATYPE_HASHMAP_H
17
# include <
BALL/DATATYPE/hashMap.h
>
18
#endif
19
20
#include <typeinfo>
21
22
namespace
BALL
23
{
24
31
#define BALL_EMBEDDABLE(TYPE,BASE)\
32
virtual void registerThis() \
33
{ \
34
if (typeid(*this) != typeid(TYPE))\
35
{\
36
Log.error() << "Warning: derived class " << typeid(*this).name() << " was derived from BALL::Embeddable, but the macro\n"\
37
<< "BALL_EMBEDDABLE(...) was not specified in the class declaration!" << std::endl;\
38
}\
39
Embeddable::registerInstance_(typeid(TYPE), this);\
40
Embeddable::registerInstance_(typeid(BASE), this);\
41
}\
42
\
43
static TYPE* getInstance(Position index) \
44
{ \
45
Embeddable* ptr = Embeddable::getInstance_(typeid(TYPE), index);\
46
if (ptr != 0)\
47
{\
48
return dynamic_cast<TYPE*>(ptr); \
49
}\
50
else\
51
{\
52
return 0;\
53
}\
54
}\
55
static TYPE* getInstance(const String& identifier) \
56
{\
57
Embeddable* ptr = Embeddable::getInstance_(typeid(TYPE), identifier);\
58
if (ptr != 0)\
59
{\
60
return dynamic_cast<TYPE*>(ptr); \
61
}\
62
else\
63
{\
64
return 0;\
65
}\
66
}\
67
static Size countInstances() { return (Embeddable::countInstances_(typeid(TYPE))); };
68
81
class
BALL_EXPORT
Embeddable
82
{
83
public
:
84
88
typedef
std::vector<Embeddable*>
EmbeddableVector
;
90
94
97
Embeddable
(
const
String
& identifier =
"<Embeddable>"
)
98
;
99
102
Embeddable
(
const
Embeddable
& embeddable)
103
;
104
107
virtual
~
Embeddable
()
108
;
110
114
117
void
setIdentifier(
const
String
& identifier)
118
;
119
122
const
String
& getIdentifier()
const
123
;
124
127
void
unregisterThis()
128
;
129
136
virtual
void
registerThis()
137
;
138
140
147
virtual
void
dump(std::ostream& s = std::cout,
Size
depth = 0)
const
148
;
149
150
protected
:
153
static
void
registerInstance_(
const
std::type_info& type,
const
Embeddable
* instance)
154
;
157
static
void
unregisterInstance_(
const
Embeddable
* instance)
158
;
159
162
static
Size
countInstances_(
const
std::type_info& type)
163
;
164
169
static
Embeddable
* getInstance_(
const
std::type_info& type,
Position
index)
170
;
171
175
static
Embeddable
* getInstance_(
const
std::type_info& type,
const
String
& identifier)
176
;
177
178
179
private
:
180
183
String
identifier_
;
184
187
static
StringHashMap<EmbeddableVector>
instance_vectors_
;
188
191
static
HashMap<Embeddable*, string>
instance_to_type_map_
;
192
};
193
194
}
// namespace BALL
195
196
#endif // BALL_CONCEPT_EMBEDDABLE_H
Generated by
1.8.3.1