From 9a764d4ed5606c5f171ae05a7409128a88184b11 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 21 May 2010 19:18:52 +0200 Subject: Pool polymorphic type-id strings in binary representations Add support for an implicit string pool in istream and ostream templates. Use this support to pool type namespace and name when dealing with polymorphic types. --- libxsd/xsd/cxx/tree/istream.hxx | 46 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'libxsd/xsd/cxx/tree/istream.hxx') diff --git a/libxsd/xsd/cxx/tree/istream.hxx b/libxsd/xsd/cxx/tree/istream.hxx index 07bba53..a4daa3e 100644 --- a/libxsd/xsd/cxx/tree/istream.hxx +++ b/libxsd/xsd/cxx/tree/istream.hxx @@ -6,6 +6,9 @@ #ifndef XSD_CXX_TREE_ISTREAM_HXX #define XSD_CXX_TREE_ISTREAM_HXX +#include +#include +#include // std::auto_ptr #include // std::size_t #include @@ -138,6 +141,36 @@ namespace xsd return s_; } + // Add string to the pool. The application should add every + // potentially pooled string to correctly re-create the pool + // constructed during insertion. + // + template + void + pool_add (const std::basic_string& s) + { + typedef pool_impl pool_type; + + if (pool_.get () == 0) + pool_.reset (new pool_type); + + pool_type& p (*static_cast (pool_.get ())); + p.push_back (s); + } + + // Get string from pool id. We return the result via an argument + // instead of as a return type to avoid difficulties some compilers + // (e.g., GCC) experience with calls like istream::pool_string. + // + template + void + pool_string (std::size_t id, std::basic_string& out) + { + typedef pool_impl pool_type; + pool_type& p (*static_cast (pool_.get ())); + out = p[id - 1]; + } + public: // 8-bit // @@ -190,7 +223,20 @@ namespace xsd operator= (const istream&); private: + struct pool + { + virtual + ~pool () {} + }; + + template + struct pool_impl: pool, std::vector > + { + }; + S& s_; + std::size_t seq_; + std::auto_ptr pool_; }; -- cgit v1.1