-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathStruct.h
71 lines (51 loc) · 1.72 KB
/
Struct.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#ifndef __STRUCT_H__
#define __STRUCT_H__
#include <string>
#include <vector>
#include <map>
#include "RefCountObject.h"
#include "Type.h"
struct StructMember
{
Ref<Type> type;
std::string name;
size_t offset;
};
class ParserState;
class Struct: public RefCountObject
{
std::string m_name;
std::vector<StructMember> m_members;
std::map<std::string, StructMember> m_membersByName;
size_t m_width, m_alignment;
bool m_union;
bool m_fullyDefined;
bool m_packed;
size_t m_serializationIndex;
bool m_serializationIndexValid;
static size_t m_nextSerializationIndex;
static std::map< size_t, Ref<Struct> > m_serializationMap;
public:
Struct();
Struct(bool isUnion, bool packed = false);
Struct* Duplicate(DuplicateContext& dup);
void ReplaceWith(Struct* s);
bool IsFullyDefined() const { return m_fullyDefined; }
void Complete();
void SetName(const std::string& name) { m_name = name; }
const std::string& GetName() const { return m_name; }
const std::vector<StructMember>& GetMembers() const { return m_members; }
bool HasMember(const std::string& name) const { return m_membersByName.find(name) != m_membersByName.end(); }
StructMember GetMember(ParserState* state, const std::string& name) const;
const StructMember* GetMember(const std::string& name) const;
void SetPacked(bool packed) { m_packed = packed; }
bool IsPacked() const { return m_packed; }
size_t GetWidth() const { return m_width; }
size_t GetAlignment() const { return m_alignment; }
bool IsUnion() const { return m_union; }
void AddMember(ParserState* state, Type* type, const std::string& name);
void CopyMembers(ParserState* state, Struct* s);
void Serialize(OutputBlock* output);
static Struct* Deserialize(InputBlock* input);
};
#endif