blob: ce5f7524f79737d3d0587d05b24224af77827d47 [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 Sleef5377b32006-10-10 01:42:59 +000023 is_xception_(false) {}
Mark Sleeb15a68b2006-06-07 06:46:24 +000024
Mark Sleef0712dc2006-10-25 19:03:57 +000025 t_struct(t_program* program, const std::string& name) :
26 t_type(program, name),
Mark Sleef5377b32006-10-10 01:42:59 +000027 is_xception_(false) {}
Mark Slee31985722006-05-24 21:45:31 +000028
Mark Slee9cb7c612006-09-01 22:17:45 +000029 void set_name(const std::string& name) {
30 name_ = name;
31 }
32
Mark Slee9cb7c612006-09-01 22:17:45 +000033 void set_xception(bool is_xception) {
34 is_xception_ = is_xception;
35 }
Mark Sleee8540632006-05-30 09:24:40 +000036
Mark Slee9cb7c612006-09-01 22:17:45 +000037 void append(t_field* elem) {
38 members_.push_back(elem);
39 }
Mark Sleee8540632006-05-30 09:24:40 +000040
Mark Slee9cb7c612006-09-01 22:17:45 +000041 const std::vector<t_field*>& get_members() {
42 return members_;
43 }
44
45 bool is_struct() const {
46 return !is_xception_;
47 }
48
49 bool is_xception() const {
50 return is_xception_;
51 }
Mark Slee31985722006-05-24 21:45:31 +000052
53 private:
Mark Sleee8540632006-05-30 09:24:40 +000054 std::vector<t_field*> members_;
Mark Slee9cb7c612006-09-01 22:17:45 +000055 bool is_xception_;
Mark Slee31985722006-05-24 21:45:31 +000056};
57
58#endif