From 707cc94fe52463870a9c6c8e2e66eaaa389e601d Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 24 Feb 2009 15:16:26 +0200 Subject: Start tracking XSD/e with git after version 3.0.0 --- .../xsde/cxx/parser/validating/inheritance-map.cxx | 111 +++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 libxsde/xsde/cxx/parser/validating/inheritance-map.cxx (limited to 'libxsde/xsde/cxx/parser/validating/inheritance-map.cxx') diff --git a/libxsde/xsde/cxx/parser/validating/inheritance-map.cxx b/libxsde/xsde/cxx/parser/validating/inheritance-map.cxx new file mode 100644 index 0000000..491ec8d --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/inheritance-map.cxx @@ -0,0 +1,111 @@ +// file : xsde/cxx/parser/validating/inheritance-map.cxx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include + +#include // strcmp + +#ifndef XSDE_EXCEPTIONS +# include // assert +# include // exit +#endif + +#include +#include + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + inheritance_map* inheritance_map_init::map = 0; + size_t inheritance_map_init::count = 0; + + bool inheritance_map:: + check (const char* derived, const char* base) const + { + if (strcmp (derived, base) == 0) + return true; + + const void* p = find (derived); + + if (p) + { + const char* b = *static_cast (p); + return strcmp (base, b) == 0 ? true : check (b, base); + } + + return false; + } + + // inheritance_map_init + // + inheritance_map_init:: + inheritance_map_init () + { + if (count == 0) + { + map = new inheritance_map (XSDE_PARSER_IMAP_BUCKETS); + +#ifndef XSDE_EXCEPTIONS + if (map == 0 || map->_error () != inheritance_map::error_none) + { + // This is static initialization so there is nothing we can do. + // The best thing is to fail fast. abort() would have probably + // been the better choice here but it is not available on some + // platforms (notably, WinCE). + // + assert (false); + exit (1); + } +#endif + } + + ++count; + } + + inheritance_map_init:: + ~inheritance_map_init () + { + if (--count == 0) + delete map; + } + + // inheritance_map_entry + // + inheritance_map_entry:: + inheritance_map_entry (const char* derived, const char* base) + { + inheritance_map& m = inheritance_map_instance (); + m.insert (derived, base); + +#ifndef XSDE_EXCEPTIONS + if (m._error () != inheritance_map::error_none) + { + // This is static initialization so there is nothing we can do. + // The best thing is to fail fast. abort() would have probably + // been the better choice here but it is not available on some + // platforms (notably, WinCE). + // + assert (false); + exit (1); + } +#endif + } + + // + // + size_t + parser_imap_elements () + { + return inheritance_map_instance ().size (); + } + } + } + } +} -- cgit v1.1