tree-gen
C++ code generator for tree structures
tree-base.cpp.inc
Go to the documentation of this file.
1 TREE_NAMESPACE_BEGIN
2 namespace base {
3 
8 size_t PointerMap::add_raw(const void *ptr, const char *name) {
9  auto it = map.find(ptr);
10  if (it != map.end()) {
11  if (enable_exceptions) {
12  std::ostringstream ss{};
13  ss << "Duplicate node of type " << name;
14  ss << "at address " << std::hex << ptr << " found in tree";
15  throw NotWellFormed(ss.str());
16  } else {
17  return it->second;
18  }
19  }
20  size_t sequence = map.size();
21  map.emplace(ptr, sequence);
22  return sequence;
23 }
24 
29 size_t PointerMap::get_raw(const void *ptr, const char *name) const {
30  auto it = map.find(ptr);
31  if (it == map.end()) {
32  if (enable_exceptions) {
33  std::ostringstream ss{};
34  ss << "Link to node of type " << name;
35  ss << " at address " << std::hex << ptr << " not found in tree";
36  throw NotWellFormed(ss.str());
37  } else {
38  return (size_t)-1;
39  }
40  }
41  return it->second;
42 }
43 
47 void IdentifierMap::register_node(size_t identifier, const std::shared_ptr<void> &ptr) {
48  nodes.emplace(identifier, ptr);
49 }
50 
54 void IdentifierMap::register_link(LinkBase &link, size_t identifier) {
55  links.emplace_back(link, identifier);
56 }
57 
61 void IdentifierMap::restore_links() const {
62  for (auto &it : links) {
63  it.first.set_void_ptr(nodes.at(it.second));
64  }
65 }
66 
73 void Completable::find_reachable(PointerMap &map) const {
74  (void)map;
75 }
76 
87 void Completable::check_complete(const PointerMap &map) const {
88  (void)map;
89 }
90 
101 void Completable::check_well_formed() const {
102  PointerMap map{};
103  find_reachable(map);
104  check_complete(map);
105 }
106 
116 bool Completable::is_well_formed() const {
117  try {
118  check_well_formed();
119  return true;
120  } catch (NotWellFormed &) {
121  return false;
122  }
123 }
124 
125 } // namespace base
126 TREE_NAMESPACE_END