A portable bitfied code generator



  • As everyone should know, the C++ standard doesn't require nor guarantee that different compiler vendors and platforms implement bitfields in a portable manner. So if you really need to use bit packing and enjoy portability, raw serialization and such, you have to write it by hand. Which turns out is a tedious task, and since I work on a project that makes heavy use of those, I decided to spend some time on a neat little tool to generate the code in just a few seconds.

    You can select how wide is the container type, from 8 to 64 bit, in case all fields don't fit in one container, an array of the right size will be used instead. "prefix getter" will result in a "getField()" rather than "field()" getter. The container name can be selected (make sure you press enter after you modify it), and the output can additional be formatted, just make sure you don't mess with the "tokens" in CAPS. The generator will trim out zero shifts, which may cause bugs if you mess with the formatting beyond adding stuff like new lines before { and } and spaces for indentation (the QML element doesn't accept tabs). Up down left right will move selected fields unless a text field has taken the focus.

    For convenience I've put it all in a "single source, so just copy, paste and run":http://pastebin.com/96VcGKub

    Let me know if you find bugs, I haven't really tested it thoroughly

    !http://oi59.tinypic.com/qqa04j.jpg(1)!
    !http://oi60.tinypic.com/wtx446.jpg(2)!
    !http://oi59.tinypic.com/6iwh91.jpg(3)!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.