]> git.lyx.org Git - features.git/commitdiff
prepare switch to switch-case in when parsing tex files
authorPeter Kümmel <syntheticpp@gmx.net>
Sun, 20 Nov 2011 19:44:08 +0000 (19:44 +0000)
committerPeter Kümmel <syntheticpp@gmx.net>
Sun, 20 Nov 2011 19:44:08 +0000 (19:44 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@40232 a592a061-630c-0410-9148-cb99ea01b6c8

src/Text.cpp
src/support/metahash.h [new file with mode: 0644]

index 3cf1de49043f8fbb213201231caf6f3ded573af6..d3a122660da0636278e2972f3d3b387edcf243df 100644 (file)
 
 #include <sstream>
 
+
+// TODO: replace if in Text::readParToken() with compile time switch
+#if 0
+
+#include "support/metahash.h"
+
+typedef boost::mpl::string<'\\end','_lay','out'> end_layout;
+typedef boost::mpl::string<'\\end','in','set'>   end_inset;
+
+void foo()
+{
+       std::string token = "\\end_layout";
+
+       switch (boost::hash_value(token)) {
+               case lyx::support::hash_string<end_layout>::value:
+                       return;
+               case lyx::support::hash_string<end_inset>::value:
+                       return;
+               default: ;
+       };
+
+}
+#endif
+
+
 using namespace std;
 using namespace lyx::support;
 
@@ -316,6 +341,7 @@ InsetText const & Text::inset() const
 }
 
 
+
 void Text::readParToken(Paragraph & par, Lexer & lex,
        string const & token, Font & font, Change & change, ErrorList & errorList)
 {
diff --git a/src/support/metahash.h b/src/support/metahash.h
new file mode 100644 (file)
index 0000000..84f6062
--- /dev/null
@@ -0,0 +1,73 @@
+// -*- C++ -*-
+/**
+ * \file methash.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Peter Kümmel
+ *
+ * Full author contact details are available in file CREDITS.
+ *
+ * Code by Tor Brede Vekterli 
+ * http://arcticinteractive.com/2009/04/18/compile-time-string-hashing-boost-mpl/
+ * (Boost 1.0 license.)
+ *
+ */
+
+#ifndef LYX_META_HASH_H
+#define LYX_META_HASH_H
+
+#include <boost/mpl/string.hpp>
+#include <boost/mpl/fold.hpp>
+#include <boost/mpl/size_t.hpp>
+#include <boost/functional/hash.hpp>
+
+
+
+namespace lyx {
+namespace support {
+
+#ifdef _MSC_VER
+#pragma warning(push)
+// disable addition overflow warning
+#pragma warning(disable:4307)
+#endif
+
+    template <typename Seed, typename Value>
+    struct hash_combine
+    {
+      typedef boost::mpl::size_t<
+        Seed::value ^ (static_cast<std::size_t>(Value::value)
+               + 0x9e3779b9 + (Seed::value << 6) + (Seed::value >> 2))
+      > type;
+    };
+
+#ifdef _MSC_VER
+#pragma warning(pop)
+#endif
+
+    // Hash any sequence of integral wrapper types
+    template <typename Sequence>
+    struct hash_sequence
+      : boost::mpl::fold<
+            Sequence
+          , boost::mpl::size_t<0> 
+                 , hash_combine<boost::mpl::_1, boost::mpl::_2>
+        >::type
+    {};
+
+    // For hashing std::strings et al that don't include the zero-terminator
+    template <typename String>
+    struct hash_string : hash_sequence<String>
+    {};
+
+    // Hash including terminating zero for char arrays
+    template <typename String>
+    struct hash_cstring
+      : hash_combine< hash_sequence<String>, boost::mpl::size_t<0> >::type
+    {};
+
+} 
+}
+
+#endif