Spicy
id.h
1 // Copyright (c) 2020-2021 by the Zeek Project. See LICENSE for details.
2 
3 #pragma once
4 
5 #include <functional>
6 #include <iostream>
7 #include <optional>
8 #include <string>
9 #include <utility>
10 
11 #include <hilti/ast/node.h>
12 #include <hilti/base/id-base.h>
13 #include <hilti/base/util.h>
14 
15 namespace hilti {
16 
18 class ID : public detail::IDBase<ID>, public NodeBase, public util::type_erasure::trait::Singleton {
19 public:
21  ID(std::string name, Meta m) : IDBase(std::move(name)), NodeBase(std::move(m)) {}
22  ID() = default;
23 
25  ID& operator=(const std::string& s) {
26  IDBase::operator=(ID(s));
27  return *this;
28  }
29 
31  auto properties() const { return node::Properties{{"name", std::string(*this)}}; }
32 };
33 
34 inline std::ostream& operator<<(std::ostream& out, const ID& id) {
35  out << std::string(id);
36  return out;
37 }
38 
40 inline Node to_node(ID i) { return Node(std::move(i)); }
41 
42 } // namespace hilti
43 
44 namespace std {
45 template<>
46 struct hash<hilti::ID> {
47  std::size_t operator()(const hilti::ID& id) const { return hash<std::string>()(id); }
48 };
49 } // namespace std
Definition: optional.h:79
Definition: meta.h:19
auto properties() const
Definition: id.h:31
std::map< std::string, node::detail::PropertyValue > Properties
Definition: node.h:97
Definition: node.h:111
Definition: id-base.h:28
ID & operator=(const std::string &s)
Definition: id.h:25
Definition: id.h:18
Definition: node.h:359