Make the Cocoa generator dynamic.
authorDavid Reiss <dreiss@apache.org>
Thu, 27 Mar 2008 21:40:55 +0000 (21:40 +0000)
committerDavid Reiss <dreiss@apache.org>
Thu, 27 Mar 2008 21:40:55 +0000 (21:40 +0000)
- Modify the Cocoa generator constructor to fit the new generic interface.
- Register the Cocoa genrator with the central registry.
- Deprecate the old way of invoking the Cocoa generator.
- main.cc no longer includes t_cocoa_generator.h.

git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665603 13f79535-47bb-0310-9956-ffa450edef68

compiler/cpp/src/generate/t_cocoa_generator.cc
compiler/cpp/src/generate/t_cocoa_generator.h
compiler/cpp/src/main.cc

index 2b325c4..4be14db 100644 (file)
@@ -1867,3 +1867,6 @@ string t_cocoa_generator::format_string_for_type(t_type* type) {
 string t_cocoa_generator::call_field_setter(t_field* tfield, string fieldName) {
   return "[self set" + capitalize(tfield->get_name()) + ": " + fieldName + "];";
 }
+
+
+THRIFT_REGISTER_GENERATOR(cocoa, "Cocoa", "");
index 79f3007..1d68fa5 100644 (file)
  */
 class t_cocoa_generator : public t_oop_generator {
  public:
-  t_cocoa_generator(t_program* program) :
-    t_oop_generator(program) {
+  t_cocoa_generator(
+      t_program* program,
+      const std::map<std::string, std::string>& parsed_options,
+      const std::string& option_string)
+    : t_oop_generator(program)
+  {
     out_dir_base_ = "gen-cocoa";
   }
 
index dfd5f9e..3499035 100644 (file)
@@ -41,7 +41,6 @@
 #include "generate/t_xsd_generator.h"
 #include "generate/t_perl_generator.h"
 #include "generate/t_erl_generator.h"
-#include "generate/t_cocoa_generator.h"
 #include "generate/t_csharp_generator.h"
 
 using namespace std;
@@ -610,7 +609,6 @@ void usage() {
   fprintf(stderr, "  -xsd        Generate XSD output files\n");
   fprintf(stderr, "  -perl       Generate Perl output files\n");
   fprintf(stderr, "  -erl        Generate Erlang output files\n");
-  fprintf(stderr, "  -cocoa      Generate Cocoa/Objective-C output files\n");
   fprintf(stderr, "  -csharp     Generate C# output files\n");
   fprintf(stderr, "  -o dir      Set the output directory for gen-* packages\n");
   fprintf(stderr, "               (default: current directory)\n");
@@ -909,13 +907,6 @@ void generate(t_program* program, const vector<string>& generator_strings) {
       delete erl;
     }
 
-    if (gen_cocoa) {
-      pverbose("Generating Cocoa/Objective-C\n");
-      t_cocoa_generator* cocoa = new t_cocoa_generator(program);
-      cocoa->generate_program();
-      delete cocoa;
-    }
-
     if (gen_csharp) {
       pverbose("Generating C#\n");
       t_csharp_generator* csharp = new t_csharp_generator(program);
@@ -1116,6 +1107,10 @@ int main(int argc, char** argv) {
     pwarning(1, "-javabean is deprecated.  Use --gen java:beans");
     generator_strings.push_back("java:beans");
   }
+  if (gen_cocoa) {
+    pwarning(1, "-cocoa is deprecated.  Use --gen cocoa");
+    generator_strings.push_back("cocoa");
+  }
   if (gen_st) {
     pwarning(1, "-st is deprecated.  Use --gen st");
     generator_strings.push_back("st");
@@ -1130,7 +1125,7 @@ int main(int argc, char** argv) {
   }
 
   // You gotta generate something!
-  if (!gen_php && !gen_phpi && !gen_py && !gen_rb && !gen_xsd && !gen_perl && !gen_erl && !gen_cocoa && !gen_csharp && generator_strings.empty()) {
+  if (!gen_php && !gen_phpi && !gen_py && !gen_rb && !gen_xsd && !gen_perl && !gen_erl && !gen_csharp && generator_strings.empty()) {
     fprintf(stderr, "!!! No output language(s) specified\n\n");
     usage();
   }