Home Help Center

How to define a variant type?

fengxbfengxb Member feng xuebinOrganization: jiexin techProject: scientific calculation
Hi,

Did anybody define "Variant" data type like windows's COM in ICE? I had defined a struct to present the variant.

enum ValueType {VTINT, VTSHORT, VTLONG, VTFLOAT, VTDOUBLE, VTSTRING, VTBYTE, VTBOOLEAN,
VTINTSEQ, VTSHORTSEQ, VTLONGSEQ, VTFLOATSEQ, VTDOUBLESEQ, VTSTRINGSEQ, VTBYTESEQ, VTBOOLEANSEQ};
struct Variant
{
ValueType type;
Ice::ByteSeq byValues;
};

I'm not very satisfact with the definition. Have any more suggestion?

Thanks in advance.

Comments

  • marcmarc FloridaAdministrators, ZeroC Staff Marc LaukienOrganization: ZeroC, Inc.Project: The Internet Communications Engine ZeroC Staff
    Is "Variant" the same as a union type? If so, I recommend to use a class hierarchy, e.g.:

    class VariantBase { };

    class VariantInt extends VariantBase { int value; };

    class VariantDouble extends VariantBase { double value; };

    etc.
  • fengxbfengxb Member feng xuebinOrganization: jiexin techProject: scientific calculation
    Thanks a lot. Let me try.
Sign In or Register to comment.