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 | |
Mark Slee | 748d83f | 2007-02-07 01:20:08 +0000 | [diff] [blame] | 6 | // Forward declare for xsd_attrs |
| 7 | class t_struct; |
| 8 | |
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 | * Class to represent a field in a thrift structure. A field has a data type, |
| 11 | * a symbolic name, and a numeric identifier. |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 12 | * |
| 13 | * @author Mark Slee <mcslee@facebook.com> |
| 14 | */ |
| 15 | class t_field { |
| 16 | public: |
Mark Slee | b15a68b | 2006-06-07 06:46:24 +0000 | [diff] [blame] | 17 | t_field(t_type* type, std::string name) : |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 18 | type_(type), |
| 19 | name_(name), |
Mark Slee | 36bfa2e | 2007-01-19 20:09:51 +0000 | [diff] [blame] | 20 | key_(0), |
Mark Slee | 7ff3245 | 2007-02-01 05:26:18 +0000 | [diff] [blame] | 21 | value_(NULL), |
Mark Slee | 7df0e2a | 2007-02-06 21:03:18 +0000 | [diff] [blame] | 22 | xsd_optional_(false), |
Mark Slee | 748d83f | 2007-02-07 01:20:08 +0000 | [diff] [blame] | 23 | xsd_nillable_(false), |
| 24 | xsd_attrs_(NULL) {} |
Mark Slee | b15a68b | 2006-06-07 06:46:24 +0000 | [diff] [blame] | 25 | |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 26 | t_field(t_type* type, std::string name, int32_t key) : |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 27 | type_(type), |
| 28 | name_(name), |
Mark Slee | 36bfa2e | 2007-01-19 20:09:51 +0000 | [diff] [blame] | 29 | key_(key), |
Mark Slee | 7ff3245 | 2007-02-01 05:26:18 +0000 | [diff] [blame] | 30 | value_(NULL), |
Mark Slee | 7df0e2a | 2007-02-06 21:03:18 +0000 | [diff] [blame] | 31 | xsd_optional_(false), |
Mark Slee | 748d83f | 2007-02-07 01:20:08 +0000 | [diff] [blame] | 32 | xsd_nillable_(false), |
| 33 | xsd_attrs_(NULL) {} |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 34 | |
| 35 | ~t_field() {} |
| 36 | |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 37 | t_type* get_type() const { |
| 38 | return type_; |
| 39 | } |
| 40 | |
| 41 | const std::string& get_name() const { |
| 42 | return name_; |
| 43 | } |
| 44 | |
| 45 | int32_t get_key() const { |
| 46 | return key_; |
| 47 | } |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 48 | |
Mark Slee | 21135c3 | 2007-02-05 21:52:08 +0000 | [diff] [blame] | 49 | void set_value(t_const_value* value) { |
| 50 | value_ = value; |
| 51 | } |
| 52 | |
| 53 | t_const_value* get_value() { |
| 54 | return value_; |
| 55 | } |
| 56 | |
Mark Slee | 36bfa2e | 2007-01-19 20:09:51 +0000 | [diff] [blame] | 57 | void set_xsd_optional(bool xsd_optional) { |
| 58 | xsd_optional_ = xsd_optional; |
| 59 | } |
| 60 | |
| 61 | bool get_xsd_optional() const { |
| 62 | return xsd_optional_; |
| 63 | } |
| 64 | |
Mark Slee | 7df0e2a | 2007-02-06 21:03:18 +0000 | [diff] [blame] | 65 | void set_xsd_nillable(bool xsd_nillable) { |
| 66 | xsd_nillable_ = xsd_nillable; |
| 67 | } |
| 68 | |
| 69 | bool get_xsd_nillable() const { |
| 70 | return xsd_nillable_; |
| 71 | } |
| 72 | |
Mark Slee | 748d83f | 2007-02-07 01:20:08 +0000 | [diff] [blame] | 73 | void set_xsd_attrs(t_struct* xsd_attrs) { |
| 74 | xsd_attrs_ = xsd_attrs; |
Mark Slee | 7ff3245 | 2007-02-01 05:26:18 +0000 | [diff] [blame] | 75 | } |
| 76 | |
Mark Slee | 748d83f | 2007-02-07 01:20:08 +0000 | [diff] [blame] | 77 | t_struct* get_xsd_attrs() { |
Mark Slee | 21135c3 | 2007-02-05 21:52:08 +0000 | [diff] [blame] | 78 | return xsd_attrs_; |
Mark Slee | 7ff3245 | 2007-02-01 05:26:18 +0000 | [diff] [blame] | 79 | } |
| 80 | |
ccheever | f53b5cf | 2007-02-05 20:33:11 +0000 | [diff] [blame] | 81 | const std::string& get_doc() const { |
| 82 | return doc_; |
| 83 | } |
| 84 | |
| 85 | bool has_doc() { |
| 86 | return has_doc_; |
| 87 | } |
| 88 | |
| 89 | void set_doc(const std::string& doc) { |
| 90 | doc_ = doc; |
| 91 | has_doc_ = true; |
| 92 | } |
| 93 | |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 94 | private: |
| 95 | t_type* type_; |
| 96 | std::string name_; |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 97 | int32_t key_; |
Mark Slee | 7ff3245 | 2007-02-01 05:26:18 +0000 | [diff] [blame] | 98 | t_const_value* value_; |
ccheever | f53b5cf | 2007-02-05 20:33:11 +0000 | [diff] [blame] | 99 | |
Mark Slee | 36bfa2e | 2007-01-19 20:09:51 +0000 | [diff] [blame] | 100 | bool xsd_optional_; |
Mark Slee | 7df0e2a | 2007-02-06 21:03:18 +0000 | [diff] [blame] | 101 | bool xsd_nillable_; |
Mark Slee | 748d83f | 2007-02-07 01:20:08 +0000 | [diff] [blame] | 102 | t_struct* xsd_attrs_; |
Mark Slee | 36bfa2e | 2007-01-19 20:09:51 +0000 | [diff] [blame] | 103 | |
ccheever | f53b5cf | 2007-02-05 20:33:11 +0000 | [diff] [blame] | 104 | std::string doc_; |
| 105 | bool has_doc_; |
| 106 | |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 107 | }; |
| 108 | |
| 109 | #endif |