blob: 03d4ba7e367f7b42a92ff7b09dc3bda0287b1706 [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 Slee36bfa2e2007-01-19 20:09:51 +000019 xsd_optional_(false) {}
Mark Sleeb15a68b2006-06-07 06:46:24 +000020
Mark Slee9cb7c612006-09-01 22:17:45 +000021 t_field(t_type* type, std::string name, int32_t key) :
Mark Sleef5377b32006-10-10 01:42:59 +000022 type_(type),
23 name_(name),
Mark Slee36bfa2e2007-01-19 20:09:51 +000024 key_(key),
Mark Slee7ff32452007-02-01 05:26:18 +000025 value_(NULL),
Mark Slee36bfa2e2007-01-19 20:09:51 +000026 xsd_optional_(false) {}
Mark Slee31985722006-05-24 21:45:31 +000027
28 ~t_field() {}
29
Mark Sleef5377b32006-10-10 01:42:59 +000030 t_type* get_type() const {
31 return type_;
32 }
33
34 const std::string& get_name() const {
35 return name_;
36 }
37
38 int32_t get_key() const {
39 return key_;
40 }
Mark Slee31985722006-05-24 21:45:31 +000041
Mark Slee36bfa2e2007-01-19 20:09:51 +000042 void set_xsd_optional(bool xsd_optional) {
43 xsd_optional_ = xsd_optional;
44 }
45
46 bool get_xsd_optional() const {
47 return xsd_optional_;
48 }
49
Mark Slee7ff32452007-02-01 05:26:18 +000050 void set_value(t_const_value* value) {
51 value_ = value;
52 }
53
54 t_const_value* get_value() {
55 return value_;
56 }
57
ccheeverf53b5cf2007-02-05 20:33:11 +000058 const std::string& get_doc() const {
59 return doc_;
60 }
61
62 bool has_doc() {
63 return has_doc_;
64 }
65
66 void set_doc(const std::string& doc) {
67 doc_ = doc;
68 has_doc_ = true;
69 }
70
Mark Slee31985722006-05-24 21:45:31 +000071 private:
72 t_type* type_;
73 std::string name_;
Mark Slee9cb7c612006-09-01 22:17:45 +000074 int32_t key_;
Mark Slee7ff32452007-02-01 05:26:18 +000075 t_const_value* value_;
ccheeverf53b5cf2007-02-05 20:33:11 +000076
Mark Slee36bfa2e2007-01-19 20:09:51 +000077 bool xsd_optional_;
78
ccheeverf53b5cf2007-02-05 20:33:11 +000079 std::string doc_;
80 bool has_doc_;
81
Mark Slee31985722006-05-24 21:45:31 +000082};
83
84#endif