blob: bebea2a5656d530fcf96338286b3413b3f84f819 [file] [log] [blame]
Mark Slee31985722006-05-24 21:45:31 +00001#ifndef T_STRUCT_H
2#define T_STRUCT_H
3
4#include <vector>
5#include <string>
6
7#include "t_type.h"
Mark Sleee8540632006-05-30 09:24:40 +00008#include "t_field.h"
Mark Slee31985722006-05-24 21:45:31 +00009
Mark Sleef0712dc2006-10-25 19:03:57 +000010// Forward declare that puppy
11class t_program;
12
Mark Sleef5377b32006-10-10 01:42:59 +000013/**
14 * A struct is a container for a set of member fields that has a name. Structs
15 * are also used to implement exception types.
16 *
17 * @author Mark Slee <mcslee@facebook.com>
18 */
Mark Slee31985722006-05-24 21:45:31 +000019class t_struct : public t_type {
20 public:
Mark Sleef0712dc2006-10-25 19:03:57 +000021 t_struct(t_program* program) :
22 t_type(program),
Mark Slee782abbb2007-01-19 00:17:02 +000023 is_xception_(false),
24 xsd_all_(false) {}
Mark Sleeb15a68b2006-06-07 06:46:24 +000025
Mark Sleef0712dc2006-10-25 19:03:57 +000026 t_struct(t_program* program, const std::string& name) :
27 t_type(program, name),
Mark Slee782abbb2007-01-19 00:17:02 +000028 is_xception_(false),
29 xsd_all_(false) {}
Mark Slee31985722006-05-24 21:45:31 +000030
Mark Slee9cb7c612006-09-01 22:17:45 +000031 void set_name(const std::string& name) {
32 name_ = name;
33 }
34
Mark Slee9cb7c612006-09-01 22:17:45 +000035 void set_xception(bool is_xception) {
36 is_xception_ = is_xception;
37 }
Mark Sleee8540632006-05-30 09:24:40 +000038
Mark Slee782abbb2007-01-19 00:17:02 +000039 void set_xsd_all(bool xsd_all) {
40 xsd_all_ = xsd_all;
41 }
42
43 bool get_xsd_all() const {
44 return xsd_all_;
45 }
46
Mark Slee9cb7c612006-09-01 22:17:45 +000047 void append(t_field* elem) {
48 members_.push_back(elem);
49 }
Mark Sleee8540632006-05-30 09:24:40 +000050
Mark Slee9cb7c612006-09-01 22:17:45 +000051 const std::vector<t_field*>& get_members() {
52 return members_;
53 }
54
55 bool is_struct() const {
56 return !is_xception_;
57 }
58
59 bool is_xception() const {
60 return is_xception_;
61 }
Mark Slee31985722006-05-24 21:45:31 +000062
63 private:
Mark Sleee8540632006-05-30 09:24:40 +000064 std::vector<t_field*> members_;
Mark Slee9cb7c612006-09-01 22:17:45 +000065 bool is_xception_;
Mark Slee782abbb2007-01-19 00:17:02 +000066
67 bool xsd_all_;
68
Mark Slee31985722006-05-24 21:45:31 +000069};
70
71#endif