1- #include " Graph.hpp"
1+ #include < rdf4cpp/ Graph.hpp>
22#include < rdf4cpp/Dataset.hpp>
33#include < rdf4cpp/writer/TryWrite.hpp>
44#include < rdf4cpp/writer/SerializationState.hpp>
55
66#include < utility>
7+ #include < ranges>
78
89namespace rdf4cpp {
910
1011storage::identifier::NodeBackendID Graph::to_node_id (Node node) noexcept {
1112 return node.backend_handle ().id ();
1213}
1314
15+ Graph::triple Graph::to_id_triple (Statement const &stmt) noexcept {
16+ return triple{
17+ to_node_id (stmt.subject ()),
18+ to_node_id (stmt.predicate ()),
19+ to_node_id (stmt.object ())
20+ };
21+ }
22+
1423Node Graph::to_node (storage::identifier::NodeBackendID id) const noexcept {
1524 return Node{storage::identifier::NodeBackendHandle{id, node_storage_}};
1625}
1726
27+ Statement Graph::to_statement (triple const &t) const noexcept {
28+ return Statement{to_node (t[0 ]), to_node (t[1 ]), to_node (t[2 ])};
29+ }
30+
1831Graph::Graph (storage::DynNodeStoragePtr node_storage) noexcept : node_storage_{node_storage} {
1932}
2033
2134void Graph::add (Statement const &stmt_) {
2235 auto stmt = stmt_.to_node_storage (node_storage_);
23- triples_.insert (triple{ to_node_id (stmt. subject ()), to_node_id (stmt. predicate ()), to_node_id (stmt. object ())} );
36+ triples_.insert (to_id_triple (stmt) );
2437}
2538
2639bool Graph::contains (Statement const &stmt_) const noexcept {
2740 auto const stmt = stmt_.try_get_in_node_storage (node_storage_);
28- return triples_.contains (triple{ to_node_id (stmt. subject ()), to_node_id (stmt. predicate ()), to_node_id (stmt. object ())} );
41+ return triples_.contains (to_id_triple (stmt) );
2942}
3043
3144Graph::iterator Graph::begin () const noexcept {
@@ -86,27 +99,27 @@ std::ostream &operator<<(std::ostream &os, Graph const &graph) {
8699 return os;
87100}
88101
89- Statement Graph::iterator::to_statement (rdf4cpp::Graph::triple const &t) const noexcept {
90- return Statement{parent_->to_node (t[0 ]), parent_->to_node (t[1 ]), parent_->to_node (t[2 ])};
91- }
92-
93102Graph::iterator::iterator (Graph const *parent, typename triple_storage_type::const_iterator beg, typename triple_storage_type::const_iterator end) noexcept : parent_{parent},
94103 iter_{beg},
95104 end_{end} {
96105 if (iter_ != end_) {
97- cur_ = to_statement (*iter_);
106+ cur_ = parent_-> to_statement (*iter_);
98107 }
99108}
100109
101110Graph::iterator &Graph::iterator::operator ++() noexcept {
102111 ++iter_;
103112 if (iter_ != end_) {
104- cur_ = to_statement (*iter_);
113+ cur_ = parent_-> to_statement (*iter_);
105114 }
106115
107116 return *this ;
108117}
109118
119+ void Graph::iterator::operator ++(int ) noexcept {
120+ ++*this ;
121+ }
122+
110123Graph::reference Graph::iterator::operator *() const noexcept {
111124 return cur_;
112125}
@@ -115,12 +128,12 @@ Graph::pointer Graph::iterator::operator->() const noexcept {
115128 return &cur_;
116129}
117130
118- bool Graph::iterator:: operator ==(Graph::sentinel) const noexcept {
119- return iter_ == end_;
131+ bool operator ==(Graph::iterator const &self, Graph::sentinel) noexcept {
132+ return self. iter_ == self. end_ ;
120133}
121134
122- bool Graph::iterator:: operator != (Graph::sentinel) const noexcept {
123- return !(* this == Graph::sentinel{}) ;
135+ bool operator == (Graph::sentinel, Graph::iterator const &self) noexcept {
136+ return self. iter_ == self. end_ ;
124137}
125138
126139bool Graph::solution_iterator::check_solution () noexcept {
@@ -168,12 +181,22 @@ Graph::solution_iterator::pointer Graph::solution_iterator::operator->() const n
168181 return &cur_;
169182}
170183
171- bool Graph::solution_iterator::operator ==(Graph::sentinel) const noexcept {
172- return iter_ == Graph::sentinel{};
184+ bool operator ==(Graph::solution_iterator const &self, Graph::sentinel) noexcept {
185+ return self.iter_ == Graph::sentinel{};
186+ }
187+
188+ bool operator ==(Graph::sentinel, Graph::solution_iterator const &self) noexcept {
189+ return self.iter_ == Graph::sentinel{};
173190}
174191
175- bool Graph::solution_iterator::operator !=(Graph::sentinel) const noexcept {
176- return iter_ != Graph::sentinel{};
192+ Graph Graph::anonymize (util::Anonymizer &anonymizer) const {
193+ Graph anon{anonymizer.node_storage ()};
194+
195+ for (auto const &non_anon_triple : triples_) {
196+ anon.triples_ .insert (to_id_triple (anonymizer.anonymize (to_statement (non_anon_triple))));
197+ }
198+
199+ return anon;
177200}
178201
179202} // namespace rdf4cpp
0 commit comments