[cppx] Xerces strings simplified by ownership, part I.

For Windows, where wchar_t corresponds in size and encoding to XercesXMLCh, all that’s needed to convert from a wchar_t literal to Xerces XMLCh string is, at most, a little reinterpret_cast… But that won’t work on a system with 4 byte wchar_t or a system where wchar_t doesn’t imply Unicode. And although the non-Unicode systems are perhaps not your top porting priority, 4 byte wchar_t systems are common.

The wrapping that I start discussing in this posting, based on the cppx Ownership class, does a simple reinterpret_cast when it can (e.g. for a literal wchar_t string argument in Windows), and a dynamic allocation plus transcoding in other cases.

The Ownership wrapping of the result abstracts away the details of how the string is converted, and whether deallocation is needed. Thus, the calling code does not have to care. It gets raw null-operation efficiency where possible, and otherwise at least the same convenient notation + C++ RAII based safety. 🙂

[… More] Read all of this posting →