blob: 256e82c61444988fea33698df61b2045311291d8 [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_STRUCT_H
8#define T_STRUCT_H
9
10#include <vector>
11#include <string>
12
13#include "t_type.h"
Mark Sleee8540632006-05-30 09:24:40 +000014#include "t_field.h"
Mark Slee31985722006-05-24 21:45:31 +000015
Mark Sleef0712dc2006-10-25 19:03:57 +000016// Forward declare that puppy
17class t_program;
18
Mark Sleef5377b32006-10-10 01:42:59 +000019/**
20 * A struct is a container for a set of member fields that has a name. Structs
21 * are also used to implement exception types.
22 *
23 * @author Mark Slee <mcslee@facebook.com>
24 */
Mark Slee31985722006-05-24 21:45:31 +000025class t_struct : public t_type {
26 public:
Mark Sleef0712dc2006-10-25 19:03:57 +000027 t_struct(t_program* program) :
28 t_type(program),
Mark Slee782abbb2007-01-19 00:17:02 +000029 is_xception_(false),
30 xsd_all_(false) {}
Mark Sleeb15a68b2006-06-07 06:46:24 +000031
Mark Sleef0712dc2006-10-25 19:03:57 +000032 t_struct(t_program* program, const std::string& name) :
33 t_type(program, name),
Mark Slee782abbb2007-01-19 00:17:02 +000034 is_xception_(false),
35 xsd_all_(false) {}
Mark Slee31985722006-05-24 21:45:31 +000036
Mark Slee9cb7c612006-09-01 22:17:45 +000037 void set_name(const std::string& name) {
38 name_ = name;
39 }
40
Mark Slee9cb7c612006-09-01 22:17:45 +000041 void set_xception(bool is_xception) {
42 is_xception_ = is_xception;
43 }
Mark Sleee8540632006-05-30 09:24:40 +000044
Mark Slee782abbb2007-01-19 00:17:02 +000045 void set_xsd_all(bool xsd_all) {
46 xsd_all_ = xsd_all;
47 }
48
49 bool get_xsd_all() const {
50 return xsd_all_;
51 }
52
Mark Slee9cb7c612006-09-01 22:17:45 +000053 void append(t_field* elem) {
54 members_.push_back(elem);
55 }
Mark Sleee8540632006-05-30 09:24:40 +000056
Mark Slee9cb7c612006-09-01 22:17:45 +000057 const std::vector<t_field*>& get_members() {
58 return members_;
59 }
60
61 bool is_struct() const {
62 return !is_xception_;
63 }
64
65 bool is_xception() const {
66 return is_xception_;
67 }
Mark Slee31985722006-05-24 21:45:31 +000068
69 private:
Mark Sleee8540632006-05-30 09:24:40 +000070 std::vector<t_field*> members_;
Mark Slee9cb7c612006-09-01 22:17:45 +000071 bool is_xception_;
Mark Slee782abbb2007-01-19 00:17:02 +000072
73 bool xsd_all_;
74
Mark Slee31985722006-05-24 21:45:31 +000075};
76
77#endif