Implement ranged container hooks for B{Object}List handler.

This commit is contained in:
Rene Gollent 2013-04-27 14:21:13 -04:00
parent 920576bbfe
commit fc23dd2ca2
2 changed files with 62 additions and 16 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012, Rene Gollent, rene@gollent.com
* Copyright 2012-2013, Rene Gollent, rene@gollent.com
* Distributed under the terms of the MIT License.
*/
@ -165,7 +165,8 @@ BListValueNode::BListValueNode(ValueNodeChild* nodeChild,
fType(type),
fLoader(NULL),
fItemCountType(NULL),
fItemCount(0)
fItemCount(0),
fCountChildCreated(false)
{
fType->AcquireReference();
}
@ -304,19 +305,60 @@ BListValueNode::ResolvedLocationAndValue(ValueLoader* valueLoader,
status_t
BListValueNode::CreateChildren()
{
if (fChildrenCreated)
return B_OK;
return CreateChildrenInRange(0, kMaxArrayElementCount);
}
int32
BListValueNode::CountChildren() const
{
return fChildren.CountItems();
}
ValueNodeChild*
BListValueNode::ChildAt(int32 index) const
{
return fChildren.ItemAt(index);
}
bool
BListValueNode::IsRangedContainer() const
{
return true;
}
void
BListValueNode::ClearChildren()
{
fChildren.MakeEmpty();
fCountChildCreated = false;
if (fContainer != NULL)
fContainer->NotifyValueNodeChildrenDeleted(this);
}
status_t
BListValueNode::CreateChildrenInRange(int32 lowIndex, int32 highIndex)
{
if (fLocationResolutionState != B_OK)
return fLocationResolutionState;
if (fItemCountType != NULL) {
if (lowIndex < 0)
lowIndex = 0;
if (highIndex >= fItemCount)
highIndex = fItemCount - 1;
if (!fCountChildCreated && fItemCountType != NULL) {
BListItemCountNodeChild* countChild = new(std::nothrow)
BListItemCountNodeChild(fItemCountLocation, this, fItemCountType);
if (countChild == NULL)
return B_NO_MEMORY;
fCountChildCreated = true;
countChild->SetContainer(fContainer);
fChildren.AddItem(countChild);
}
@ -343,7 +385,7 @@ BListValueNode::CreateChildren()
return result;
}
for (int32 i = 0; i < fItemCount && i < kMaxArrayElementCount; i++)
for (int32 i = lowIndex; i <= highIndex; i++)
{
BListElementNodeChild* child =
new(std::nothrow) BListElementNodeChild(this, i, type);
@ -362,15 +404,12 @@ BListValueNode::CreateChildren()
}
int32
BListValueNode::CountChildren() const
status_t
BListValueNode::SupportedChildRange(int32& lowIndex, int32& highIndex) const
{
return fChildren.CountItems();
lowIndex = 0;
highIndex = fItemCount - 1;
return B_OK;
}
ValueNodeChild*
BListValueNode::ChildAt(int32 index) const
{
return fChildren.ItemAt(index);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012, Rene Gollent, rene@gollent.com.
* Copyright 2012-2013, Rene Gollent, rene@gollent.com.
* Distributed under the terms of the MIT License.
*/
#ifndef BLIST_VALUE_NODE_H
@ -36,6 +36,12 @@ public:
virtual int32 CountChildren() const;
virtual ValueNodeChild* ChildAt(int32 index) const;
virtual bool IsRangedContainer() const;
virtual void ClearChildren();
virtual status_t CreateChildrenInRange(int32 lowIndex,
int32 highIndex);
virtual status_t SupportedChildRange(int32& lowIndex,
int32& highIndex) const;
private:
class BListElementNodeChild;
class BListItemCountNodeChild;
@ -55,6 +61,7 @@ private:
BVariant fItemCountLocation;
Type* fItemCountType;
int32 fItemCount;
bool fCountChildCreated;
};