Home Bug Reports

Ice::OutputStream::writeEnum should be virtual

grembogrembo Member Michael GmelinOrganization: Grem Equity GmbHProject: E-Commerce platform
Therefore it cannot be overriden (Stream.h).


  • mesmes CaliforniaAdministrators, ZeroC Staff Mark SpruiellOrganization: ZeroC, Inc.Project: Ice Developer ZeroC Staff

    Is there a particular use case you had in mind that we're preventing you from implementing here?

  • grembogrembo Member Michael GmelinOrganization: Grem Equity GmbHProject: E-Commerce platform
    Hi mes,

    My use case was a little debugging tool that allows me to convert any slice defined structure to a string (similar to str(...) in python). This works pretty well for most constructs, by using --stream on slice2cpp and implementing a custom OutputStream and a couple of StreamHelper replacements (all of this is template based, so no classic polymorphism involved). Things get problematic in case of classes and exceptions, as those can only be serialized by (ab)using __write, which uses an OutputStreamPtr and classic polymorphism. There are two problems here, one is the template function write (so none of my replacement StreamHelpers work, no formatting, indentation etc. - not too nice, but somehow acceptable for a debug function) and writeEnum, which for some reason is not virtual like its siblings. This would call writeSize by default, which is not very helpful for debuggging, as there is no context. Fortunately worked around this by making getEncoding return version 1.0, so it will call writeInt (not too nice, as I still don't have any context that this is writing an enum, but at least there is reasonable output).

    What I would like to do:
    • mark writeEnum as virtual (for the sake of uniformity)
    • make slice2cpp --stream generate functions in the header for exceptions and classes similar to those for structs (so it won't rely on classic polymorphism) - or a similar workaround, that allows using a different write template function.

    Right now, my toString tool works pretty well for standard types (even good enough that something like a toJSON function would be feasible), but for classes and exceptions the output lacks readability.
Sign In or Register to comment.