vfs: check userland buffers before reading them.
[haiku.git] / src / kits / debugger / value / ValueNodeContainer.cpp
blob774aacf706bdd996b90c78ee2e6197da65ac364c
1 /*
2 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
4 */
7 #include "ValueNodeContainer.h"
9 #include <AutoLocker.h>
11 #include "ValueNode.h"
14 // #pragma mark - ValueNodeContainer
17 ValueNodeContainer::ValueNodeContainer()
19 fLock("value node container")
24 ValueNodeContainer::~ValueNodeContainer()
26 RemoveAllChildren();
30 status_t
31 ValueNodeContainer::Init()
33 return fLock.InitCheck();
37 int32
38 ValueNodeContainer::CountChildren() const
40 return fChildren.CountItems();
44 ValueNodeChild*
45 ValueNodeContainer::ChildAt(int32 index) const
47 return fChildren.ItemAt(index);
51 bool
52 ValueNodeContainer::AddChild(ValueNodeChild* child)
54 AutoLocker<ValueNodeContainer> locker(this);
56 if (!fChildren.AddItem(child))
57 return false;
59 child->AcquireReference();
60 child->SetContainer(this);
62 return true;
66 void
67 ValueNodeContainer::RemoveChild(ValueNodeChild* child)
69 if (child->Container() != this || !fChildren.RemoveItem(child))
70 return;
72 child->SetContainer(NULL);
73 child->ReleaseReference();
77 void
78 ValueNodeContainer::RemoveAllChildren()
80 for (int32 i = 0; ValueNodeChild* child = ChildAt(i); i++) {
81 child->SetContainer(NULL);
82 child->ReleaseReference();
85 fChildren.MakeEmpty();
89 bool
90 ValueNodeContainer::AddListener(Listener* listener)
92 return fListeners.AddItem(listener);
96 void
97 ValueNodeContainer::RemoveListener(Listener* listener)
99 fListeners.RemoveItem(listener);
103 void
104 ValueNodeContainer::NotifyValueNodeChanged(ValueNodeChild* nodeChild,
105 ValueNode* oldNode, ValueNode* newNode)
107 for (int32 i = fListeners.CountItems() - 1; i >= 0; i--)
108 fListeners.ItemAt(i)->ValueNodeChanged(nodeChild, oldNode, newNode);
112 void
113 ValueNodeContainer::NotifyValueNodeChildrenCreated(ValueNode* node)
115 for (int32 i = fListeners.CountItems() - 1; i >= 0; i--)
116 fListeners.ItemAt(i)->ValueNodeChildrenCreated(node);
120 void
121 ValueNodeContainer::NotifyValueNodeChildrenDeleted(ValueNode* node)
123 for (int32 i = fListeners.CountItems() - 1; i >= 0; i--)
124 fListeners.ItemAt(i)->ValueNodeChildrenDeleted(node);
128 void
129 ValueNodeContainer::NotifyValueNodeValueChanged(ValueNode* node)
131 for (int32 i = fListeners.CountItems() - 1; i >= 0; i--)
132 fListeners.ItemAt(i)->ValueNodeValueChanged(node);
136 // #pragma mark - ValueNodeContainer
139 ValueNodeContainer::Listener::~Listener()
144 void
145 ValueNodeContainer::Listener::ValueNodeChanged(ValueNodeChild* nodeChild,
146 ValueNode* oldNode, ValueNode* newNode)
151 void
152 ValueNodeContainer::Listener::ValueNodeChildrenCreated(ValueNode* node)
157 void
158 ValueNodeContainer::Listener::ValueNodeChildrenDeleted(ValueNode* node)
163 void
164 ValueNodeContainer::Listener::ValueNodeValueChanged(ValueNode* node)