]> Creatis software - cpPlugins.git/blobdiff - lib/mstch/visitor/is_node_empty.hpp
Moved to version 1.0
[cpPlugins.git] / lib / mstch / visitor / is_node_empty.hpp
diff --git a/lib/mstch/visitor/is_node_empty.hpp b/lib/mstch/visitor/is_node_empty.hpp
new file mode 100644 (file)
index 0000000..a0ae432
--- /dev/null
@@ -0,0 +1,41 @@
+#pragma once
+
+#include <boost/variant/static_visitor.hpp>
+
+#include "mstch/mstch.hpp"
+
+namespace mstch {
+
+class is_node_empty: public boost::static_visitor<bool> {
+ public:
+  template<class T>
+  bool operator()(const T&) const {
+    return false;
+  }
+
+  bool operator()(const std::nullptr_t&) const {
+    return true;
+  }
+
+  bool operator()(const int& value) const {
+    return value == 0;
+  }
+
+  bool operator()(const double& value) const {
+    return value == 0;
+  }
+
+  bool operator()(const bool& value) const {
+    return !value;
+  }
+
+  bool operator()(const std::string& value) const {
+    return value == "";
+  }
+
+  bool operator()(const array& array) const {
+    return array.size() == 0;
+  }
+};
+
+}