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