Details
-
New Feature
-
Status: Closed
-
Minor
-
Resolution: Won't Fix
-
0.8
-
None
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
Attachments
Issue Links
- is duplicated by
-
THRIFT-2255 add Parent Class for generated Struct class
- Closed
- is related to
-
THRIFT-3382 TBase class for C++ Library
- Closed