OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
t_generator_registry.h
Go to the documentation of this file.
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  */
19 
20 #ifndef T_GENERATOR_REGISTRY_H
21 #define T_GENERATOR_REGISTRY_H
22 
23 class t_generator;
24 
33  public:
34  t_generator_factory(const std::string& short_name,
35  const std::string& long_name,
36  const std::string& documentation);
37 
38  virtual ~t_generator_factory() {}
39 
40  virtual t_generator* get_generator(
41  // The program to generate.
42  t_program* program,
43  // Note: parsed_options will not exist beyond the call to get_generator.
44  const std::map<std::string, std::string>& parsed_options,
45  // Note: option_string might not exist beyond the call to get_generator.
46  const std::string& option_string)
47  = 0;
48 
49  virtual bool is_valid_namespace(const std::string& sub_namespace) = 0;
50 
51  std::string get_short_name() { return short_name_; }
52  std::string get_long_name() { return long_name_; }
53  std::string get_documentation() { return documentation_; }
54 
55  private:
56  std::string short_name_;
57  std::string long_name_;
58  std::string documentation_;
59 };
60 
61 template <typename generator>
63  public:
64  t_generator_factory_impl(const std::string& short_name,
65  const std::string& long_name,
66  const std::string& documentation)
67  : t_generator_factory(short_name, long_name, documentation)
68  {}
69 
71  t_program* program,
72  const std::map<std::string, std::string>& parsed_options,
73  const std::string& option_string) {
74  return new generator(program, parsed_options, option_string);
75  }
76 
77  virtual bool is_valid_namespace(const std::string& sub_namespace) {
78  return generator::is_valid_namespace(sub_namespace);
79  }
80 };
81 
83  public:
84  static void register_generator(t_generator_factory* factory);
85 
86  static t_generator* get_generator(t_program* program,
87  const std::string& options);
88 
89  typedef std::map<std::string, t_generator_factory*> gen_map_t;
90  static gen_map_t& get_generator_map();
91 
92  private:
95 };
96 
97 #define THRIFT_REGISTER_GENERATOR(language, long_name, doc) \
98  class t_##language##_generator_factory_impl \
99  : public t_generator_factory_impl<t_##language##_generator> \
100  { \
101  public: \
102  t_##language##_generator_factory_impl() \
103  : t_generator_factory_impl<t_##language##_generator>( \
104  #language, long_name, doc) \
105  {} \
106  }; \
107  static t_##language##_generator_factory_impl _registerer;
108 
109 #endif
t_generator_factory_impl(const std::string &short_name, const std::string &long_name, const std::string &documentation)
t_generator_factory(const std::string &short_name, const std::string &long_name, const std::string &documentation)
Definition: t_generator.cc:180
virtual bool is_valid_namespace(const std::string &sub_namespace)=0
static void register_generator(t_generator_factory *factory)
Definition: t_generator.cc:129
static Options options
std::map< std::string, t_generator_factory * > gen_map_t
static gen_map_t & get_generator_map()
Definition: t_generator.cc:174
virtual t_generator * get_generator(t_program *program, const std::map< std::string, std::string > &parsed_options, const std::string &option_string)=0
std::string get_short_name()
std::string get_documentation()
virtual t_generator * get_generator(t_program *program, const std::map< std::string, std::string > &parsed_options, const std::string &option_string)
static t_generator * get_generator(t_program *program, const std::string &options)
Definition: t_generator.cc:137
virtual bool is_valid_namespace(const std::string &sub_namespace)