[ 
https://issues.apache.org/jira/browse/THRIFT-1712?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Martin Vogt updated THRIFT-1712:
--------------------------------

    Attachment: 010_base_struct_gen_140628v1.patch
                000_line_first_140628v1.patch

>Henrique Mendonça added a comment - 24/Jun/14 10:01:
>Thanks for your patches! Contribution is what we need, but please try to 
>add at least one test case on each patch and for each variant you are 
>>proposing. 

Thanks for the feedback. I will add a test case.
Additionally I have reworked the patch, the current
 version has a new approach:

- It needs less changes to the code
- It is more generic

The "line_first" modifier allows to set a custom include path and the 
base_struct modifier adds a given string at the right place.
Both options are "always on", but in the default case only
insert a "comment" /* xyz modifier off */

regards,

Martin




> Add TBase class for c++
> -----------------------
>
>                 Key: THRIFT-1712
>                 URL: https://issues.apache.org/jira/browse/THRIFT-1712
>             Project: Thrift
>          Issue Type: New Feature
>          Components: C++ - Compiler
>    Affects Versions: 0.8
>            Reporter: Martin Vogt
>            Assignee: Ben Craig
>            Priority: Minor
>              Labels: base, c++, class
>         Attachments: 000_line_first_140628v1.patch, 
> 010_base_struct_gen_140628v1.patch
>
>
> 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:
> {code:title=MyService.thrift}
> struct MyStruct {
>    1:i32 val;
> }
> service MyService {
>    void doSomething();
> }
> {code}
> thrift --gen cpp:line_first='#include <path/TBase.h>',base_struct=':public 
> TBase' ./MyService.thrift
> {code:title=MyService_types.h}
> #ifndef MyService_TYPES_H
> #define MyService_TYPES_H
> #include <path/TBase.h>
> #include <thrift/Thrift.h>
> [....]
> class MyStruct:public TBase {
> [...]
> {code}
> The default, without any option:
> thrift --gen cpp ./MyService.thrift
> {code:title=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) */ {
> [...
> {code}
> The idea is to have a base class for typecasting, which can be done with:
> {code}
> void processSignal(const TBase& tBase) {
>   if (typeid(tBase).name() == typeid(MyStruct).name()) 
>     printf("MyStruct found!\n")
>  
> {code}



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Reply via email to