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

Add TBase class for c++

    XMLWordPrintableJSON

    Details

    • Type: New Feature
    • Status: Closed
    • Priority: Minor
    • Resolution: Won't Fix
    • Affects Version/s: 0.8
    • Fix Version/s: None
    • Component/s: C++ - Compiler
    • Labels:

      Description

      The generated c++ classes for struct's do not have a common base class.

      The patch adds two options to the compiler:

      • line_first : first line before all includes
      • base_struct : custom base class for structs

      For example:

      MyService.thrift
      struct MyStruct {
         1:i32 val;
      }
      service MyService {
         void doSomething();
      }
      

      thrift --gen cpp:line_first='#include <path/TBase.h>',base_struct=':public TBase' ./MyService.thrift

      MyService_types.h
      #ifndef MyService_TYPES_H
      #define MyService_TYPES_H
      
      #include <path/TBase.h>
      #include <thrift/Thrift.h>
      [....]
      class MyStruct:public TBase {
      [...]
      

      The default, without any option:

      thrift --gen cpp ./MyService.thrift

      MyService_types.h
      #ifndef MyService_TYPES_H
      #define MyService_TYPES_H
      
      /* first line (modifier:off) */
      #include <thrift/Thrift.h>
      [....]
      class MyStruct /* base_struct (modifier:off) */ {
      [...
      
      

      The idea is to have a base class for typecasting, which can be done with:

      void processSignal(const TBase& tBase) {
        if (typeid(tBase).name() == typeid(MyStruct).name()) 
          printf("MyStruct found!\n")
       
      

        Attachments

        1. 000_line_first_140628v1.patch
          3 kB
          Martin Vogt
        2. 010_base_struct_gen_140629v1.patch
          2 kB
          Martin Vogt
        3. 011_base_struct_rest_140619v2.patch
          2 kB
          Martin Vogt

          Issue Links

            Activity

              People

              • Assignee:
                ben.craig Ben Craig
                Reporter:
                mvogt1 Martin Vogt
              • Votes:
                3 Vote for this issue
                Watchers:
                7 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: