blob: a4a2cc7eea30e81062d7f70fb15ec026d95156ac [file] [log] [blame]
Mark Sleee9ce01c2007-05-16 02:29:53 +00001// 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 Slee31985722006-05-24 21:45:31 +00007#ifndef T_FIELD_H
8#define T_FIELD_H
9
10#include <string>
11
Mark Slee748d83f2007-02-07 01:20:08 +000012// Forward declare for xsd_attrs
13class t_struct;
14
Mark Slee31985722006-05-24 21:45:31 +000015/**
Mark Sleef5377b32006-10-10 01:42:59 +000016 * Class to represent a field in a thrift structure. A field has a data type,
17 * a symbolic name, and a numeric identifier.
Mark Slee31985722006-05-24 21:45:31 +000018 *
19 * @author Mark Slee <mcslee@facebook.com>
20 */
21class t_field {
22 public:
Mark Sleeb15a68b2006-06-07 06:46:24 +000023 t_field(t_type* type, std::string name) :
Mark Sleef5377b32006-10-10 01:42:59 +000024 type_(type),
25 name_(name),
Mark Slee36bfa2e2007-01-19 20:09:51 +000026 key_(0),
Mark Slee7ff32452007-02-01 05:26:18 +000027 value_(NULL),
Mark Slee7df0e2a2007-02-06 21:03:18 +000028 xsd_optional_(false),
Mark Slee748d83f2007-02-07 01:20:08 +000029 xsd_nillable_(false),
30 xsd_attrs_(NULL) {}
Mark Sleeb15a68b2006-06-07 06:46:24 +000031
Mark Slee9cb7c612006-09-01 22:17:45 +000032 t_field(t_type* type, std::string name, int32_t key) :
Mark Sleef5377b32006-10-10 01:42:59 +000033 type_(type),
34 name_(name),
Mark Slee36bfa2e2007-01-19 20:09:51 +000035 key_(key),
David Reiss8320a922007-08-14 19:59:26 +000036 req_(OPT_IN_REQ_OUT),
Mark Slee7ff32452007-02-01 05:26:18 +000037 value_(NULL),
Mark Slee7df0e2a2007-02-06 21:03:18 +000038 xsd_optional_(false),
Mark Slee748d83f2007-02-07 01:20:08 +000039 xsd_nillable_(false),
40 xsd_attrs_(NULL) {}
Mark Slee31985722006-05-24 21:45:31 +000041
42 ~t_field() {}
43
Mark Sleef5377b32006-10-10 01:42:59 +000044 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 Slee31985722006-05-24 21:45:31 +000055
David Reiss8320a922007-08-14 19:59:26 +000056 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 Slee21135c32007-02-05 21:52:08 +000070 void set_value(t_const_value* value) {
71 value_ = value;
72 }
73
74 t_const_value* get_value() {
75 return value_;
76 }
77
Mark Slee36bfa2e2007-01-19 20:09:51 +000078 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 Slee7df0e2a2007-02-06 21:03:18 +000086 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 Slee748d83f2007-02-07 01:20:08 +000094 void set_xsd_attrs(t_struct* xsd_attrs) {
95 xsd_attrs_ = xsd_attrs;
Mark Slee7ff32452007-02-01 05:26:18 +000096 }
97
Mark Slee748d83f2007-02-07 01:20:08 +000098 t_struct* get_xsd_attrs() {
Mark Slee21135c32007-02-05 21:52:08 +000099 return xsd_attrs_;
Mark Slee7ff32452007-02-01 05:26:18 +0000100 }
101
ccheeverf53b5cf2007-02-05 20:33:11 +0000102 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 Slee31985722006-05-24 21:45:31 +0000115 private:
116 t_type* type_;
117 std::string name_;
Mark Slee9cb7c612006-09-01 22:17:45 +0000118 int32_t key_;
David Reiss8320a922007-08-14 19:59:26 +0000119 e_req req_;
Mark Slee7ff32452007-02-01 05:26:18 +0000120 t_const_value* value_;
ccheeverf53b5cf2007-02-05 20:33:11 +0000121
Mark Slee36bfa2e2007-01-19 20:09:51 +0000122 bool xsd_optional_;
Mark Slee7df0e2a2007-02-06 21:03:18 +0000123 bool xsd_nillable_;
Mark Slee748d83f2007-02-07 01:20:08 +0000124 t_struct* xsd_attrs_;
Mark Slee36bfa2e2007-01-19 20:09:51 +0000125
ccheeverf53b5cf2007-02-05 20:33:11 +0000126 std::string doc_;
127 bool has_doc_;
128
Mark Slee31985722006-05-24 21:45:31 +0000129};
130
131#endif