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 | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 10 | /** |
11 | * A struct is a container for a set of member fields that has a name. Structs | ||||
12 | * are also used to implement exception types. | ||||
13 | * | ||||
14 | * @author Mark Slee <mcslee@facebook.com> | ||||
15 | */ | ||||
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 16 | class t_struct : public t_type { |
17 | public: | ||||
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 18 | t_struct() : |
19 | is_xception_(false) {} | ||||
Mark Slee | b15a68b | 2006-06-07 06:46:24 +0000 | [diff] [blame] | 20 | |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 21 | t_struct(const std::string& name) : |
22 | t_type(name), | ||||
23 | is_xception_(false) {} | ||||
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 24 | |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 25 | void set_name(const std::string& name) { |
26 | name_ = name; | ||||
27 | } | ||||
28 | |||||
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 29 | void set_xception(bool is_xception) { |
30 | is_xception_ = is_xception; | ||||
31 | } | ||||
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 32 | |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 33 | void append(t_field* elem) { |
34 | members_.push_back(elem); | ||||
35 | } | ||||
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 36 | |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 37 | const std::vector<t_field*>& get_members() { |
38 | return members_; | ||||
39 | } | ||||
40 | |||||
41 | bool is_struct() const { | ||||
42 | return !is_xception_; | ||||
43 | } | ||||
44 | |||||
45 | bool is_xception() const { | ||||
46 | return is_xception_; | ||||
47 | } | ||||
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 48 | |
49 | private: | ||||
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 50 | std::vector<t_field*> members_; |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 51 | bool is_xception_; |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 52 | }; |
53 | |||||
54 | #endif |