streaming redux

Michel Fortin michel.fortin at michelf.com
Tue Dec 28 10:49:08 PST 2010


On 2010-12-28 13:07:56 -0500, Sean Kelly <sean at invisibleduck.org> said:

> Michel Fortin Wrote:
>> 
>> So because of all this virtual dispatch and all this rigidity, I think
>> Formatter needs to be rethought a little. My preference obviously goes
>> to satically-typed formatters. But what I'd like to see is something
>> like this:
>> 
>> 	interface Serializable(F) {
>> 		void writeTo(F formatter);
>> 	}
>> 
>> Any object can implement a serialization for a given formatter by
>> implementing the interface above parametrized with the formatter type.
> 
> I like it.  There needs to be some way to hold format-specific state 
> info for a stream though.  I guess this could be done via an external 
> hash (stream address to formatter state), but it would be nicer if this 
> could be stored in the stream itself somehow.

The 'F' formatter can be anything, it can be a class, a delegate, a 
struct (although for a struct you might want to pass it as 'ref')... so 
it *can* hold a state. Or am I missing something?

If we want to specify additional parameters to writeTo for a given 
formatter, such as a format string, then the Serializable interface 
template could introspect type F to find what additional arguments it 
wants writeTo to have.


-- 
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/



More information about the Digitalmars-d mailing list