initial commit
[menupp.git] / src / option.hpp
blob6972e19e42bde631d00077802f0343d8bf8b759a
1 #ifndef MENUPP_OPTION_HPP_
2 #define MENUPP_OPTION_HPP_
4 #include "node.hpp"
6 #include <ostream>
7 #include <iterator>
9 namespace Menu
12 template<typename F>
13 class Option: public INode
15 NodeId _id;
16 const char* _label;
17 F _f;
19 public:
20 explicit Option(const char* label, F f)
21 : _label(label), _f(f) {}
23 NodeId id() const override { return _id; }
25 void set_id(NodeId id) override { _id = id; }
27 void dump(std::ostream& os, size_t indent, size_t total_indent) const override
29 (void) indent;
30 std::fill_n(std::ostream_iterator<char>(os), total_indent, ' ');
31 os << "Option" << _id << ": \"" << label() << "\"\n";
34 NodeId move(Move m) override
36 switch (m) {
37 case Move::Into:
38 _f();
39 return _id.parent();
40 case Move::Up:
41 case Move::Down:
42 case Move::Left:
43 case Move::Right:
44 return NodeId();
46 return NodeId();
49 INode* get(size_t) override { return nullptr; }
51 const char* label() const override { return _label; }
56 #endif // MENUPP_OPTION_HPP_