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 | 7df0e2a | 2007-02-06 21:03:18 +0000 | [diff] [blame] | 19 | xsd_optional_(false), |
| 20 | xsd_nillable_(false) {} |
Mark Slee | b15a68b | 2006-06-07 06:46:24 +0000 | [diff] [blame] | 21 | |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 22 | t_field(t_type* type, std::string name, int32_t key) : |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 23 | type_(type), |
| 24 | name_(name), |
Mark Slee | 36bfa2e | 2007-01-19 20:09:51 +0000 | [diff] [blame] | 25 | key_(key), |
Mark Slee | 7ff3245 | 2007-02-01 05:26:18 +0000 | [diff] [blame] | 26 | value_(NULL), |
Mark Slee | 7df0e2a | 2007-02-06 21:03:18 +0000 | [diff] [blame] | 27 | xsd_optional_(false), |
| 28 | xsd_nillable_(false) {} |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 29 | |
| 30 | ~t_field() {} |
| 31 | |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 32 | t_type* get_type() const { |
| 33 | return type_; |
| 34 | } |
| 35 | |
| 36 | const std::string& get_name() const { |
| 37 | return name_; |
| 38 | } |
| 39 | |
| 40 | int32_t get_key() const { |
| 41 | return key_; |
| 42 | } |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 43 | |
Mark Slee | 21135c3 | 2007-02-05 21:52:08 +0000 | [diff] [blame] | 44 | void set_value(t_const_value* value) { |
| 45 | value_ = value; |
| 46 | } |
| 47 | |
| 48 | t_const_value* get_value() { |
| 49 | return value_; |
| 50 | } |
| 51 | |
Mark Slee | 36bfa2e | 2007-01-19 20:09:51 +0000 | [diff] [blame] | 52 | void set_xsd_optional(bool xsd_optional) { |
| 53 | xsd_optional_ = xsd_optional; |
| 54 | } |
| 55 | |
| 56 | bool get_xsd_optional() const { |
| 57 | return xsd_optional_; |
| 58 | } |
| 59 | |
Mark Slee | 7df0e2a | 2007-02-06 21:03:18 +0000 | [diff] [blame] | 60 | void set_xsd_nillable(bool xsd_nillable) { |
| 61 | xsd_nillable_ = xsd_nillable; |
| 62 | } |
| 63 | |
| 64 | bool get_xsd_nillable() const { |
| 65 | return xsd_nillable_; |
| 66 | } |
| 67 | |
Mark Slee | 21135c3 | 2007-02-05 21:52:08 +0000 | [diff] [blame] | 68 | void add_xsd_attr(std::string attr) { |
| 69 | xsd_attrs_.push_back(attr); |
Mark Slee | 7ff3245 | 2007-02-01 05:26:18 +0000 | [diff] [blame] | 70 | } |
| 71 | |
Mark Slee | 21135c3 | 2007-02-05 21:52:08 +0000 | [diff] [blame] | 72 | const std::vector<std::string>& get_xsd_attrs() { |
| 73 | return xsd_attrs_; |
Mark Slee | 7ff3245 | 2007-02-01 05:26:18 +0000 | [diff] [blame] | 74 | } |
| 75 | |
ccheever | f53b5cf | 2007-02-05 20:33:11 +0000 | [diff] [blame] | 76 | const std::string& get_doc() const { |
| 77 | return doc_; |
| 78 | } |
| 79 | |
| 80 | bool has_doc() { |
| 81 | return has_doc_; |
| 82 | } |
| 83 | |
| 84 | void set_doc(const std::string& doc) { |
| 85 | doc_ = doc; |
| 86 | has_doc_ = true; |
| 87 | } |
| 88 | |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 89 | private: |
| 90 | t_type* type_; |
| 91 | std::string name_; |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 92 | int32_t key_; |
Mark Slee | 7ff3245 | 2007-02-01 05:26:18 +0000 | [diff] [blame] | 93 | t_const_value* value_; |
ccheever | f53b5cf | 2007-02-05 20:33:11 +0000 | [diff] [blame] | 94 | |
Mark Slee | 36bfa2e | 2007-01-19 20:09:51 +0000 | [diff] [blame] | 95 | bool xsd_optional_; |
Mark Slee | 7df0e2a | 2007-02-06 21:03:18 +0000 | [diff] [blame] | 96 | bool xsd_nillable_; |
Mark Slee | 21135c3 | 2007-02-05 21:52:08 +0000 | [diff] [blame] | 97 | std::vector<std::string> xsd_attrs_; |
Mark Slee | 36bfa2e | 2007-01-19 20:09:51 +0000 | [diff] [blame] | 98 | |
ccheever | f53b5cf | 2007-02-05 20:33:11 +0000 | [diff] [blame] | 99 | std::string doc_; |
| 100 | bool has_doc_; |
| 101 | |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 102 | }; |
| 103 | |
| 104 | #endif |