ed
include
ed
property_key_db.h
Go to the documentation of this file.
1
#ifndef ED_PROPERTY_KEY_DB_H_
2
#define ED_PROPERTY_KEY_DB_H_
3
4
#include "
ed/types.h
"
5
#include "
ed/property_key.h
"
6
#include "
ed/property_info.h
"
7
8
#include <
map
>
9
10
namespace
ed
11
{
12
13
struct
PropertyKeyDBEntry
14
{
15
PropertyKeyDBEntry
() :
info
(nullptr) {}
16
17
~PropertyKeyDBEntry
()
18
{
19
if
(
info
)
20
delete
info
;
21
}
22
23
std::string
name
;
24
PropertyInfo
*
info
;
25
Idx
idx
;
26
};
27
28
class
PropertyKeyDB
29
{
30
31
public
:
32
33
~PropertyKeyDB
()
34
{
35
for
(
std::map<std::string, PropertyKeyDBEntry*>::iterator
it =
name_to_info_
.begin(); it !=
name_to_info_
.end(); ++it)
36
{
37
if
(it->second)
38
delete
it->second;
39
}
40
}
41
42
template
<
typename
T>
43
void
registerProperty
(
const
std::string
& name,
PropertyKey<T>
& key,
PropertyInfo
*
info
= 0)
44
{
45
PropertyKeyDBEntry
* entry;
46
47
std::map<std::string, PropertyKeyDBEntry*>::iterator
it =
name_to_info_
.find(name);
48
if
(it ==
name_to_info_
.end())
49
{
50
entry =
new
PropertyKeyDBEntry
;
51
entry->
name
= name;
52
entry->
idx
=
name_to_info_
.size();
53
54
if
(
info
)
55
entry->
info
=
info
;
56
else
57
entry->
info
=
new
PropertyInfo
;
58
59
name_to_info_
[name] = entry;
60
}
61
else
62
{
63
entry = it->second;
64
65
if
(
info
)
66
{
67
// TODO: needs locking? (Keys may access the entry info at this point)
68
delete
entry->
info
;
69
entry->
info
=
info
;
70
}
71
}
72
73
key.
entry
= entry;
74
key.
idx
= entry->
idx
;
75
}
76
77
const
PropertyKeyDBEntry
*
getPropertyKeyDBEntry
(
const
std::string
& name)
const
78
{
79
std::map<std::string, PropertyKeyDBEntry*>::const_iterator
it =
name_to_info_
.find(name);
80
if
(it ==
name_to_info_
.end())
81
return
0;
82
83
return
it->second;
84
}
85
86
private
:
87
88
std::map<std::string, PropertyKeyDBEntry*>
name_to_info_
;
89
90
};
91
92
}
// end namespace
93
94
#endif
ed::PropertyKeyDBEntry::PropertyKeyDBEntry
PropertyKeyDBEntry()
Definition:
property_key_db.h:15
ed::PropertyKey::idx
Idx idx
Definition:
property_key.h:15
std::string
types.h
ed::PropertyKey::entry
const PropertyKeyDBEntry * entry
Definition:
property_key.h:17
ed::PropertyKeyDBEntry::~PropertyKeyDBEntry
~PropertyKeyDBEntry()
Definition:
property_key_db.h:17
ed::PropertyKeyDB::name_to_info_
std::map< std::string, PropertyKeyDBEntry * > name_to_info_
Definition:
property_key_db.h:88
ed::PropertyKeyDBEntry::idx
Idx idx
Definition:
property_key_db.h:25
ed::log::info
std::ostream & info()
Definition:
logging.cpp:30
property_info.h
ed::PropertyKeyDBEntry
Definition:
property_key_db.h:13
ed::PropertyKeyDB
Definition:
property_key_db.h:28
map
property_key.h
ed::PropertyKeyDB::~PropertyKeyDB
~PropertyKeyDB()
Definition:
property_key_db.h:33
ed::PropertyKeyDBEntry::name
std::string name
Definition:
property_key_db.h:23
ed::PropertyKeyDBEntry::info
PropertyInfo * info
Definition:
property_key_db.h:24
ed::PropertyInfo
Definition:
property_info.h:12
ed
Definition:
convex_hull.h:8
ed::PropertyKeyDB::registerProperty
void registerProperty(const std::string &name, PropertyKey< T > &key, PropertyInfo *info=0)
Definition:
property_key_db.h:43
ed::PropertyKey
Definition:
property_key.h:12
ed::PropertyKeyDB::getPropertyKeyDBEntry
const PropertyKeyDBEntry * getPropertyKeyDBEntry(const std::string &name) const
Definition:
property_key_db.h:77
ed::Idx
uint64_t Idx
Definition:
types.h:21
Generated on Sun Feb 23 2025 04:34:40 for ed by
1.8.17