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 
14 {
15  PropertyKeyDBEntry() : info(nullptr) {}
16 
18  {
19  if (info)
20  delete info;
21  }
22 
26 };
27 
29 {
30 
31 public:
32 
34  {
36  {
37  if(it->second)
38  delete it->second;
39  }
40  }
41 
42  template<typename T>
44  {
45  PropertyKeyDBEntry* entry;
46 
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 
78  {
80  if (it == name_to_info_.end())
81  return 0;
82 
83  return it->second;
84  }
85 
86 private:
87 
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