aboutsummaryrefslogtreecommitdiff
path: root/lib/mstch/src/visitor/get_token.hpp
blob: d41ab6eb1ef7c4ee97d4e5a9eeaa9af197e24a8e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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;
};

}