Jez Higgins

Freelance software generalist
software created
extended or repaired


Older posts are available in the archive or through tags.

Feed

Follow me on Twitter
My code on GitHub

Contact
About

Wednesday 17 October 2001 Arabica

The expat wrapper is now parameterised on string type and string conversion policy, which isn't nearly as frightening as it sounds. Basically, you specify what output string type you want, typically std::string and a supply a second type which knows how to convert const char* (expat's native string type) to std::string. Obviously that's a pretty trivial example.

It get's more interesting if you're using some custom string type, or you want std::wstrings containing UCS-2 Unicode instead of expat's UTF-8 encoded const char*. In cases like this, the string conversion policy class would need to a little more work (although not too much). The big gain is that you can just drop it straight in, and the expat wrapper will hand out what you want. No second conversion layer on top, no further fiddling. Cool.

Andrei Alexandrescu's fantastic book Modern C++ Design describes this design approach in much more, and more illuminating, detail.


Tagged code, arabica, xml, and c++


Jez Higgins

Freelance software generalist
software created
extended or repaired

Older posts are available in the archive or through tags.

Feed

Follow me on Twitter
My code on GitHub

Contact
About