Ticket #8336: manip.hpp.patch
File manip.hpp.patch, 2.7 KB (added by , 10 years ago) |
---|
-
manip.hpp
11 11 12 12 #include <boost/config.hpp> 13 13 #include <string> 14 #include <vector>15 14 #include <cctype> 16 15 17 16 // Tuple I/O manipulators … … 46 45 return index; 47 46 } 48 47 49 template <typename Stream, typename Tag , typename T>48 template <typename Stream, typename Tag> 50 49 struct stream_data 51 50 { 52 struct arena 51 typedef FUSION_STRING_OF_STREAM(Stream) string_type; 52 53 static void attach(Stream& s, string_type const& data) 53 54 { 54 ~arena() 55 { 56 for ( 57 typename std::vector<T*>::iterator i = data.begin() 58 ; i != data.end() 59 ; ++i) 60 { 61 delete *i; 62 } 63 } 55 delete_this(s); // last manipulator over-writes previous 64 56 65 std::vector<T*> data; 66 }; 57 get_ptr_ref(s) = new string_type(data); 67 58 68 static void attach(Stream& stream, T const& data) 59 s.register_callback(erase, index()); 60 } 61 62 static string_type const* get(Stream& s) 69 63 { 70 static arena ar; // our arena 71 ar.data.push_back(new T(data)); 72 stream.pword(get_xalloc_index<Tag>()) = ar.data.back(); 64 return get_ptr_ref(s); 73 65 } 74 66 75 static T const* get(Stream& stream) 67 private: 68 69 static int index() { return get_xalloc_index<Tag>(); } 70 71 static string_type const*& get_ptr_ref(std::ios_base& s) 76 72 { 77 return ( T const*)stream.pword(get_xalloc_index<Tag>());73 return (string_type const*&)s.pword(index()); 78 74 } 75 76 static void erase(std::ios_base::event ev, std::ios_base& s, int idx) 77 { 78 if(std::ios_base::erase_event == ev && index() == idx) 79 { 80 delete_this(s); 81 } 82 } 83 84 static void delete_this(std::ios_base& s) 85 { 86 delete get_ptr_ref(s); get_ptr_ref(s) = 0; 87 } 79 88 }; 80 89 81 90 template <typename Tag, typename Stream> … … 85 94 86 95 typedef FUSION_STRING_OF_STREAM(Stream) string_type; 87 96 88 typedef stream_data<Stream, Tag , string_type> stream_data_t;97 typedef stream_data<Stream, Tag> stream_data_t; 89 98 90 99 string_ios_manip(Stream& str_) 91 100 : stream(str_)