owlcpp  v0.3.3~
C++ library for working with OWL ontologies
 All Classes Namespaces Files Functions Macros Pages
rdf_list_iterator.hpp
Go to the documentation of this file.
1 
6 #ifndef RDF_LIST_ITERATOR_HPP_
7 #define RDF_LIST_ITERATOR_HPP_
8 #include "boost/iterator/iterator_facade.hpp"
10 #include "owlcpp/rdf/exception.hpp"
13 
14 namespace owlcpp{
15 
20 : public boost::iterator_facade<
21  Rdf_list_iter_s,
22  Node_id const,
23  boost::forward_traversal_tag
24  >
25 {
26 public:
27  struct Err : public Rdf_err {};
28 
30  : ts_(0), nid_(terms::rdf_nil::id())
31  {}
32 
33  Rdf_list_iter_s(const Node_id nid, Triple_store const& ts)
34  : ts_(&ts), nid_(nid)
35  {}
36 
37 private:
38  Triple_store const* ts_;
39  Node_id nid_;
40 
41  friend class boost::iterator_core_access;
42 
43  void increment() {
44  const Triple_store::result_b<1,1,0,0>::type r = ts_->find_triple(
45  nid_,
46  terms::rdf_rest::id(),
47  any(),
48  any()
49  );
50  if( ! r ) BOOST_THROW_EXCEPTION(
51  Err()
52  << Err::msg_t("rdf:rest triple not found")
53  << Err::str1_t(to_string(nid_, *ts_))
54  );
55  Triple const& t = r.front();
56  if( boost::distance(r) != 1U ) BOOST_THROW_EXCEPTION(
57  Err()
58  << Err::msg_t("multiple rdf:rest triples")
59  << Err::str1_t(to_string(nid_, *ts_))
60  );
61  nid_ = t.obj_;
62  }
63 
64  Node_id const& dereference() const {
65  const Triple_store::result_b<1,1,0,0>::type r = ts_->find_triple(
66  nid_,
67  terms::rdf_first::id(),
68  any(),
69  any()
70  );
71  if( ! r ) BOOST_THROW_EXCEPTION(
72  Err()
73  << Err::msg_t("rdf:first triple not found")
74  << Err::str1_t(to_string(nid_, *ts_))
75  );
76  Triple const& t = r.front();
77  if( boost::distance(r) != 1U ) BOOST_THROW_EXCEPTION(
78  Err()
79  << Err::msg_t("multiple rdf:first triples")
80  << Err::str1_t(to_string(nid_, *ts_))
81  );
82  return t.obj_;
83  }
84 
85  bool equal(Rdf_list_iter_s const& i) const {return nid_ == i.nid_;}
86 };
87 
88 }//namespace owlcpp
89 #endif /* RDF_LIST_ITERATOR_HPP_ */