Index: manip.hpp =================================================================== --- manip.hpp (revision 83587) +++ manip.hpp (working copy) @@ -11,7 +11,6 @@ #include #include -#include #include // Tuple I/O manipulators @@ -46,36 +45,46 @@ return index; } - template + template struct stream_data { - struct arena + typedef FUSION_STRING_OF_STREAM(Stream) string_type; + + static void attach(Stream& s, string_type const& data) { - ~arena() - { - for ( - typename std::vector::iterator i = data.begin() - ; i != data.end() - ; ++i) - { - delete *i; - } - } + delete_this(s); // last manipulator over-writes previous - std::vector data; - }; + get_ptr_ref(s) = new string_type(data); - static void attach(Stream& stream, T const& data) + s.register_callback(erase, index()); + } + + static string_type const* get(Stream& s) { - static arena ar; // our arena - ar.data.push_back(new T(data)); - stream.pword(get_xalloc_index()) = ar.data.back(); + return get_ptr_ref(s); } - static T const* get(Stream& stream) + private: + + static int index() { return get_xalloc_index(); } + + static string_type const*& get_ptr_ref(std::ios_base& s) { - return (T const*)stream.pword(get_xalloc_index()); + return (string_type const*&)s.pword(index()); } + + static void erase(std::ios_base::event ev, std::ios_base& s, int idx) + { + if(std::ios_base::erase_event == ev && index() == idx) + { + delete_this(s); + } + } + + static void delete_this(std::ios_base& s) + { + delete get_ptr_ref(s); get_ptr_ref(s) = 0; + } }; template @@ -85,7 +94,7 @@ typedef FUSION_STRING_OF_STREAM(Stream) string_type; - typedef stream_data stream_data_t; + typedef stream_data stream_data_t; string_ios_manip(Stream& str_) : stream(str_)