void replace_pword(std::ios_base& iob, int idx, const T& x) {
    iob.register_callback(callback<NewFormat>, idx);

    NewFormat* new_format(new NewFormat(x));
    OldFormat* old_format(static_cast<OldFormat*>(iob.pword(idx)));
    iob.pword(idx) = new_format;
    delete old_format;
}
示例#2
0
// Set print_context associated with stream, retain options
static void set_print_context(std::ios_base & s, const print_context & c)
{
	int i = my_ios_index();
	long flags = s.iword(i);
	if (!(flags & callback_registered)) {
		s.register_callback(my_ios_callback, i);
		s.iword(i) = flags | callback_registered;
	}
	print_context *p = static_cast<print_context *>(s.pword(i));
	unsigned options = p ? p->options : c.options;
	delete p;
	p = c.duplicate();
	p->options = options;
	s.pword(i) = p;
}