diff options
| author | Mistivia <i@mistivia.com> | 2025-01-16 15:43:04 +0800 |
|---|---|---|
| committer | Mistivia <i@mistivia.com> | 2025-01-16 15:53:58 +0800 |
| commit | 8689a7c78c50676ea739f52fbcee9f091709f5c0 (patch) | |
| tree | bbb72c68e5e1753f751133941a402caa43e29a16 /lib/mstch/src/visitor/get_token.hpp | |
| parent | 00afb767ae37488d99f78363d031b898b1932354 (diff) | |
add mstch
Diffstat (limited to 'lib/mstch/src/visitor/get_token.hpp')
| -rw-r--r-- | lib/mstch/src/visitor/get_token.hpp | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/lib/mstch/src/visitor/get_token.hpp b/lib/mstch/src/visitor/get_token.hpp new file mode 100644 index 0000000..d41ab6e --- /dev/null +++ b/lib/mstch/src/visitor/get_token.hpp @@ -0,0 +1,35 @@ +#pragma once + +#include <boost/variant/static_visitor.hpp> + +#include "mstch/mstch.hpp" +#include "has_token.hpp" + +namespace mstch { + +class get_token: public boost::static_visitor<const mstch::node&> { + public: + get_token(const std::string& token, const mstch::node& node): + m_token(token), m_node(node) + { + } + + template<class T> + const mstch::node& operator()(const T&) const { + return m_node; + } + + const mstch::node& operator()(const map& map) const { + return map.at(m_token); + } + + const mstch::node& operator()(const std::shared_ptr<object>& object) const { + return object->at(m_token); + } + + private: + const std::string& m_token; + const mstch::node& m_node; +}; + +} |
