You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by "Vitali Lovich (JIRA)" <ji...@apache.org> on 2014/10/08 00:09:34 UTC

[jira] [Created] (THRIFT-2772) reduce manual maintenance required for cpp_type & cpp_include

Vitali Lovich created THRIFT-2772:
-------------------------------------

             Summary: reduce manual maintenance required for cpp_type & cpp_include
                 Key: THRIFT-2772
                 URL: https://issues.apache.org/jira/browse/THRIFT-2772
             Project: Thrift
          Issue Type: Bug
          Components: C++ - Compiler, Compiler (General)
            Reporter: Vitali Lovich


If I want to reference thrift types in a custom unordered_map currently:

     // foo.thrift defines Foo
     namespace cpp me::thrift::foo

     // bar.thrift defined Bar
     namespace cpp me::thrift::bar

    // foobar.thrift
    namespace cpp me::thrift
    include "foo.thrift"
    include "bar.thrift"

    cpp_include "<unordered_map>"

    message Foobar {
        map cpp_type "std::unordered_map<foo::Foo, bar::Bar>" <Foo, Bar> mapping;
    }

Downsides:
1) Requires me to have a good rule for generating package names from the get-go.
2) If I change the namespace name, I have to know *all* the spots to update it.
3) If I change the type name, I have to modify it in an extra spot that's not validated by the compiler.
4) I have to duplicate the cpp_include statement across all thrift files & know the mapping.

A more maintainable mechanism would be a type-mapping file supported by the compiler.

type UnorderedMap<T1, T2> {
    cpp_include = "<unordered_map>"
    cpp_type = "std::unordered_map<$T1, $T2>"
    java_type = "java.util.HashMap"
}

Then:
   include "UnorderedMap.thrift"

   message Foo {
       UnorderedMap<T1, T2> foo;
   }



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)