owlcpp  v0.3.3~
C++ library for working with OWL ontologies
 All Classes Namespaces Files Functions Macros Pages
raptor_wrapper.hpp
Go to the documentation of this file.
1 
6 #ifndef RAPTOR_WRAPPER_HPP_
7 #define RAPTOR_WRAPPER_HPP_
8 #include <iosfwd>
9 #include <string>
10 #include "boost/assert.hpp"
11 #include "boost/bind.hpp"
12 #include "boost/function.hpp"
13 #include "boost/shared_ptr.hpp"
14 #include "owlcpp/io/config.hpp"
15 #include "owlcpp/io/exception.hpp"
16 
17 typedef struct raptor_parser_s raptor_parser;
18 typedef struct raptor_world_s raptor_world;
19 typedef struct raptor_uri_s raptor_uri;
20 
21 namespace owlcpp{
22 
25 class OWLCPP_IO_DECL Raptor_wrapper {
26  typedef void (*handle_statement_fun_t)(void *, const void*);
27  typedef bool (*stop_parsing_fun_t)(const void *);
28 
29  static char* blank_prefix_char() {
30  static char pref[] = "b";
31  return pref;
32  }
33 public:
34  struct Err : public Input_err {};
35 
36  static std::string const& blank_prefix() {
37  static const std::string pref(blank_prefix_char());
38  return pref;
39  }
40 
42 
43  template<class Sink> void operator()(std::istream& stream, Sink& sink) {
44  setup(&sink, &handle_statement<Sink>);
45  parse(stream);
46  }
47 
48  template<class Sink> void operator()(std::string const& file, Sink& sink) {
49  setup(&sink, &handle_statement<Sink>);
50  parse(file);
51  }
52 
53  const boost::function<void()> abort_call() {
54  return boost::bind(&Raptor_wrapper::abort_parse, this);
55  }
56 
57 private:
58  boost::shared_ptr<raptor_world> world_;
59  boost::shared_ptr<raptor_parser> parser_;
60  bool abort_requested_;
61 
62  void abort_parse();
63 
64  void setup(void* sink, handle_statement_fun_t hs_fun);
65 
66  void parse(std::istream&);
67 
68  void parse(std::string const&);
69 
70  template<class Sink> static void handle_statement(void* data, const void* rs) {
71  static_cast<Sink*>(data)->insert(rs);
72  }
73 
74 };
75 }//namespace owlcpp
76 #endif /* RAPTOR_WRAPPER_HPP_ */