headers/bsd: Add sys/queue.h.
[haiku.git] / src / kits / debugger / value / ValueNode.cpp
blobd868a07c92e501b8cfad32ae161249d30aed8f5b
1 /*
2 * Copyright 2015, Rene Gollent, rene@gollent.com.
3 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
4 * Distributed under the terms of the MIT License.
5 */
8 #include "ValueNode.h"
10 #include "Value.h"
11 #include "ValueLocation.h"
12 #include "ValueNodeContainer.h"
15 // #pragma mark - ValueNode
18 ValueNode::ValueNode(ValueNodeChild* nodeChild)
20 fContainer(NULL),
21 fNodeChild(nodeChild),
22 fLocation(NULL),
23 fValue(NULL),
24 fLocationResolutionState(VALUE_NODE_UNRESOLVED),
25 fChildrenCreated(false)
27 fNodeChild->AcquireReference();
31 ValueNode::~ValueNode()
33 SetLocationAndValue(NULL, NULL, VALUE_NODE_UNRESOLVED);
34 SetContainer(NULL);
35 fNodeChild->ReleaseReference();
39 const BString&
40 ValueNode::Name() const
42 return fNodeChild->Name();
46 void
47 ValueNode::SetContainer(ValueNodeContainer* container)
49 if (container == fContainer)
50 return;
52 if (fContainer != NULL)
53 fContainer->ReleaseReference();
55 fContainer = container;
57 if (fContainer != NULL)
58 fContainer->AcquireReference();
60 // propagate to children
61 int32 childCount = CountChildren();
62 for (int32 i = 0; i < childCount; i++)
63 ChildAt(i)->SetContainer(fContainer);
67 bool
68 ValueNode::IsRangedContainer() const
70 return false;
74 bool
75 ValueNode::IsContainerRangeFixed() const
77 return false;
81 void
82 ValueNode::ClearChildren()
84 // do nothing
88 status_t
89 ValueNode::CreateChildrenInRange(TeamTypeInformation* info, int32 lowIndex,
90 int32 highIndex)
92 return B_NOT_SUPPORTED;
96 status_t
97 ValueNode::SupportedChildRange(int32& lowIndex, int32& highIndex) const
99 return B_NOT_SUPPORTED;
103 void
104 ValueNode::SetLocationAndValue(ValueLocation* location, Value* value,
105 status_t resolutionState)
107 if (fLocation != location) {
108 if (fLocation != NULL)
109 fLocation->ReleaseReference();
111 fLocation = location;
113 if (fLocation != NULL)
114 fLocation->AcquireReference();
117 if (fValue != value) {
118 if (fValue != NULL)
119 fValue->ReleaseReference();
121 fValue = value;
123 if (fValue != NULL)
124 fValue->AcquireReference();
127 fLocationResolutionState = resolutionState;
129 // notify listeners
130 if (fContainer != NULL)
131 fContainer->NotifyValueNodeValueChanged(this);
135 // #pragma mark - ValueNodeChild
138 ValueNodeChild::ValueNodeChild()
140 fContainer(NULL),
141 fNode(NULL),
142 fLocation(NULL),
143 fLocationResolutionState(VALUE_NODE_UNRESOLVED)
148 ValueNodeChild::~ValueNodeChild()
150 SetLocation(NULL, VALUE_NODE_UNRESOLVED);
151 SetNode(NULL);
152 SetContainer(NULL);
156 bool
157 ValueNodeChild::IsInternal() const
159 return false;
163 status_t
164 ValueNodeChild::CreateInternalNode(ValueNode*& _node)
166 return B_BAD_VALUE;
170 void
171 ValueNodeChild::SetContainer(ValueNodeContainer* container)
173 if (container == fContainer)
174 return;
176 if (fContainer != NULL)
177 fContainer->ReleaseReference();
179 fContainer = container;
181 if (fContainer != NULL)
182 fContainer->AcquireReference();
184 // propagate to node
185 if (fNode != NULL)
186 fNode->SetContainer(fContainer);
190 void
191 ValueNodeChild::SetNode(ValueNode* node)
193 if (node == fNode)
194 return;
196 ValueNode* oldNode = fNode;
197 BReference<ValueNode> oldNodeReference(oldNode, true);
199 if (fNode != NULL)
200 fNode->SetContainer(NULL);
202 fNode = node;
204 if (fNode != NULL) {
205 fNode->AcquireReference();
206 fNode->SetContainer(fContainer);
209 if (fContainer != NULL)
210 fContainer->NotifyValueNodeChanged(this, oldNode, fNode);
214 ValueLocation*
215 ValueNodeChild::Location() const
217 return fLocation;
221 void
222 ValueNodeChild::SetLocation(ValueLocation* location, status_t resolutionState)
224 if (fLocation != location) {
225 if (fLocation != NULL)
226 fLocation->ReleaseReference();
228 fLocation = location;
230 if (fLocation != NULL)
231 fLocation->AcquireReference();
234 fLocationResolutionState = resolutionState;
238 // #pragma mark - ChildlessValueNode
241 ChildlessValueNode::ChildlessValueNode(ValueNodeChild* nodeChild)
243 ValueNode(nodeChild)
245 fChildrenCreated = true;
249 status_t
250 ChildlessValueNode::CreateChildren(TeamTypeInformation* info)
252 return B_OK;
255 int32
256 ChildlessValueNode::CountChildren() const
258 return 0;
262 ValueNodeChild*
263 ChildlessValueNode::ChildAt(int32 index) const
265 return NULL;