aboutsummaryrefslogtreecommitdiff
path: root/lib/mstch/src/visitor/has_token.hpp
blob: 5ab30d46b62f7d746055a6a94aa9fe8924ee8c7f (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
#pragma once

#include <boost/variant/static_visitor.hpp>

#include "mstch/mstch.hpp"

namespace mstch {

class has_token: public boost::static_visitor<bool> {
 public:
  has_token(const std::string& token): m_token(token) {
  }

  template<class T>
  bool operator()(const T&) const {
    return m_token == ".";
  }

  bool operator()(const map& map) const {
    return map.count(m_token) == 1;
  }

  bool operator()(const std::shared_ptr<object>& object) const {
    return object->has(m_token);
  }

 private:
  const std::string& m_token;
};

}