blob: dfa5cacf50c93c9f8b6050b7750d11cc4550a1b8 [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
6/**
Mark Sleef5377b32006-10-10 01:42:59 +00007 * Class to represent a field in a thrift structure. A field has a data type,
8 * a symbolic name, and a numeric identifier.
Mark Slee31985722006-05-24 21:45:31 +00009 *
10 * @author Mark Slee <mcslee@facebook.com>
11 */
12class t_field {
13 public:
Mark Sleeb15a68b2006-06-07 06:46:24 +000014 t_field(t_type* type, std::string name) :
Mark Sleef5377b32006-10-10 01:42:59 +000015 type_(type),
16 name_(name),
Mark Slee36bfa2e2007-01-19 20:09:51 +000017 key_(0),
Mark Slee7ff32452007-02-01 05:26:18 +000018 value_(NULL),
Mark Slee7df0e2a2007-02-06 21:03:18 +000019 xsd_optional_(false),
20 xsd_nillable_(false) {}
Mark Sleeb15a68b2006-06-07 06:46:24 +000021
Mark Slee9cb7c612006-09-01 22:17:45 +000022 t_field(t_type* type, std::string name, int32_t key) :
Mark Sleef5377b32006-10-10 01:42:59 +000023 type_(type),
24 name_(name),
Mark Slee36bfa2e2007-01-19 20:09:51 +000025 key_(key),
Mark Slee7ff32452007-02-01 05:26:18 +000026 value_(NULL),
Mark Slee7df0e2a2007-02-06 21:03:18 +000027 xsd_optional_(false),
28 xsd_nillable_(false) {}
Mark Slee31985722006-05-24 21:45:31 +000029
30 ~t_field() {}
31
Mark Sleef5377b32006-10-10 01:42:59 +000032 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 Slee31985722006-05-24 21:45:31 +000043
Mark Slee21135c32007-02-05 21:52:08 +000044 void set_value(t_const_value* value) {
45 value_ = value;
46 }
47
48 t_const_value* get_value() {
49 return value_;
50 }
51
Mark Slee36bfa2e2007-01-19 20:09:51 +000052 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 Slee7df0e2a2007-02-06 21:03:18 +000060 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 Slee21135c32007-02-05 21:52:08 +000068 void add_xsd_attr(std::string attr) {
69 xsd_attrs_.push_back(attr);
Mark Slee7ff32452007-02-01 05:26:18 +000070 }
71
Mark Slee21135c32007-02-05 21:52:08 +000072 const std::vector<std::string>& get_xsd_attrs() {
73 return xsd_attrs_;
Mark Slee7ff32452007-02-01 05:26:18 +000074 }
75
ccheeverf53b5cf2007-02-05 20:33:11 +000076 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 Slee31985722006-05-24 21:45:31 +000089 private:
90 t_type* type_;
91 std::string name_;
Mark Slee9cb7c612006-09-01 22:17:45 +000092 int32_t key_;
Mark Slee7ff32452007-02-01 05:26:18 +000093 t_const_value* value_;
ccheeverf53b5cf2007-02-05 20:33:11 +000094
Mark Slee36bfa2e2007-01-19 20:09:51 +000095 bool xsd_optional_;
Mark Slee7df0e2a2007-02-06 21:03:18 +000096 bool xsd_nillable_;
Mark Slee21135c32007-02-05 21:52:08 +000097 std::vector<std::string> xsd_attrs_;
Mark Slee36bfa2e2007-01-19 20:09:51 +000098
ccheeverf53b5cf2007-02-05 20:33:11 +000099 std::string doc_;
100 bool has_doc_;
101
Mark Slee31985722006-05-24 21:45:31 +0000102};
103
104#endif