Just a little something I've been working on the past few days.
Code:
class LeafTester1 : public BeTree::Leaf
{
private:
public:
LeafTester1() { };
virtual void Run()
{
std::cout << "LeafTester1 " << 1 << "\n";
yield(BeTree::RUNNING);
std::cout << "LeafTester1 " << 2 << "\n";
yield(BeTree::FAILURE);
};
};
class LeafTester2 : public BeTree::Leaf
{
private:
public:
LeafTester2() { };
virtual void Run()
{
std::cout << "LeafTester2 " << 1 << "\n";
yield(BeTree::RUNNING);
std::cout << "LeafTester2 " << 2 << "\n";
yield(BeTree::SUCCESS);
};
};
Code:
int main(int argc, char* argv[])
{
try
{
using namespace BeTree;
std::auto_ptr<Parallel> par(new Parallel(2));
LeafTester1* lt1 = new LeafTester1();
LeafTester2* lt2 = new LeafTester2();
par->AddChild(lt1);
par->AddChild(lt2);
while(true)
{
std::cout << "Pulsing...\n";
auto ret = par->Execute();
if(ret == SUCCESS || ret == FAILURE)
break;
}
} catch(const boost::exception& ex)
{
std::cout << boost::diagnostic_information_what(ex) << "\n";
}
std::cin.clear();
std::cin.get();
return 0;
}
Output:
Code:
D:\Projects\Common Libs\BeTree>TreeEx.exe
Pulsing...
LeafTester1 1
LeafTester2 1
Pulsing...
LeafTester1 2
D:\Projects\Common Libs\BeTree>
Uses Fiber API internally to implement coroutines in the leaf nodes. Sequences, Selectors, Parallels are "hard-wired" to work(FSM-like).
Feel free to criticize. This is my first real C++ project, and it was quite an undertaking. Simple a PoC at this point.