Converting between C enum and XML

前端 未结 5 374
遇见更好的自我
遇见更好的自我 2020-12-04 20:21

What\'s the cleanest way to store an enum in XML and read it back out again? Say I\'ve got:

enum ETObjectType {ETNormalObjectType, ETRareObjectType, ETEssent         


        
5条回答
  •  忘掉有多难
    2020-12-04 21:13

    The great thing of XML is that it can transform to nearly anything, even to code. It just takes (a lot of) effort to make the translation once. I have worked in several projects where XML was translated to code. And this saved a lot of time. This technique is for instance, covered in chapter 12 of the book "XSLT Cookbook 2nd edition, S. Mangano, O'Reilley".

    It's not an easy solution, but if you have a good mapping you - have a single point of definition (your xml) - can generate .h files with enum - can generate tables or functions to read/write values in xml

    It depends on the number of enums and how often they change if it is worthwhile. Good luck!

提交回复
热议问题