]> Creatis software - cpPlugins.git/blob - lib/mstch/visitor/get_token.hpp
Moved to version 1.0
[cpPlugins.git] / lib / mstch / visitor / get_token.hpp
1 #pragma once
2
3 #include <boost/variant/static_visitor.hpp>
4
5 #include "mstch/mstch.hpp"
6 #include "has_token.hpp"
7
8 namespace mstch {
9
10 class get_token: public boost::static_visitor<const mstch::node&> {
11  public:
12   get_token(const std::string& token, const mstch::node& node):
13       m_token(token), m_node(node)
14   {
15   }
16
17   template<class T>
18   const mstch::node& operator()(const T&) const {
19     return m_node;
20   }
21
22   const mstch::node& operator()(const map& map) const {
23     return map.at(m_token);
24   }
25
26   const mstch::node& operator()(const std::shared_ptr<object>& object) const {
27     return object->at(m_token);
28   }
29
30  private:
31   const std::string& m_token;
32   const mstch::node& m_node;
33 };
34
35 }