1 // Copyright (c) 2006- Facebook
2 // Distributed under the Thrift Software License
4 // See accompanying file LICENSE or visit the Thrift site at:
5 // http://developers.facebook.com/thrift/
19 #include "t_base_type.h"
20 #include "t_typedef.h"
24 #include "t_service.h"
31 * Top level class representing an entire thrift program. A program consists
32 * fundamentally of the following:
41 * The program module also contains the definitions of the base types.
43 * @author Mark Slee <mcslee@facebook.com>
45 class t_program
: public t_doc
{
47 t_program(std::string path
, std::string name
) :
51 scope_
= new t_scope();
54 t_program(std::string path
) :
57 name_
= program_name(path
);
58 scope_
= new t_scope();
62 const std::string
& get_path() const { return path_
; }
64 // Output path accessor
65 const std::string
& get_out_path() const { return out_path_
; }
68 const std::string
& get_name() const { return name_
; }
71 const std::string
& get_namespace() const { return namespace_
; }
73 // Accessors for program elements
74 const std::vector
<t_typedef
*>& get_typedefs() const { return typedefs_
; }
75 const std::vector
<t_enum
*>& get_enums() const { return enums_
; }
76 const std::vector
<t_const
*>& get_consts() const { return consts_
; }
77 const std::vector
<t_struct
*>& get_structs() const { return structs_
; }
78 const std::vector
<t_struct
*>& get_xceptions() const { return xceptions_
; }
79 const std::vector
<t_service
*>& get_services() const { return services_
; }
82 void add_typedef (t_typedef
* td
) { typedefs_
.push_back(td
); }
83 void add_enum (t_enum
* te
) { enums_
.push_back(te
); }
84 void add_const (t_const
* tc
) { consts_
.push_back(tc
); }
85 void add_struct (t_struct
* ts
) { structs_
.push_back(ts
); }
86 void add_xception (t_struct
* tx
) { xceptions_
.push_back(tx
); }
87 void add_service (t_service
* ts
) { services_
.push_back(ts
); }
89 // Programs to include
90 const std::vector
<t_program
*>& get_includes() const { return includes_
; }
92 void set_out_path(std::string out_path
) {
94 // Ensure that it ends with a trailing '/' (or '\' for windows machines)
95 char c
= out_path_
.at(out_path_
.size() - 1);
96 if (!(c
== '/' || c
== '\\')) {
97 out_path_
.push_back('/');
101 // Scoping and namespacing
102 void set_namespace(std::string name
) {
113 void add_include(std::string path
) {
114 includes_
.push_back(new t_program(path
));
117 std::vector
<t_program
*>& get_includes() {
121 // Language specific namespace / packaging
123 void set_cpp_namespace(std::string cpp_namespace
) {
124 cpp_namespace_
= cpp_namespace
;
127 const std::string
& get_cpp_namespace() const {
128 return cpp_namespace_
;
131 void add_cpp_include(std::string path
) {
132 cpp_includes_
.push_back(path
);
135 const std::vector
<std::string
>& get_cpp_includes() {
136 return cpp_includes_
;
139 void set_php_namespace(std::string php_namespace
) {
140 php_namespace_
= php_namespace
;
143 const std::string
& get_php_namespace() const {
144 return php_namespace_
;
147 void set_java_package(std::string java_package
) {
148 java_package_
= java_package
;
151 const std::string
& get_java_package() const {
152 return java_package_
;
155 void set_csharp_namespace(std::string csharp_namespace
) {
156 csharp_namespace_
= csharp_namespace
;
159 const std::string
& get_csharp_namespace() const {
160 return csharp_namespace_
;
163 void set_xsd_namespace(std::string xsd_namespace
) {
164 xsd_namespace_
= xsd_namespace
;
167 const std::string
& get_xsd_namespace() const {
168 return xsd_namespace_
;
171 void set_ruby_namespace(std::string ruby_namespace
) {
172 ruby_namespace_
= ruby_namespace
;
175 const std::string
& get_ruby_namespace() const {
176 return ruby_namespace_
;
179 void set_py_module(std::string py_module
) {
180 py_module_
= py_module
;
183 const std::string
& get_py_module() const {
187 void set_perl_package(std::string perl_package
) {
188 perl_package_
= perl_package
;
191 const std::string
& get_perl_package() const {
192 return perl_package_
;
195 void set_cocoa_prefix(std::string cocoa_prefix
) {
196 cocoa_prefix_
= cocoa_prefix
;
199 const std::string
& get_cocoa_prefix() const {
200 return cocoa_prefix_
;
203 void set_smalltalk_category(std::string smalltalk_category
) {
204 smalltalk_category_
= smalltalk_category
;
207 const std::string
& get_smalltalk_category() const {
208 return smalltalk_category_
;
211 void set_smalltalk_prefix(std::string smalltalk_prefix
) {
212 smalltalk_prefix_
= smalltalk_prefix
;
215 const std::string
& get_smalltalk_prefix() const {
216 return smalltalk_prefix_
;
228 std::string out_path_
;
231 std::string namespace_
;
234 std::vector
<t_program
*> includes_
;
236 // Identifier lookup scope
239 // Components to generate code for
240 std::vector
<t_typedef
*> typedefs_
;
241 std::vector
<t_enum
*> enums_
;
242 std::vector
<t_const
*> consts_
;
243 std::vector
<t_struct
*> structs_
;
244 std::vector
<t_struct
*> xceptions_
;
245 std::vector
<t_service
*> services_
;
248 std::string cpp_namespace_
;
250 // C++ extra includes
251 std::vector
<std::string
> cpp_includes_
;
254 std::string php_namespace_
;
257 std::string java_package_
;
260 std::string xsd_namespace_
;
263 std::string ruby_namespace_
;
266 std::string py_module_
;
269 std::string perl_package_
;
271 // Cocoa/Objective-C naming prefix
272 std::string cocoa_prefix_
;
274 // Smalltalk category
275 std::string smalltalk_category_
;
277 std::string smalltalk_prefix_
;
280 std::string csharp_namespace_
;