diff --git a/SearchVisitor.cpp b/SearchVisitor.cpp index fa4bc02..1a2512f 100644 --- a/SearchVisitor.cpp +++ b/SearchVisitor.cpp @@ -39,3 +39,52 @@ void SearchVisitor::visit(Scene &n) // search only in workspace n.ws()->accept(*this); } + + + +SearchFileVisitor::SearchFileVisitor(std::string filename) : Visitor(), filename_(filename), found_(false) +{ + +} + + +void SearchFileVisitor::visit(Node &n) +{ + +} + +void SearchFileVisitor::visit(Group &n) +{ + if (found_) + return; + + for (NodeSet::iterator node = n.begin(); node != n.end(); node++) { + (*node)->accept(*this); + if (found_) + break; + } +} + +void SearchFileVisitor::visit(Switch &n) +{ + if (n.numChildren()>0) + n.activeChild()->accept(*this); +} + + +void SearchFileVisitor::visit(Scene &n) +{ + // search only in workspace + n.ws()->accept(*this); +} + + +void SearchFileVisitor::visit (MediaSource& s) +{ + +} + +void SearchFileVisitor::visit (SessionFileSource& s) +{ + +} diff --git a/SearchVisitor.h b/SearchVisitor.h index 20a6642..a927108 100644 --- a/SearchVisitor.h +++ b/SearchVisitor.h @@ -1,6 +1,7 @@ #ifndef SEARCHVISITOR_H #define SEARCHVISITOR_H +#include #include "Visitor.h" class SearchVisitor: public Visitor @@ -14,12 +15,33 @@ public: inline Node *node() const { return found_ ? node_ : nullptr; } // Elements of Scene - void visit(Scene& n); - void visit(Node& n); - void visit(Primitive&) {} - void visit(Group& n); - void visit(Switch& n); + void visit(Scene& n) override; + void visit(Node& n) override; + void visit(Primitive&) override {} + void visit(Group& n) override; + void visit(Switch& n) override; }; +class SearchFileVisitor: public Visitor +{ + std::string filename_; + bool found_; + +public: + SearchFileVisitor(std::string filename); + inline bool found() const { return found_; } + + // Elements of Scene + void visit(Scene& n) override; + void visit(Node& n) override; + void visit(Primitive&) override {} + void visit(Group& n) override; + void visit(Switch& n) override; + + // Sources + void visit (MediaSource& s) override; + void visit (SessionFileSource& s) override; +}; + #endif // SEARCHVISITOR_H