Implement ranged container hooks in ArrayValueNode.
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
|
* Copyright 2013, Rene Gollent, [email protected].
|
||||||
* Copyright 2009, Ingo Weinhold, [email protected].
|
* Copyright 2009, Ingo Weinhold, [email protected].
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
@@ -76,18 +77,62 @@ AbstractArrayValueNode::CreateChildren()
|
|||||||
if (!fChildren.IsEmpty())
|
if (!fChildren.IsEmpty())
|
||||||
return B_OK;
|
return B_OK;
|
||||||
|
|
||||||
|
return CreateChildrenInRange(0, kMaxArrayElementCount - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int32
|
||||||
|
AbstractArrayValueNode::CountChildren() const
|
||||||
|
{
|
||||||
|
return fChildren.CountItems();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ValueNodeChild*
|
||||||
|
AbstractArrayValueNode::ChildAt(int32 index) const
|
||||||
|
{
|
||||||
|
return fChildren.ItemAt(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
AbstractArrayValueNode::IsRangedContainer() const
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
AbstractArrayValueNode::ClearChildren()
|
||||||
|
{
|
||||||
|
fChildren.MakeEmpty();
|
||||||
|
if (fContainer != NULL)
|
||||||
|
fContainer->NotifyValueNodeChildrenDeleted(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
AbstractArrayValueNode::CreateChildrenInRange(int32 lowIndex,
|
||||||
|
int32 highIndex)
|
||||||
|
{
|
||||||
|
// TODO: ensure that we don't already have children in the specified
|
||||||
|
// index range. These need to be skipped if so.
|
||||||
TRACE_LOCALS("TYPE_ARRAY\n");
|
TRACE_LOCALS("TYPE_ARRAY\n");
|
||||||
|
|
||||||
int32 dimensionCount = fType->CountDimensions();
|
int32 dimensionCount = fType->CountDimensions();
|
||||||
bool isFinalDimension = fDimension + 1 == dimensionCount;
|
bool isFinalDimension = fDimension + 1 == dimensionCount;
|
||||||
|
|
||||||
ArrayDimension* dimension = fType->DimensionAt(fDimension);
|
int32 lowerBound, upperBound;
|
||||||
uint64 elementCount = dimension->CountElements();
|
if (SupportedChildRange(lowerBound, upperBound) == B_OK) {
|
||||||
if (elementCount == 0 || elementCount > kMaxArrayElementCount)
|
// clamp inputs to supported range.
|
||||||
elementCount = kMaxArrayElementCount;
|
if (lowIndex < lowerBound)
|
||||||
|
lowIndex = lowerBound;
|
||||||
|
if (highIndex > upperBound)
|
||||||
|
highIndex = upperBound;
|
||||||
|
}
|
||||||
|
|
||||||
// create children for the array elements
|
// create children for the array elements
|
||||||
for (int32 i = 0; i < (int32)elementCount; i++) {
|
for (int32 i = lowIndex; i <= (int32)highIndex; i++) {
|
||||||
BString name(Name());
|
BString name(Name());
|
||||||
name << '[' << i << ']';
|
name << '[' << i << ']';
|
||||||
if (name.Length() <= Name().Length())
|
if (name.Length() <= Name().Length())
|
||||||
@@ -117,17 +162,23 @@ AbstractArrayValueNode::CreateChildren()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int32
|
status_t
|
||||||
AbstractArrayValueNode::CountChildren() const
|
AbstractArrayValueNode::SupportedChildRange(int32& lowIndex,
|
||||||
|
int32& highIndex) const
|
||||||
{
|
{
|
||||||
return fChildren.CountItems();
|
ArrayDimension* dimension = fType->DimensionAt(fDimension);
|
||||||
}
|
|
||||||
|
|
||||||
|
SubrangeType* dimensionType = dynamic_cast<SubrangeType*>(
|
||||||
|
dimension->GetType());
|
||||||
|
|
||||||
ValueNodeChild*
|
if (dimensionType != NULL) {
|
||||||
AbstractArrayValueNode::ChildAt(int32 index) const
|
lowIndex = dimensionType->LowerBound().ToInt32();
|
||||||
{
|
highIndex = dimensionType->UpperBound().ToInt32();
|
||||||
return fChildren.ItemAt(index);
|
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
return B_UNSUPPORTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
|
* Copyright 2013, Rene Gollent, [email protected].
|
||||||
* Copyright 2009, Ingo Weinhold, [email protected].
|
* Copyright 2009, Ingo Weinhold, [email protected].
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
@@ -40,6 +41,12 @@ public:
|
|||||||
virtual int32 CountChildren() const;
|
virtual int32 CountChildren() const;
|
||||||
virtual ValueNodeChild* ChildAt(int32 index) 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;
|
||||||
protected:
|
protected:
|
||||||
typedef BObjectList<AbstractArrayValueNodeChild> ChildList;
|
typedef BObjectList<AbstractArrayValueNodeChild> ChildList;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user