Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 1 | #ifndef T_FIELD_H |
| 2 | #define T_FIELD_H |
| 3 | |
| 4 | #include <string> |
| 5 | |
| 6 | /** |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 7 | * Class to represent a field in a thrift structure. A field has a data type, |
| 8 | * a symbolic name, and a numeric identifier. |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 9 | * |
| 10 | * @author Mark Slee <mcslee@facebook.com> |
| 11 | */ |
| 12 | class t_field { |
| 13 | public: |
Mark Slee | b15a68b | 2006-06-07 06:46:24 +0000 | [diff] [blame] | 14 | t_field(t_type* type, std::string name) : |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 15 | type_(type), |
| 16 | name_(name), |
Mark Slee | 36bfa2e | 2007-01-19 20:09:51 +0000 | [diff] [blame] | 17 | key_(0), |
Mark Slee | 7ff3245 | 2007-02-01 05:26:18 +0000 | [diff] [blame] | 18 | value_(NULL), |
Mark Slee | 36bfa2e | 2007-01-19 20:09:51 +0000 | [diff] [blame] | 19 | xsd_optional_(false) {} |
Mark Slee | b15a68b | 2006-06-07 06:46:24 +0000 | [diff] [blame] | 20 | |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 21 | t_field(t_type* type, std::string name, int32_t key) : |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 22 | type_(type), |
| 23 | name_(name), |
Mark Slee | 36bfa2e | 2007-01-19 20:09:51 +0000 | [diff] [blame] | 24 | key_(key), |
Mark Slee | 7ff3245 | 2007-02-01 05:26:18 +0000 | [diff] [blame] | 25 | value_(NULL), |
Mark Slee | 36bfa2e | 2007-01-19 20:09:51 +0000 | [diff] [blame] | 26 | xsd_optional_(false) {} |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 27 | |
| 28 | ~t_field() {} |
| 29 | |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 30 | t_type* get_type() const { |
| 31 | return type_; |
| 32 | } |
| 33 | |
| 34 | const std::string& get_name() const { |
| 35 | return name_; |
| 36 | } |
| 37 | |
| 38 | int32_t get_key() const { |
| 39 | return key_; |
| 40 | } |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 41 | |
Mark Slee | 36bfa2e | 2007-01-19 20:09:51 +0000 | [diff] [blame] | 42 | void set_xsd_optional(bool xsd_optional) { |
| 43 | xsd_optional_ = xsd_optional; |
| 44 | } |
| 45 | |
| 46 | bool get_xsd_optional() const { |
| 47 | return xsd_optional_; |
| 48 | } |
| 49 | |
Mark Slee | 7ff3245 | 2007-02-01 05:26:18 +0000 | [diff] [blame] | 50 | void set_value(t_const_value* value) { |
| 51 | value_ = value; |
| 52 | } |
| 53 | |
| 54 | t_const_value* get_value() { |
| 55 | return value_; |
| 56 | } |
| 57 | |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 58 | private: |
| 59 | t_type* type_; |
| 60 | std::string name_; |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 61 | int32_t key_; |
Mark Slee | 7ff3245 | 2007-02-01 05:26:18 +0000 | [diff] [blame] | 62 | t_const_value* value_; |
Mark Slee | 36bfa2e | 2007-01-19 20:09:51 +0000 | [diff] [blame] | 63 | |
| 64 | bool xsd_optional_; |
| 65 | |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 66 | }; |
| 67 | |
| 68 | #endif |