MICO Platform
 All Classes Namespaces Functions Variables Friends
rdf_query.hpp
1 #ifndef HAVE_RDF_QUERY_H
2 #define HAVE_RDF_QUERY_H 1
3 
4 #include <iostream>
5 #include <map>
6 #include <vector>
7 #include <string>
8 
9 
10 
11 namespace mico {
12  namespace rdf {
13  namespace model {
14  class Value;
15  }
16 
17  namespace query {
18 
23  typedef std::map<std::string,mico::rdf::model::Value*> BindingSet;
24 
25 
30  class QueryResult {
31  public:
32 
37  virtual void loadFrom(std::istream& is) = 0;
38 
39 
44  virtual void loadFrom(const char* ptr, size_t len) = 0;
45 
46  };
47 
51  class BooleanResult : public QueryResult {
52 
53  static void startElement(void *data, const char *el, const char **attr);
54  static void endElement(void *data, const char *el);
55  static void characterData(void *data, const char *chars, int len);
56 
57  private:
58  bool value;
59 
60  public:
61  BooleanResult() : value(false) {};
62  BooleanResult(bool value) : value(value) {};
63 
68  void loadFrom(std::istream& is);
69 
70 
75  void loadFrom(const char* ptr, size_t len);
76 
77 
78  // can be used as boolean value in boolean expressions...
79  inline operator bool() const { return value; };
80 
81  };
82 
83 
84 
89  class TupleResult : public QueryResult {
90 
91  private:
92  friend std::istream& operator>>(std::istream& is, TupleResult& r);
93  friend std::ostream& operator<<(std::ostream& is, TupleResult& r);
94 
95  std::vector<std::string> bindingNames;
96  std::vector<BindingSet> data;
97 
98  static void startElement(void *data, const char *el, const char **attr);
99  static void endElement(void *data, const char *el);
100  static void characterData(void *data, const char *chars, int len);
101 
102  public:
103 
104  virtual ~TupleResult() {};
105 
106 
110  const std::vector<std::string>& getBindingNames() const { return bindingNames; };
111 
112 
117  void loadFrom(std::istream& is);
118 
119 
124  void loadFrom(const char* ptr, size_t len);
125 
126 
127  // delegate methods
128  inline std::vector<BindingSet>::iterator begin() { return data.begin(); }
129  inline std::vector<BindingSet>::iterator end() { return data.end(); }
130  inline size_t size() const { return data.size(); }
131  inline BindingSet& at(size_t i) { return data.at(i); }
132  inline const BindingSet& at(size_t i) const { return data.at(i); }
133 
134  inline BindingSet& operator[](size_t i) { return data[i]; };
135  inline const BindingSet& operator[](size_t i) const { return data[i]; };
136  };
137 
138 
139 
140 
145  std::istream& operator>>(std::istream& is, TupleResult& r);
146  std::istream& operator>>(std::istream& is, BooleanResult& r);
147 
148 
152  std::ostream& operator<<(std::ostream& is, TupleResult& r);
153  std::ostream& operator<<(std::ostream& is, BooleanResult& r);
154 
155 
156  }
157  }
158 }
159 
160 
161 #endif
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in c...
Definition: http_client.cpp:23
friend std::ostream & operator<<(std::ostream &is, TupleResult &r)
Serialize query result data from the given argument into XML SPARQL protocol syntax.
Definition: rdf_query_tuple.cpp:33
Abstract base class for query results.
Definition: rdf_query.hpp:30
friend std::istream & operator>>(std::istream &is, TupleResult &r)
Load query result data represented in the XML SPARQL protocol syntax into the query result given as a...
Definition: rdf_query_tuple.cpp:316
The boolean result of a SPARQL ASK query.
Definition: rdf_query.hpp:51
void loadFrom(std::istream &is)
Load query result data represented in the XML SPARQL protocol syntax into the query result given as a...
Definition: rdf_query_bool.cpp:114
const std::vector< std::string > & getBindingNames() const
Return the binding names (variable names) contained in the result.
Definition: rdf_query.hpp:110
void loadFrom(std::istream &is)
Load query result data represented in the XML SPARQL protocol syntax into the query result given as a...
Definition: rdf_query_tuple.cpp:271
The result of a SPARQL SELECT query.
Definition: rdf_query.hpp:89
virtual void loadFrom(std::istream &is)=0
Load query result data represented in the XML SPARQL protocol syntax into the query result given as a...