aboutsummaryrefslogtreecommitdiff
path: root/lib/mstch/src/visitor/has_token.hpp
diff options
context:
space:
mode:
authorMistivia <i@mistivia.com>2025-01-16 15:43:04 +0800
committerMistivia <i@mistivia.com>2025-01-16 15:53:58 +0800
commit8689a7c78c50676ea739f52fbcee9f091709f5c0 (patch)
treebbb72c68e5e1753f751133941a402caa43e29a16 /lib/mstch/src/visitor/has_token.hpp
parent00afb767ae37488d99f78363d031b898b1932354 (diff)
add mstch
Diffstat (limited to 'lib/mstch/src/visitor/has_token.hpp')
-rw-r--r--lib/mstch/src/visitor/has_token.hpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/lib/mstch/src/visitor/has_token.hpp b/lib/mstch/src/visitor/has_token.hpp
new file mode 100644
index 0000000..5ab30d4
--- /dev/null
+++ b/lib/mstch/src/visitor/has_token.hpp
@@ -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;
+};
+
+}