blob: 35414efe897a33aa748892332cd24526ae92d369 [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),
18 xsd_optional_(false) {}
Mark Sleeb15a68b2006-06-07 06:46:24 +000019
Mark Slee9cb7c612006-09-01 22:17:45 +000020 t_field(t_type* type, std::string name, int32_t key) :
Mark Sleef5377b32006-10-10 01:42:59 +000021 type_(type),
22 name_(name),
Mark Slee36bfa2e2007-01-19 20:09:51 +000023 key_(key),
24 xsd_optional_(false) {}
Mark Slee31985722006-05-24 21:45:31 +000025
26 ~t_field() {}
27
Mark Sleef5377b32006-10-10 01:42:59 +000028 t_type* get_type() const {
29 return type_;
30 }
31
32 const std::string& get_name() const {
33 return name_;
34 }
35
36 int32_t get_key() const {
37 return key_;
38 }
Mark Slee31985722006-05-24 21:45:31 +000039
Mark Slee36bfa2e2007-01-19 20:09:51 +000040 void set_xsd_optional(bool xsd_optional) {
41 xsd_optional_ = xsd_optional;
42 }
43
44 bool get_xsd_optional() const {
45 return xsd_optional_;
46 }
47
Mark Slee31985722006-05-24 21:45:31 +000048 private:
49 t_type* type_;
50 std::string name_;
Mark Slee9cb7c612006-09-01 22:17:45 +000051 int32_t key_;
Mark Slee36bfa2e2007-01-19 20:09:51 +000052
53 bool xsd_optional_;
54
Mark Slee31985722006-05-24 21:45:31 +000055};
56
57#endif