Using ODF Relax NG schema to generate easier XML writing classes

Jos van den Oever jos at vandenoever.info
Fri Jun 10 07:43:39 BST 2011


On Friday, June 10, 2011 08:30:36 AM Pierre Stirnweiss wrote:
> I like the idea.
> On the headerWriter example you give, the end-element is written when the
> Writer gets out of scope. We'd need to verify that all our start/end
> element couples are within the same scope however.

Yes, i did this on purpose. Extra scopes can be added to force calling of the 
destructor. Alternatively, an endElement() function can be added.

I would love to know a way to make it impossible to compile code like this:
  TextPWriter textP1 = textContentWriter.startTextPWriter();
  TextPWriter textP2 = textContentWriter.startTextPWriter();
  textP1.writeText("hello");

At debug time, such errors can be detected by passing a digital baton between 
the classes and reporting an error if a class tries to write without having a 
baton. In the above code, the textP1 would have the baton and 
textContentWriiter cannot instantiate a textP2 until it gets back the baton 
when textP1 is destructed. That would add overhead that can disabled in a 
release.

Cheers,
Jos



More information about the calligra-devel mailing list