99
99
///////////////////////////////////////////////////////////////////////////////
101
101
} // namespace transcode
103
///////////////////////////////////////////////////////////////////////////////
107
// Both new & delete are done here inside Zorba rather than in the header to
108
// guarantee that they're cross-DLL-boundary safe on Windows.
110
zorba::transcode::streambuf*
111
alloc_streambuf( char const *charset, std::streambuf *orig ) {
112
return new zorba::transcode::streambuf( charset, orig );
115
void dealloc_streambuf( zorba::transcode::streambuf *buf ) {
119
int get_streambuf_index() {
121
// This function is out-of-line because it has a static constant within it.
122
// It has a static constant within it to guarantee (1) initialization before
123
// use and (2) initialization happens exactly once.
125
// See: "Standard C++ IOStreams and Locales: Advanced Programmer's Guide and
126
// Reference," Angelika Langer and Klaus Kreft, Addison-Wesley, 2000, section
127
// 3.3.1.1: "Initializing and Maintaining the iword/pword Index."
129
// See: "The C++ Programming Language," Bjarne Stroustrup, Addison-Wesley,
130
// 2000, section 10.4.8: "Local Static Store."
132
static int const index = ios_base::xalloc();
136
void stream_callback( ios_base::event e, ios_base &ios, int index ) {
138
// See: "Standard C++ IOStreams and Locales: Advanced Programmer's Guide and
139
// Reference," Angelika Langer and Klaus Kreft, Addison-Wesley, 2000, section
140
// 3.3.1.4: "Using Stream Callbacks for Memory Management."
142
if ( e == ios_base::erase_event )
143
delete static_cast<streambuf*>( ios.pword( index ) );
146
} // namespace internal
148
///////////////////////////////////////////////////////////////////////////////
102
150
} // namespace zorba
103
151
/* vim:set et sw=2 ts=2: */