Mark Slee | e9ce01c | 2007-05-16 02:29:53 +0000 | [diff] [blame] | 1 | // Copyright (c) 2006- Facebook |
| 2 | // Distributed under the Thrift Software License |
| 3 | // |
| 4 | // See accompanying file LICENSE or visit the Thrift site at: |
| 5 | // http://developers.facebook.com/thrift/ |
| 6 | |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 7 | #ifndef T_FIELD_H |
| 8 | #define T_FIELD_H |
| 9 | |
| 10 | #include <string> |
| 11 | |
Mark Slee | 748d83f | 2007-02-07 01:20:08 +0000 | [diff] [blame] | 12 | // Forward declare for xsd_attrs |
| 13 | class t_struct; |
| 14 | |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 15 | /** |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 16 | * Class to represent a field in a thrift structure. A field has a data type, |
| 17 | * a symbolic name, and a numeric identifier. |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 18 | * |
| 19 | * @author Mark Slee <mcslee@facebook.com> |
| 20 | */ |
| 21 | class t_field { |
| 22 | public: |
Mark Slee | b15a68b | 2006-06-07 06:46:24 +0000 | [diff] [blame] | 23 | t_field(t_type* type, std::string name) : |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 24 | type_(type), |
| 25 | name_(name), |
Mark Slee | 36bfa2e | 2007-01-19 20:09:51 +0000 | [diff] [blame] | 26 | key_(0), |
Mark Slee | 7ff3245 | 2007-02-01 05:26:18 +0000 | [diff] [blame] | 27 | value_(NULL), |
Mark Slee | 7df0e2a | 2007-02-06 21:03:18 +0000 | [diff] [blame] | 28 | xsd_optional_(false), |
Mark Slee | 748d83f | 2007-02-07 01:20:08 +0000 | [diff] [blame] | 29 | xsd_nillable_(false), |
| 30 | xsd_attrs_(NULL) {} |
Mark Slee | b15a68b | 2006-06-07 06:46:24 +0000 | [diff] [blame] | 31 | |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 32 | t_field(t_type* type, std::string name, int32_t key) : |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 33 | type_(type), |
| 34 | name_(name), |
Mark Slee | 36bfa2e | 2007-01-19 20:09:51 +0000 | [diff] [blame] | 35 | key_(key), |
David Reiss | 8320a92 | 2007-08-14 19:59:26 +0000 | [diff] [blame^] | 36 | req_(OPT_IN_REQ_OUT), |
Mark Slee | 7ff3245 | 2007-02-01 05:26:18 +0000 | [diff] [blame] | 37 | value_(NULL), |
Mark Slee | 7df0e2a | 2007-02-06 21:03:18 +0000 | [diff] [blame] | 38 | xsd_optional_(false), |
Mark Slee | 748d83f | 2007-02-07 01:20:08 +0000 | [diff] [blame] | 39 | xsd_nillable_(false), |
| 40 | xsd_attrs_(NULL) {} |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 41 | |
| 42 | ~t_field() {} |
| 43 | |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 44 | t_type* get_type() const { |
| 45 | return type_; |
| 46 | } |
| 47 | |
| 48 | const std::string& get_name() const { |
| 49 | return name_; |
| 50 | } |
| 51 | |
| 52 | int32_t get_key() const { |
| 53 | return key_; |
| 54 | } |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 55 | |
David Reiss | 8320a92 | 2007-08-14 19:59:26 +0000 | [diff] [blame^] | 56 | enum e_req { |
| 57 | REQUIRED, |
| 58 | OPTIONAL, |
| 59 | OPT_IN_REQ_OUT |
| 60 | }; |
| 61 | |
| 62 | void set_req(e_req req) { |
| 63 | req_ = req; |
| 64 | } |
| 65 | |
| 66 | e_req get_req() const { |
| 67 | return req_; |
| 68 | } |
| 69 | |
Mark Slee | 21135c3 | 2007-02-05 21:52:08 +0000 | [diff] [blame] | 70 | void set_value(t_const_value* value) { |
| 71 | value_ = value; |
| 72 | } |
| 73 | |
| 74 | t_const_value* get_value() { |
| 75 | return value_; |
| 76 | } |
| 77 | |
Mark Slee | 36bfa2e | 2007-01-19 20:09:51 +0000 | [diff] [blame] | 78 | void set_xsd_optional(bool xsd_optional) { |
| 79 | xsd_optional_ = xsd_optional; |
| 80 | } |
| 81 | |
| 82 | bool get_xsd_optional() const { |
| 83 | return xsd_optional_; |
| 84 | } |
| 85 | |
Mark Slee | 7df0e2a | 2007-02-06 21:03:18 +0000 | [diff] [blame] | 86 | void set_xsd_nillable(bool xsd_nillable) { |
| 87 | xsd_nillable_ = xsd_nillable; |
| 88 | } |
| 89 | |
| 90 | bool get_xsd_nillable() const { |
| 91 | return xsd_nillable_; |
| 92 | } |
| 93 | |
Mark Slee | 748d83f | 2007-02-07 01:20:08 +0000 | [diff] [blame] | 94 | void set_xsd_attrs(t_struct* xsd_attrs) { |
| 95 | xsd_attrs_ = xsd_attrs; |
Mark Slee | 7ff3245 | 2007-02-01 05:26:18 +0000 | [diff] [blame] | 96 | } |
| 97 | |
Mark Slee | 748d83f | 2007-02-07 01:20:08 +0000 | [diff] [blame] | 98 | t_struct* get_xsd_attrs() { |
Mark Slee | 21135c3 | 2007-02-05 21:52:08 +0000 | [diff] [blame] | 99 | return xsd_attrs_; |
Mark Slee | 7ff3245 | 2007-02-01 05:26:18 +0000 | [diff] [blame] | 100 | } |
| 101 | |
ccheever | f53b5cf | 2007-02-05 20:33:11 +0000 | [diff] [blame] | 102 | const std::string& get_doc() const { |
| 103 | return doc_; |
| 104 | } |
| 105 | |
| 106 | bool has_doc() { |
| 107 | return has_doc_; |
| 108 | } |
| 109 | |
| 110 | void set_doc(const std::string& doc) { |
| 111 | doc_ = doc; |
| 112 | has_doc_ = true; |
| 113 | } |
| 114 | |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 115 | private: |
| 116 | t_type* type_; |
| 117 | std::string name_; |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 118 | int32_t key_; |
David Reiss | 8320a92 | 2007-08-14 19:59:26 +0000 | [diff] [blame^] | 119 | e_req req_; |
Mark Slee | 7ff3245 | 2007-02-01 05:26:18 +0000 | [diff] [blame] | 120 | t_const_value* value_; |
ccheever | f53b5cf | 2007-02-05 20:33:11 +0000 | [diff] [blame] | 121 | |
Mark Slee | 36bfa2e | 2007-01-19 20:09:51 +0000 | [diff] [blame] | 122 | bool xsd_optional_; |
Mark Slee | 7df0e2a | 2007-02-06 21:03:18 +0000 | [diff] [blame] | 123 | bool xsd_nillable_; |
Mark Slee | 748d83f | 2007-02-07 01:20:08 +0000 | [diff] [blame] | 124 | t_struct* xsd_attrs_; |
Mark Slee | 36bfa2e | 2007-01-19 20:09:51 +0000 | [diff] [blame] | 125 | |
ccheever | f53b5cf | 2007-02-05 20:33:11 +0000 | [diff] [blame] | 126 | std::string doc_; |
| 127 | bool has_doc_; |
| 128 | |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 129 | }; |
| 130 | |
| 131 | #endif |