Forum Navigation
Pluggable formatting
Posted: 08/13/08 15:29:08Layout!(T) works, but the only way that I can add support for my own types is if I override toString. This doesn't allow me to specify formatting options, which is a minor annoyance sometimes. More importantly, it forces me to put presentation logic into my domain classes. That is evil.
I'd like to see a formatter system more like:
class Formatter { public IFormattingProvider[TypeInfo] formatters; ... char[] formatSingle(TypeInfo info, void* object, char[] arguments) { if (info in formatters) { return formatters[info].format(info, object, arguments); } return defaultFormatter.format(info, object, arguments); } }The major problems I see with this setup are: - Lots of heap activity. - It doesn't deal with inheritance. If I don't have a formatter set up for a class, I probably want to default to the formatter for its parent class.
The latter can be dealt with by making formatting even more expensive, or simply not dealt with -- if I didn't provide a formatting provider for class Inherited, there's no indication that the provider for class Base will be appropriate.
I'll implement something like this and submit it, but I'm curious: how many people here would find that useful?












