blob: 65a75d34eb70d78521fe92c32717848f9c33c648 [file] [log] [blame]
Mark Slee31985722006-05-24 21:45:31 +00001#ifndef T_FIELD_H
2#define T_FIELD_H
3
4#include <string>
5
Mark Slee748d83f2007-02-07 01:20:08 +00006// Forward declare for xsd_attrs
7class t_struct;
8
Mark Slee31985722006-05-24 21:45:31 +00009/**
Mark Sleef5377b32006-10-10 01:42:59 +000010 * Class to represent a field in a thrift structure. A field has a data type,
11 * a symbolic name, and a numeric identifier.
Mark Slee31985722006-05-24 21:45:31 +000012 *
13 * @author Mark Slee <mcslee@facebook.com>
14 */
15class t_field {
16 public:
Mark Sleeb15a68b2006-06-07 06:46:24 +000017 t_field(t_type* type, std::string name) :
Mark Sleef5377b32006-10-10 01:42:59 +000018 type_(type),
19 name_(name),
Mark Slee36bfa2e2007-01-19 20:09:51 +000020 key_(0),
Mark Slee7ff32452007-02-01 05:26:18 +000021 value_(NULL),
Mark Slee7df0e2a2007-02-06 21:03:18 +000022 xsd_optional_(false),
Mark Slee748d83f2007-02-07 01:20:08 +000023 xsd_nillable_(false),
24 xsd_attrs_(NULL) {}
Mark Sleeb15a68b2006-06-07 06:46:24 +000025
Mark Slee9cb7c612006-09-01 22:17:45 +000026 t_field(t_type* type, std::string name, int32_t key) :
Mark Sleef5377b32006-10-10 01:42:59 +000027 type_(type),
28 name_(name),
Mark Slee36bfa2e2007-01-19 20:09:51 +000029 key_(key),
Mark Slee7ff32452007-02-01 05:26:18 +000030 value_(NULL),
Mark Slee7df0e2a2007-02-06 21:03:18 +000031 xsd_optional_(false),
Mark Slee748d83f2007-02-07 01:20:08 +000032 xsd_nillable_(false),
33 xsd_attrs_(NULL) {}
Mark Slee31985722006-05-24 21:45:31 +000034
35 ~t_field() {}
36
Mark Sleef5377b32006-10-10 01:42:59 +000037 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 Slee31985722006-05-24 21:45:31 +000048
Mark Slee21135c32007-02-05 21:52:08 +000049 void set_value(t_const_value* value) {
50 value_ = value;
51 }
52
53 t_const_value* get_value() {
54 return value_;
55 }
56
Mark Slee36bfa2e2007-01-19 20:09:51 +000057 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 Slee7df0e2a2007-02-06 21:03:18 +000065 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 Slee748d83f2007-02-07 01:20:08 +000073 void set_xsd_attrs(t_struct* xsd_attrs) {
74 xsd_attrs_ = xsd_attrs;
Mark Slee7ff32452007-02-01 05:26:18 +000075 }
76
Mark Slee748d83f2007-02-07 01:20:08 +000077 t_struct* get_xsd_attrs() {
Mark Slee21135c32007-02-05 21:52:08 +000078 return xsd_attrs_;
Mark Slee7ff32452007-02-01 05:26:18 +000079 }
80
ccheeverf53b5cf2007-02-05 20:33:11 +000081 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 Slee31985722006-05-24 21:45:31 +000094 private:
95 t_type* type_;
96 std::string name_;
Mark Slee9cb7c612006-09-01 22:17:45 +000097 int32_t key_;
Mark Slee7ff32452007-02-01 05:26:18 +000098 t_const_value* value_;
ccheeverf53b5cf2007-02-05 20:33:11 +000099
Mark Slee36bfa2e2007-01-19 20:09:51 +0000100 bool xsd_optional_;
Mark Slee7df0e2a2007-02-06 21:03:18 +0000101 bool xsd_nillable_;
Mark Slee748d83f2007-02-07 01:20:08 +0000102 t_struct* xsd_attrs_;
Mark Slee36bfa2e2007-01-19 20:09:51 +0000103
ccheeverf53b5cf2007-02-05 20:33:11 +0000104 std::string doc_;
105 bool has_doc_;
106
Mark Slee31985722006-05-24 21:45:31 +0000107};
108
109#endif