aboutsummaryrefslogtreecommitdiff
path: root/libxsde/xsde/cxx/hybrid/parser-map.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'libxsde/xsde/cxx/hybrid/parser-map.cxx')
-rw-r--r--libxsde/xsde/cxx/hybrid/parser-map.cxx59
1 files changed, 59 insertions, 0 deletions
diff --git a/libxsde/xsde/cxx/hybrid/parser-map.cxx b/libxsde/xsde/cxx/hybrid/parser-map.cxx
new file mode 100644
index 0000000..c19325c
--- /dev/null
+++ b/libxsde/xsde/cxx/hybrid/parser-map.cxx
@@ -0,0 +1,59 @@
+// file : xsde/cxx/hybrid/parser-map.cxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC
+// license : GNU GPL v2 + exceptions; see accompanying LICENSE file
+
+#include <string.h> // strcmp
+
+#include <xsde/cxx/hybrid/parser-map.hxx>
+
+namespace xsde
+{
+ namespace cxx
+ {
+ namespace hybrid
+ {
+ parser::parser_base* parser_map_impl::
+ find (const char* tid) const
+ {
+ // Binary search.
+ //
+ if (size_ == 0)
+ return 0;
+
+ size_t l = 0;
+ size_t h = size_ - 1;
+
+ while (l <= h)
+ {
+ size_t m = l + (h - l)/2;
+ int r = strcmp (entries_[m].type_id, tid);
+
+ if (r > 0)
+ h = m - 1;
+ else if (r < 0)
+ l = m + 1;
+ else
+ return entries_[m].parser;
+ }
+
+ return 0;
+ }
+
+ void parser_map_impl::
+ reset () const
+ {
+ if (resetting_)
+ return;
+
+ bool& r = const_cast<bool&> (resetting_);
+ r = true;
+
+ for (const entry* p = entries_; p != entries_ + size_; ++p)
+ p->parser->_reset ();
+
+ r = false;
+ }
+ }
+ }
+}