#include "graphsearch/Pattern.h"
namespace GSearch {
enum InquiryType {
UnionInquiry,
IntersectionInquiry,
PatternInquiry,
PathInquiry
};
struct SearchStage {
InquiryType type;
Pattern *pattern; StrGraph result;
bool done;
SearchStage(StrGraph *parent) : pattern(0),result(parent),done(false) {}
SearchStage(const SearchStage &o) : type(o.type),pattern(o.pattern),result(o.result),done(false) {}
};
struct NamedStage : Name,SearchStage {
NamedStage(const NamedStage &o) : Name(o),SearchStage(o) {}
NamedStage(StrGraph *parent,DString name) : Name(name),SearchStage(parent) {}
};
typedef std::map<DString,StrGraph*> Inputs;
struct Search : LGraph<Nothing,NamedStage,Name> {
StrGraph &source;
std::map<DString,Node*> dict;
Search(const Search ©) : Graph(copy),source(copy.source) { for(node_iter ni = nodes().begin(); ni!=nodes().end(); ++ni)
dict[gd<Name>(*ni)] = *ni;
}
Search(StrGraph &source);
void readStrGraph(Patterns &patterns,StrGraph &desc);
void Run(const Inputs &inputs);
Node *create_node(DString name) {
Node *n = Graph::create_node(NamedStage(&source,name));
dict[name] = n;
return n;
}
void reset() {
for(node_iter ni = nodes().begin(); ni!=nodes().end(); ++ni) {
Node *n = *ni;
SearchStage &stage = gd<SearchStage>(n);
stage.done = false;
stage.result.clear();
}
}
};
struct StageNotFound : DGException {
DString name;
StageNotFound(DString name) : DGException("search stage not found (impossible!)"),
name(name) {}
};
struct PatternNotThere : DGException {
PatternNotThere() : DGException("search stage is supposed to execute a pattern, but the pattern wasn't specified") {}
};
struct PatternStateNotFound : DGException {
DString name;
PatternStateNotFound(DString name) : DGException("input state of pattern not found"),
name(name) {}
};
struct UnknownAction : DGException {
DString name; UnknownAction(DString name) : DGException("stage's action type not recognized"),
name(name) {}
};
struct UndefinedPattern : DGException {
DString name;
UndefinedPattern(DString name) : DGException("pattern not defined"),
name(name) {}
};
}