owlcpp  v0.3.3~
C++ library for working with OWL ontologies
 All Classes Namespaces Files Functions Macros Pages
ns_iri.hpp
Go to the documentation of this file.
1 
6 #ifndef NS_IRI_HPP_
7 #define NS_IRI_HPP_
8 #include <string>
9 #include <iosfwd>
10 #include "boost/functional/hash.hpp"
11 
12 namespace owlcpp{
13 
16 class Ns_iri {
17 public:
18  explicit Ns_iri(char const* nsiri) : str_(nsiri) {}
19  explicit Ns_iri(std::string const& nsiri) : str_(nsiri) {}
20  Ns_iri(char const* nsiri, const std::size_t n) : str_(nsiri, n) {}
21 
22  bool operator==(Ns_iri const& n) const {return str_ == n.str_;}
23  bool operator==(std::string const& str) const {return str_ == str;}
24 
25  std::string const& str() const {return str_;}
26 
27 private:
28  std::string str_;
29 };
30 
31 template<class Ch, class Tr> inline std::basic_ostream<Ch,Tr>&
32  operator<<(std::basic_ostream<Ch,Tr>& os, Ns_iri const& ns_iri)
33 {return os << ns_iri.str();}
34 
35 inline std::size_t hash_value(Ns_iri const& n)
36 {return boost::hash_value(n.str());}
37 
44 inline Ns_iri remove_fragment(std::string const& iri, std::size_t& n) {
45  n = iri.find('#');
46  if( n == std::string::npos ) {
47  n = iri.size();
48  return Ns_iri(iri);
49  }
50  return Ns_iri(iri.substr(0,n++));
51 }
52 
57 inline Ns_iri remove_fragment(std::string const& iri) {
58  std::size_t n;
59  return remove_fragment(iri, n);
60 }
61 
62 inline std::string add_fragment(Ns_iri const& nsiri, std::string const& frag) {
63  return nsiri.str() + '#' + frag;
64 }
65 
66 
67 }//namespace owlcpp
68 #endif /* NS_IRI_HPP_ */