1/* 2 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. 3 * Distributed under the terms of the MIT License. 4 */ 5#ifndef VALUE_NODE_CONTAINER_H 6#define VALUE_NODE_CONTAINER_H 7 8 9#include <Locker.h> 10 11#include <ObjectList.h> 12#include <Referenceable.h> 13 14 15class ValueNode; 16class ValueNodeChild; 17 18 19class ValueNodeContainer : public BReferenceable { 20public: 21 class Listener; 22 23public: 24 ValueNodeContainer(); 25 virtual ~ValueNodeContainer(); 26 27 status_t Init(); 28 29 inline bool Lock() { return fLock.Lock(); } 30 inline void Unlock() { fLock.Unlock(); } 31 32 int32 CountChildren() const; 33 ValueNodeChild* ChildAt(int32 index) const; 34 bool AddChild(ValueNodeChild* child); 35 void RemoveChild(ValueNodeChild* child); 36 void RemoveAllChildren(); 37 38 bool AddListener(Listener* listener); 39 void RemoveListener(Listener* listener); 40 41 // container must be locked 42 43 void NotifyValueNodeChanged( 44 ValueNodeChild* nodeChild, 45 ValueNode* oldNode, ValueNode* newNode); 46 void NotifyValueNodeChildrenCreated(ValueNode* node); 47 void NotifyValueNodeChildrenDeleted(ValueNode* node); 48 void NotifyValueNodeValueChanged(ValueNode* node); 49 50private: 51 typedef BObjectList<ValueNodeChild> NodeChildList; 52 typedef BObjectList<Listener> ListenerList; 53 54private: 55 BLocker fLock; 56 NodeChildList fChildren; 57 ListenerList fListeners; 58}; 59 60 61class ValueNodeContainer::Listener { 62public: 63 virtual ~Listener(); 64 65 // container is locked 66 67 virtual void ValueNodeChanged(ValueNodeChild* nodeChild, 68 ValueNode* oldNode, ValueNode* newNode); 69 virtual void ValueNodeChildrenCreated(ValueNode* node); 70 virtual void ValueNodeChildrenDeleted(ValueNode* node); 71 virtual void ValueNodeValueChanged(ValueNode* node); 72}; 73 74 75#endif // VALUE_NODE_CONTAINER_H 76