blob: d342bff450916ee4e9c24f4f2c2f99ed40a3273b [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),
Mark Slee7ff32452007-02-01 05:26:18 +000036 value_(NULL),
Mark Slee7df0e2a2007-02-06 21:03:18 +000037 xsd_optional_(false),
Mark Slee748d83f2007-02-07 01:20:08 +000038 xsd_nillable_(false),
39 xsd_attrs_(NULL) {}
Mark Slee31985722006-05-24 21:45:31 +000040
41 ~t_field() {}
42
Mark Sleef5377b32006-10-10 01:42:59 +000043 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 Slee31985722006-05-24 21:45:31 +000054
Mark Slee21135c32007-02-05 21:52:08 +000055 void set_value(t_const_value* value) {
56 value_ = value;
57 }
58
59 t_const_value* get_value() {
60 return value_;
61 }
62
Mark Slee36bfa2e2007-01-19 20:09:51 +000063 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 Slee7df0e2a2007-02-06 21:03:18 +000071 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 Slee748d83f2007-02-07 01:20:08 +000079 void set_xsd_attrs(t_struct* xsd_attrs) {
80 xsd_attrs_ = xsd_attrs;
Mark Slee7ff32452007-02-01 05:26:18 +000081 }
82
Mark Slee748d83f2007-02-07 01:20:08 +000083 t_struct* get_xsd_attrs() {
Mark Slee21135c32007-02-05 21:52:08 +000084 return xsd_attrs_;
Mark Slee7ff32452007-02-01 05:26:18 +000085 }
86
ccheeverf53b5cf2007-02-05 20:33:11 +000087 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 Slee31985722006-05-24 21:45:31 +0000100 private:
101 t_type* type_;
102 std::string name_;
Mark Slee9cb7c612006-09-01 22:17:45 +0000103 int32_t key_;
Mark Slee7ff32452007-02-01 05:26:18 +0000104 t_const_value* value_;
ccheeverf53b5cf2007-02-05 20:33:11 +0000105
Mark Slee36bfa2e2007-01-19 20:09:51 +0000106 bool xsd_optional_;
Mark Slee7df0e2a2007-02-06 21:03:18 +0000107 bool xsd_nillable_;
Mark Slee748d83f2007-02-07 01:20:08 +0000108 t_struct* xsd_attrs_;
Mark Slee36bfa2e2007-01-19 20:09:51 +0000109
ccheeverf53b5cf2007-02-05 20:33:11 +0000110 std::string doc_;
111 bool has_doc_;
112
Mark Slee31985722006-05-24 21:45:31 +0000113};
114
115#endif