Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 1 | #ifndef T_STRUCT_H |
| 2 | #define T_STRUCT_H |
| 3 | |
| 4 | #include <vector> |
| 5 | #include <string> |
| 6 | |
| 7 | #include "t_type.h" |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 8 | #include "t_field.h" |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 9 | |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 10 | // Forward declare that puppy |
| 11 | class t_program; |
| 12 | |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 13 | /** |
| 14 | * A struct is a container for a set of member fields that has a name. Structs |
| 15 | * are also used to implement exception types. |
| 16 | * |
| 17 | * @author Mark Slee <mcslee@facebook.com> |
| 18 | */ |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 19 | class t_struct : public t_type { |
| 20 | public: |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 21 | t_struct(t_program* program) : |
| 22 | t_type(program), |
Mark Slee | 782abbb | 2007-01-19 00:17:02 +0000 | [diff] [blame] | 23 | is_xception_(false), |
| 24 | xsd_all_(false) {} |
Mark Slee | b15a68b | 2006-06-07 06:46:24 +0000 | [diff] [blame] | 25 | |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 26 | t_struct(t_program* program, const std::string& name) : |
| 27 | t_type(program, name), |
Mark Slee | 782abbb | 2007-01-19 00:17:02 +0000 | [diff] [blame] | 28 | is_xception_(false), |
| 29 | xsd_all_(false) {} |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 30 | |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 31 | void set_name(const std::string& name) { |
| 32 | name_ = name; |
| 33 | } |
| 34 | |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 35 | void set_xception(bool is_xception) { |
| 36 | is_xception_ = is_xception; |
| 37 | } |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 38 | |
Mark Slee | 782abbb | 2007-01-19 00:17:02 +0000 | [diff] [blame] | 39 | void set_xsd_all(bool xsd_all) { |
| 40 | xsd_all_ = xsd_all; |
| 41 | } |
| 42 | |
| 43 | bool get_xsd_all() const { |
| 44 | return xsd_all_; |
| 45 | } |
| 46 | |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 47 | void append(t_field* elem) { |
| 48 | members_.push_back(elem); |
| 49 | } |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 50 | |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 51 | const std::vector<t_field*>& get_members() { |
| 52 | return members_; |
| 53 | } |
| 54 | |
| 55 | bool is_struct() const { |
| 56 | return !is_xception_; |
| 57 | } |
| 58 | |
| 59 | bool is_xception() const { |
| 60 | return is_xception_; |
| 61 | } |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 62 | |
| 63 | private: |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 64 | std::vector<t_field*> members_; |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 65 | bool is_xception_; |
Mark Slee | 782abbb | 2007-01-19 00:17:02 +0000 | [diff] [blame] | 66 | |
| 67 | bool xsd_all_; |
| 68 | |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 69 | }; |
| 70 | |
| 71 | #endif |