Uploaded image for project: 'Thrift'
  1. Thrift
  2. THRIFT-2494

Add enum toString helper function in c_glib

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 0.9.2
    • C glib - Compiler
    • None
    • Patch Available

    Description

      If I have IDL like this:

      enum CertificateStoreType
      {
      CERT = 1,
      PKCS12 = 2
      }

      In header file, it will be:

      enum _CertificateStoreType {
      CERTIFICATE_STORE_TYPE_CERT = 1,
      CERTIFICATE_STORE_TYPE_PKCS12 = 2
      };
      typedef enum _CertificateStoreType CertificateStoreType;

      + /* return the name of the constant */
      + const char *
      + toString_CertificateStoreType(int value);

      In c file

      + /* return the name of the constant */
      + const char *
      + toString_CertificateStoreType(int value)
      + {
      + static __thread char buf[16] =

      {0}

      ;
      + switch(value)

      { + case CERTIFICATE_STORE_TYPE_CERT:return "CERTIFICATE_STORE_TYPE_CERT"; + case CERTIFICATE_STORE_TYPE_PKCS12:return "CERTIFICATE_STORE_TYPE_PKCS12"; + default: g_snprintf(buf, 16, "%d", value); return buf; + }

      + }

      Attachments

        1. c_glib_enum_toString.diff
          1 kB
          Xiaodong Ma

        Activity

          People

            roger Roger Meier
            xiaodongma Xiaodong Ma
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: