00001
00002
00003 #ifndef DEV_W3_ORG__2001_BLINDFOLD_SRC_XSBMATCH_H
00004 #define DEV_W3_ORG__2001_BLINDFOLD_SRC_XSBMATCH_H
00005
00006 #include "config.h"
00007 #include "Query.h"
00008 #include <string>
00009 #include "ByteSink.h"
00010 #include "ByteFIFO.h"
00011 class XSBAgent;
00012 class XSBPool;
00013
00018 class XSBQuery : public Query {
00019
00020 public:
00021
00022
00023 XSBQuery(XSBAgent& agent, const XSBPool& dataset,
00024 const TripleSource& pattern);
00025 XSBQuery(const XSBQuery& other);
00026 const XSBQuery& operator=(const XSBQuery& other);
00027 bool operator==(const XSBQuery& other) const;
00028 bool operator<(const XSBQuery& other) const;
00029 size_t hash() const;
00030 friend std::ostream& operator<<(std::ostream& s, const XSBQuery& me);
00031 std::ostream& print_to(std::ostream& stream) const;
00032 virtual ~XSBQuery();
00033
00034
00035
00036 virtual bool advanceToFirst();
00037 virtual bool advanceToNext();
00038 virtual bool getResults();
00039 virtual void close();
00040 virtual Triple getFailurePoint();
00041
00042
00043
00044 void handleValue(int value);
00045
00046 bool getVarsMatchOnlyVars() { return varsMatchOnlyVars; }
00047 void setVarsMatchOnlyVars(bool newVal) {
00048 assert (!running);
00049 varsMatchOnlyVars = newVal;
00050 }
00051
00052 private:
00053 const TripleSource& pattern;
00054 const XSBPool& dataset;
00055 XSBAgent& agent;
00056 bool open;
00057 bool running;
00058 bool varsMatchOnlyVars;
00059
00060
00061 std::vector<Triple> pv;
00062
00063 char* fileName;
00064 std::ostream* file;
00065
00066 std::string runPredicate;
00067
00068 void writeFile();
00069 void printTriple(std::ostream& out, Triple t, int* maxVar) ;
00070
00071 int maxVar;
00072 enum { SEARCHING=1, READING_MATCH, READING_FAILURE, EXPECTING_END, ENDED } state ;
00073 enum { MATCH_FOLLOWS=1000, FAILPOINT_FOLLOWS };
00074 int readIndex;
00075
00076 bool success;
00077 Triple failurePoint;
00078
00079
00080 };
00081
00082 STANDARD_EXTERNAL(XSBQuery)
00083
00084 #endif
00085
00086