Allow the specification of custom container types in Thrift IDL files

Summary: If you want your map to be a hash_map instead of an stl::map, we now have a directive in Thrift to let you do that.

Instead of:
map<i32,i32>

You can do:
map[cpp:hash_map<int32_t,int32_t>]<i32,i32>

This tells the Thrift compiler to explicitly use whatever type was specified in the brackets when generating C++ code, instead of the implied Thrift type.

Reviewed By: aditya


git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@664828 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/compiler/cpp/src/parse/t_container.h b/compiler/cpp/src/parse/t_container.h
new file mode 100644
index 0000000..3b9f132
--- /dev/null
+++ b/compiler/cpp/src/parse/t_container.h
@@ -0,0 +1,37 @@
+#ifndef T_CONTAINER_H
+#define T_CONTAINER_H
+
+#include "t_type.h"
+
+class t_container : public t_type {
+ public:
+  t_container() :
+    cpp_name_(),
+    has_cpp_name_(false) {}
+
+  virtual ~t_container() {}
+
+  void set_cpp_name(std::string cpp_name) {
+    cpp_name_ = cpp_name;
+    has_cpp_name_ = true;
+  }
+
+  bool has_cpp_name() {
+    return has_cpp_name_;
+  }
+
+  std::string get_cpp_name() {
+    return cpp_name_;
+  }
+
+  bool is_container() const {
+    return true;
+  }
+
+ private:
+  std::string cpp_name_;
+  bool has_cpp_name_;
+
+};
+
+#endif
diff --git a/compiler/cpp/src/parse/t_list.h b/compiler/cpp/src/parse/t_list.h
index 5f9b5aa..bce5c0d 100644
--- a/compiler/cpp/src/parse/t_list.h
+++ b/compiler/cpp/src/parse/t_list.h
@@ -1,14 +1,14 @@
 #ifndef T_LIST_H
 #define T_LIST_H
 
-#include "t_type.h"
+#include "t_container.h"
 
 /**
  * A list is a lightweight container type that just wraps another data type.
  *
  * @author Mark Slee <mcslee@facebook.com>
  */
-class t_list : public t_type {
+class t_list : public t_container {
  public:
   t_list(t_type* elem_type) :
     elem_type_(elem_type) {}
diff --git a/compiler/cpp/src/parse/t_map.h b/compiler/cpp/src/parse/t_map.h
index ff1c569..fd55932 100644
--- a/compiler/cpp/src/parse/t_map.h
+++ b/compiler/cpp/src/parse/t_map.h
@@ -1,13 +1,15 @@
 #ifndef T_MAP_H
 #define T_MAP_H
 
+#include "t_container.h"
+
 /**
  * A map is a lightweight container type that just wraps another two data
  * types.
  *
  * @author Mark Slee <mcslee@facebook.com>
  */
-class t_map : public t_type {
+class t_map : public t_container {
  public:
   t_map(t_type* key_type, t_type* val_type) :
     key_type_(key_type),
diff --git a/compiler/cpp/src/parse/t_set.h b/compiler/cpp/src/parse/t_set.h
index e39e420..239868f 100644
--- a/compiler/cpp/src/parse/t_set.h
+++ b/compiler/cpp/src/parse/t_set.h
@@ -1,14 +1,14 @@
 #ifndef T_SET_H
 #define T_SET_H
 
-#include "t_type.h"
+#include "t_container.h"
 
 /**
  * A set is a lightweight container type that just wraps another data type.
  *
  * @author Mark Slee <mcslee@facebook.com>
  */
-class t_set : public t_type {
+class t_set : public t_container {
  public:
   t_set(t_type* elem_type) :
     elem_type_(elem_type) {}
diff --git a/compiler/cpp/src/parse/t_type.h b/compiler/cpp/src/parse/t_type.h
index 27b85a5..1d0a2ed 100644
--- a/compiler/cpp/src/parse/t_type.h
+++ b/compiler/cpp/src/parse/t_type.h
@@ -24,14 +24,11 @@
   virtual bool is_enum()      const { return false; }
   virtual bool is_struct()    const { return false; }
   virtual bool is_xception()  const { return false; }
+  virtual bool is_container() const { return false; }
   virtual bool is_list()      const { return false; }
   virtual bool is_set()       const { return false; }
   virtual bool is_map()       const { return false; }
 
-  bool is_container() const {
-    return is_map() || is_set() || is_list();
-  }
-
  protected:
   t_type() {}