blob: 8768c5f9ed0c0e85dce12b085fa9eff5d66f2db1 [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 Sleef5377b32006-10-10 01:42:59 +000010/**
11 * A struct is a container for a set of member fields that has a name. Structs
12 * are also used to implement exception types.
13 *
14 * @author Mark Slee <mcslee@facebook.com>
15 */
Mark Slee31985722006-05-24 21:45:31 +000016class t_struct : public t_type {
17 public:
Mark Sleef5377b32006-10-10 01:42:59 +000018 t_struct() :
19 is_xception_(false) {}
Mark Sleeb15a68b2006-06-07 06:46:24 +000020
Mark Sleef5377b32006-10-10 01:42:59 +000021 t_struct(const std::string& name) :
22 t_type(name),
23 is_xception_(false) {}
Mark Slee31985722006-05-24 21:45:31 +000024
Mark Slee9cb7c612006-09-01 22:17:45 +000025 void set_name(const std::string& name) {
26 name_ = name;
27 }
28
Mark Slee9cb7c612006-09-01 22:17:45 +000029 void set_xception(bool is_xception) {
30 is_xception_ = is_xception;
31 }
Mark Sleee8540632006-05-30 09:24:40 +000032
Mark Slee9cb7c612006-09-01 22:17:45 +000033 void append(t_field* elem) {
34 members_.push_back(elem);
35 }
Mark Sleee8540632006-05-30 09:24:40 +000036
Mark Slee9cb7c612006-09-01 22:17:45 +000037 const std::vector<t_field*>& get_members() {
38 return members_;
39 }
40
41 bool is_struct() const {
42 return !is_xception_;
43 }
44
45 bool is_xception() const {
46 return is_xception_;
47 }
Mark Slee31985722006-05-24 21:45:31 +000048
49 private:
Mark Sleee8540632006-05-30 09:24:40 +000050 std::vector<t_field*> members_;
Mark Slee9cb7c612006-09-01 22:17:45 +000051 bool is_xception_;
Mark Slee31985722006-05-24 21:45:31 +000052};
53
54#endif