Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame^] | 1 | #ifndef T_PROGRAM_H |
| 2 | #define T_PROGRAM_H |
| 3 | |
| 4 | #include <string> |
| 5 | #include <vector> |
| 6 | |
| 7 | #include "t_base_type.h" |
| 8 | #include "t_typedef.h" |
| 9 | #include "t_enum.h" |
| 10 | #include "t_struct.h" |
| 11 | #include "t_service.h" |
| 12 | |
| 13 | /** |
| 14 | * Top level class representing an entire thrift program. A program consists |
| 15 | * fundamentally of the following: |
| 16 | * |
| 17 | * Typedefs |
| 18 | * Enumerations |
| 19 | * Structs |
| 20 | * Services |
| 21 | * |
| 22 | * @author Mark Slee <mcslee@facebook.com> |
| 23 | */ |
| 24 | class t_program { |
| 25 | public: |
| 26 | t_program(std::string name) : |
| 27 | name_(name) { |
| 28 | type_void = new t_base_type("void", t_base_type::TYPE_VOID); |
| 29 | type_string = new t_base_type("string", t_base_type::TYPE_STRING); |
| 30 | type_byte = new t_base_type("byte", t_base_type::TYPE_BYTE); |
| 31 | type_i32 = new t_base_type("i32", t_base_type::TYPE_I32); |
| 32 | type_u32 = new t_base_type("u32", t_base_type::TYPE_U32); |
| 33 | type_i64 = new t_base_type("i64", t_base_type::TYPE_I64); |
| 34 | type_u64 = new t_base_type("u64", t_base_type::TYPE_U64); |
| 35 | } |
| 36 | |
| 37 | ~t_program() { |
| 38 | delete type_string; |
| 39 | delete type_byte; |
| 40 | delete type_i32; |
| 41 | delete type_u32; |
| 42 | delete type_i64; |
| 43 | delete type_u64; |
| 44 | } |
| 45 | |
| 46 | // Name accessor |
| 47 | const std::string& get_name() const { return name_; } |
| 48 | |
| 49 | // Accessors for program elements |
| 50 | const std::vector<t_typedef*>& get_typedefs() const { return typedefs_; } |
| 51 | const std::vector<t_enum*>& get_enums() const { return enums_; } |
| 52 | const std::vector<t_struct*>& get_structs() const { return structs_; } |
| 53 | const std::vector<t_service*>& get_services() const { return services_; } |
| 54 | |
| 55 | // New program element addition |
| 56 | void add_typedef(t_typedef *td) { typedefs_.push_back(td); } |
| 57 | void add_enum (t_enum *te) { enums_.push_back(te); } |
| 58 | void add_struct (t_struct *ts) { structs_.push_back(ts); } |
| 59 | void add_service(t_service *ts) { services_.push_back(ts); } |
| 60 | |
| 61 | // Accessors for global types |
| 62 | t_type* get_void_type() const { return type_void; } |
| 63 | t_type* get_string_type() const { return type_string; } |
| 64 | t_type* get_byte_type() const { return type_byte; } |
| 65 | t_type* get_i32_type() const { return type_i32; } |
| 66 | t_type* get_u32_type() const { return type_u32; } |
| 67 | t_type* get_i64_type() const { return type_i64; } |
| 68 | t_type* get_u64_type() const { return type_u64; } |
| 69 | |
| 70 | private: |
| 71 | // Name |
| 72 | std::string name_; |
| 73 | |
| 74 | // Components |
| 75 | std::vector<t_typedef*> typedefs_; |
| 76 | std::vector<t_enum*> enums_; |
| 77 | std::vector<t_struct*> structs_; |
| 78 | std::vector<t_service*> services_; |
| 79 | |
| 80 | // Global base types |
| 81 | t_type* type_void; |
| 82 | t_type* type_string; |
| 83 | t_type* type_byte; |
| 84 | t_type* type_i32; |
| 85 | t_type* type_u32; |
| 86 | t_type* type_i64; |
| 87 | t_type* type_u64; |
| 88 | }; |
| 89 | |
| 90 | #endif |