owlcpp  v0.3.3-86-g20d8c12~
C++ library for working with OWL ontologies
 All Classes Namespaces Files Functions Macros Pages
map_doc_crtpb.hpp
Go to the documentation of this file.
1 
6 #ifndef MAP_DOC_CRTPB_HPP_
7 #define MAP_DOC_CRTPB_HPP_
8 #include "boost/assert.hpp"
9 
10 #include "owlcpp/detail/map_traits.hpp"
12 #include "owlcpp/exception.hpp"
13 
14 namespace owlcpp{
15 
20 template<class Super> class Map_doc_crtpb {
21  typedef detail::Map_traits<Super> traits;
22  typedef typename traits::map_node_type map_node_t;
23  typedef typename traits::map_doc_type map_doc_type;
24  typedef typename map_doc_type::Err Err;
25  typedef typename traits::doc_type doc_type;
26 
27  map_doc_type const& _map_doc() const {
28  return static_cast<Super const&>(*this).map_doc_;
29  }
30 
31  map_doc_type& _map_doc() {
32  return static_cast<Super&>(*this).map_doc_;
33  }
34 
35 public:
36  typedef typename map_doc_type::iri_range doc_iri_range;
37  typedef typename map_doc_type::version_range doc_version_range;
38 
39  doc_type const& operator[](const Doc_id did) const {
40  return _map_doc()[did];
41  }
42 
43  doc_type const& at(const Doc_id did) const {
44  return _map_doc().at(did);
45  }
46 
47  doc_type const* find(const Doc_id did) const {
48  return _map_doc().find(did);
49  }
50 
51  doc_iri_range find_doc_iri(std::string const& iri) const {
52  BOOST_CONCEPT_ASSERT((Ns_iri_node_store<Super>));
53  Super const& super = static_cast<Super const&>(*this);
54  Node_id const*const nid = super.find_node_iri(iri);
55  if( nid ) return _map_doc().find_iri(*nid);
56  return doc_iri_range(_map_doc().end_iri(), _map_doc().end_iri());
57  }
58 
59  doc_version_range find_doc_version(std::string const& version) const {
60  BOOST_CONCEPT_ASSERT((Ns_iri_node_store<Super>));
61  Super const& super = static_cast<Super const&>(*this);
62  Node_id const*const nid = super.find_node_iri(version);
63  if( nid ) return _map_doc().find_version(*nid);
64  return doc_version_range(
65  _map_doc().end_version(),
66  _map_doc().end_version()
67  );
68  }
69 
92  std::pair<Doc_id,bool> insert_doc(
93  const Node_id iri_id,
94  std::string const& path = "",
95  const Node_id vers_id = terms::empty_::id()
96  ) {
97  BOOST_CONCEPT_ASSERT((Iri_node_store<Super>));
98  BOOST_ASSERT(
99  static_cast<Super const&>(*this).find(iri_id) &&
100  "invalid ontology IRI ID"
101  );
102 
103  BOOST_ASSERT(
104  static_cast<Super const&>(*this).find(vers_id) &&
105  "invalid version IRI ID"
106  );
107 
108  return _map_doc().insert(iri_id, path, vers_id);
109  }
110 
111  std::pair<Doc_id,bool> insert_doc(
112  std::string const& iri,
113  std::string const& path = "",
114  std::string const& vers = ""
115  ) {
116  BOOST_CONCEPT_ASSERT((Ns_iri_node_store<Super>));
117  const Node_id iri_id = static_cast<Super&>(*this).insert_node_iri(iri);
118  const Node_id vers_id = static_cast<Super&>(*this).insert_node_iri(vers);
119  try{
120  return insert_doc(iri_id, path, vers_id);
121  } catch(Err const& ) {
122  BOOST_THROW_EXCEPTION(
123  Err()
124  << typename Err::msg_t("error adding document")
125  << typename Err::str1_t(iri)
126  << typename Err::str2_t(path)
127  << typename Err::str3_t(vers)
128  << typename Err::nested_t(boost::current_exception())
129  );
130  }
131  }
132 };
133 
134 }//namespace owlcpp
135 #endif /* MAP_DOC_CRTPB_HPP_ */
std::pair< Doc_id, bool > insert_doc(const Node_id iri_id, std::string const &path="", const Node_id vers_id=terms::empty_::id())
Add document info: location, ontologyIRI, and versionIRI.
Definition: map_doc_crtpb.hpp:92
Document identifier.
Definition: doc_id.hpp:15
Term identifier.
Definition: node_id.hpp:15
Definition: map_doc_crtpb.hpp:20