Version: unspecified (using KDE 4.5.1) OS: Linux [This relates to my work on an Okteta Structure Definition for Compound File Binary File Format, which is described in MS-CFB specification] The use of enums is quite useful, but some fields are "mostly values, sometimes enums". As an example, CFB has the concept of a 32-bit sector number (basically like an on-disk filesystem), but sector numbers can have special values to indicate something other than a normal sector, and I'd like to add a text annotation to explain that. It might look like: "0x00000001" for a normal value and like: "0xFFFFFFFE (ENDOFCHAIN)" or "0xFFFFFFFF (Free sector)" for a special case. A couple of ideas for how this could work: - add an optional "default" element for the enum definition which could just show the unadorned value for things that are not specified in the enum - add some kind of display formatter to allow annotation for values based on an enum. [This is relatively low priority, but would be nice-to-have] Reproducible: Always
Added to my TODO list, Do you think it would be useful to be able to define the formatting of the enum value e.g. like this "%x (Free sector)" or "Free sector (value=%x)" and maybe %d for decimal or would it suffice to always have the value follwed by the enum constant name? Since this is not much work to implement, the chances are high it will make it into the next version :)
I think that value followed by enum constant name (if present) would be sufficient. I can see that a more flexible display system would be (a little) better, because you can separate the internal format (16 bit value) from the display (signed 16 bit integer vs unsigned 16 bit integer vs 16 bit enum vs 16 bit flags vs wide character) but I'm not sure if the impact of existing tools would be worth the pain.
Git commit 75df4af37e02d94e83758397f965eba2efc3e8cf by Alex Richardson. Committed on 13/03/2013 at 00:32. Pushed by arichardson into branch 'master'. structures: allow custom string representations of values + unit test Also install a script that allows creating UUID/GUID structures with such a custom to string function. It can be used by writing this: var x = importScript('uuid.js') var myUUID = x.UUID() var myGUID = x.GUID() Related: bug 263496 M +3 -1 kasten/controllers/CMakeLists.txt A +100 -0 kasten/controllers/test/customtostringtest.cpp [License: LGPL (v2.1+)] A +36 -0 kasten/controllers/test/resources/okteta/structures/uuid.js M +13 -0 kasten/controllers/test/testutils.h M +1 -1 kasten/controllers/view/structures/datatypes/additionaldata.h M +12 -1 kasten/controllers/view/structures/datatypes/datainformation.cpp M +17 -3 kasten/controllers/view/structures/datatypes/datainformation.h M +10 -0 kasten/controllers/view/structures/parsers/datainformationfactory.cpp M +2 -1 kasten/controllers/view/structures/parsers/datainformationfactory.h M +1 -0 kasten/controllers/view/structures/parsers/osdparser.cpp M +1 -0 kasten/controllers/view/structures/parsers/parserutils.h M +1 -0 kasten/controllers/view/structures/parsers/scriptvalueconverter_p.cpp M +13 -8 kasten/controllers/view/structures/script/classes/defaultscriptclass.cpp M +1 -0 kasten/controllers/view/structures/script/classes/defaultscriptclass.h M +14 -0 kasten/controllers/view/structures/script/scripthandler.cpp M +1 -0 kasten/controllers/view/structures/script/scripthandler.h M +2 -1 kasten/controllers/view/structures/script/scripthandlerinfo.h http://commits.kde.org/okteta/75df4af37e02d94e83758397f965eba2efc3e8cf