summaryrefslogtreecommitdiff
path: root/libxsd/xsd/cxx/tree/istream.hxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2010-05-21 19:18:52 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2010-05-21 19:18:52 +0200
commit9a764d4ed5606c5f171ae05a7409128a88184b11 (patch)
tree8f1c862354e5c6f112e7e52e3641ad87e4d276df /libxsd/xsd/cxx/tree/istream.hxx
parentefb2476d01b2bcc62569c8748327754a836195c3 (diff)
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.
Diffstat (limited to 'libxsd/xsd/cxx/tree/istream.hxx')
-rw-r--r--libxsd/xsd/cxx/tree/istream.hxx46
1 files changed, 46 insertions, 0 deletions
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 <map>
+#include <string>
+#include <memory> // std::auto_ptr
#include <cstddef> // std::size_t
#include <xsd/cxx/tree/istream-fwd.hxx>
@@ -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 <typename C>
+ void
+ pool_add (const std::basic_string<C>& s)
+ {
+ typedef pool_impl<C> pool_type;
+
+ if (pool_.get () == 0)
+ pool_.reset (new pool_type);
+
+ pool_type& p (*static_cast<pool_type*> (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<S>::pool_string<C>.
+ //
+ template <typename C>
+ void
+ pool_string (std::size_t id, std::basic_string<C>& out)
+ {
+ typedef pool_impl<C> pool_type;
+ pool_type& p (*static_cast<pool_type*> (pool_.get ()));
+ out = p[id - 1];
+ }
+
public:
// 8-bit
//
@@ -190,7 +223,20 @@ namespace xsd
operator= (const istream&);
private:
+ struct pool
+ {
+ virtual
+ ~pool () {}
+ };
+
+ template <typename C>
+ struct pool_impl: pool, std::vector<std::basic_string<C> >
+ {
+ };
+
S& s_;
+ std::size_t seq_;
+ std::auto_ptr<pool> pool_;
};