]> Creatis software - cpPlugins.git/blobdiff - lib/mstch/visitor/has_token.hpp
Moved to version 1.0
[cpPlugins.git] / lib / mstch / visitor / has_token.hpp
diff --git a/lib/mstch/visitor/has_token.hpp b/lib/mstch/visitor/has_token.hpp
new file mode 100644 (file)
index 0000000..5ab30d4
--- /dev/null
@@ -0,0 +1,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;
+};
+
+}