xref: /haiku/headers/private/debugger/value/value_nodes/BMessageValueNode.h (revision ed24eb5ff12640d052171c6a7feba37fab8a75d1)
1 /*
2  * Copyright 2011-2015, Rene Gollent, rene@gollent.com.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef BMESSAGE_VALUE_NODE_H
6 #define BMESSAGE_VALUE_NODE_H
7 
8 #include <Message.h>
9 #include <MessagePrivate.h>
10 #include <ObjectList.h>
11 #include <Variant.h>
12 
13 #include "ValueLocation.h"
14 #include "ValueNode.h"
15 
16 
17 class CompoundType;
18 
19 
20 class BMessageValueNode : public ValueNode {
21 public:
22 									BMessageValueNode(
23 										ValueNodeChild* nodeChild, Type* type);
24 	virtual							~BMessageValueNode();
25 
26 	virtual	Type*					GetType() const;
27 	virtual	status_t				ResolvedLocationAndValue(
28 										ValueLoader* valueLoader,
29 										ValueLocation*& _location,
30 										Value*& _value);
31 
32 	virtual bool					ChildCreationNeedsValue() const
33 										{ return true; }
34 	virtual status_t				CreateChildren(TeamTypeInformation* info);
35 	virtual int32					CountChildren() const;
36 	virtual ValueNodeChild*			ChildAt(int32 index) const;
37 
38 private:
39 
40 			status_t				_GetTypeForTypeCode(
41 										TeamTypeInformation* info,
42 										type_code type,
43 										Type*& _type);
44 			status_t				_FindField(const char* name,
45 										type_code type,
46 										BMessage::field_header** result) const;
47 			uint32					_HashName(const char* name) const;
48 			status_t				_FindDataLocation(const char* name,
49 										type_code type, int32 index,
50 										ValueLocation& location) const;
51 
52 private:
53 			class BMessageFieldNode;
54 			class BMessageFieldNodeChild;
55 
56 			// for GCC2
57 			friend class BMessageFieldNode;
58 			friend class BMessageFieldNodeChild;
59 			friend class BMessageWhatNodeChild;
60 
61 			typedef BObjectList<ValueNodeChild> ChildNodeList;
62 
63 private:
64 			Type*					fType;
65 			ChildNodeList			fChildren;
66 			BVariant				fDataLocation;
67 			BMessage::message_header*
68 									fHeader;
69 			BMessage::field_header*	fFields;
70 			uint8*					fData;
71 			BMessage				fMessage;
72 			bool					fIsFlatMessage;
73 };
74 
75 
76 class BMessageValueNode::BMessageFieldNode : public ValueNode {
77 public:
78 									BMessageFieldNode(
79 										BMessageFieldNodeChild *child,
80 										BMessageValueNode* parent,
81 										const BString& name,
82 										type_code type, int32 count);
83 
84 	virtual 						~BMessageFieldNode();
85 
86 	virtual Type* 					GetType() const;
87 
88 	virtual status_t 				ResolvedLocationAndValue(
89 										ValueLoader* loader,
90 										ValueLocation *& _location,
91 										Value*& _value);
92 
93 	virtual	status_t 				CreateChildren(TeamTypeInformation* info);
94 	virtual	int32 					CountChildren() const;
95 	virtual	ValueNodeChild* 		ChildAt(int32 index) const;
96 
97 private:
98 			BString 				fName;
99 			Type*					fType;
100 			BMessageValueNode* 		fParent;
101 			type_code				fFieldType;
102 			int32					fFieldCount;
103 			ChildNodeList			fChildren;
104 };
105 
106 
107 class BMessageValueNode::BMessageFieldNodeChild : public ValueNodeChild {
108 public:
109 									BMessageFieldNodeChild(
110 										BMessageValueNode* parent,
111 										Type* nodeType,
112 										const BString &name,
113 										type_code type, int32 count,
114 										int32 index = -1);
115 
116 	virtual 						~BMessageFieldNodeChild();
117 
118 	virtual const BString& 			Name() const;
119 	virtual Type* 					GetType() const;
120 	virtual ValueNode* 				Parent() const;
121 
122 	virtual bool 					IsInternal() const;
123 	virtual status_t 				CreateInternalNode(
124 										ValueNode*& _node);
125 
126 	virtual	status_t 				ResolveLocation(ValueLoader* valueLoader,
127 										ValueLocation*& _location);
128 
129 private:
130 			BString 				fName;
131 			BString					fPresentationName;
132 			Type*					fType;
133 			BMessageValueNode* 		fParent;
134 			type_code				fFieldType;
135 			int32					fFieldCount;
136 			int32					fFieldIndex;
137 };
138 
139 #endif	// BMESSAGE_VALUE_NODE_H
140