Draft searchFileVisitor

This commit is contained in:
Bruno
2021-02-13 13:45:00 +01:00
parent a1e4709910
commit 25c2bb59f5
2 changed files with 76 additions and 5 deletions

View File

@@ -39,3 +39,52 @@ void SearchVisitor::visit(Scene &n)
// search only in workspace // search only in workspace
n.ws()->accept(*this); 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)
{
}

View File

@@ -1,6 +1,7 @@
#ifndef SEARCHVISITOR_H #ifndef SEARCHVISITOR_H
#define SEARCHVISITOR_H #define SEARCHVISITOR_H
#include <string>
#include "Visitor.h" #include "Visitor.h"
class SearchVisitor: public Visitor class SearchVisitor: public Visitor
@@ -14,12 +15,33 @@ public:
inline Node *node() const { return found_ ? node_ : nullptr; } inline Node *node() const { return found_ ? node_ : nullptr; }
// Elements of Scene // Elements of Scene
void visit(Scene& n); void visit(Scene& n) override;
void visit(Node& n); void visit(Node& n) override;
void visit(Primitive&) {} void visit(Primitive&) override {}
void visit(Group& n); void visit(Group& n) override;
void visit(Switch& n); 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 #endif // SEARCHVISITOR_H