Skip to content

Commit

Permalink
Show total capacity on BList/BObjectList nodes.
Browse files Browse the repository at this point in the history
- Since we currently limit the maximum number of child elements we'll
  show, it's helpful information to know the actual capacity of the list
  in case it contains more, especially when we later support requesting
  additional elements to be retrieved.
  • Loading branch information
anevilyak committed Dec 5, 2012
1 parent 6d3ea79 commit e402c5e
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 4 deletions.
88 changes: 84 additions & 4 deletions src/apps/debugger/value/value_nodes/BListValueNode.cpp
Expand Up @@ -94,6 +94,68 @@ BListValueNode::BListElementNodeChild::ResolveLocation(
}


//#pragma mark - BListItemCountNodeChild

class BListValueNode::BListItemCountNodeChild : public ValueNodeChild {
public:
BListItemCountNodeChild(BVariant location,
BListValueNode* parent, Type* type);
virtual ~BListItemCountNodeChild();

virtual const BString& Name() const { return fName; };
virtual Type* GetType() const { return fType; };
virtual ValueNode* Parent() const { return fParent; };

virtual status_t ResolveLocation(ValueLoader* valueLoader,
ValueLocation*& _location);

private:
Type* fType;
BListValueNode* fParent;
BVariant fLocation;
BString fName;
};


BListValueNode::BListItemCountNodeChild::BListItemCountNodeChild(
BVariant location, BListValueNode* parent, Type* type)
:
ValueNodeChild(),
fType(type),
fParent(parent),
fLocation(location),
fName("Capacity")
{
fType->AcquireReference();
fParent->AcquireReference();
}


BListValueNode::BListItemCountNodeChild::~BListItemCountNodeChild()
{
fType->ReleaseReference();
fParent->ReleaseReference();
}


status_t
BListValueNode::BListItemCountNodeChild::ResolveLocation(
ValueLoader* valueLoader, ValueLocation*& _location)
{
ValueLocation* location = new(std::nothrow) ValueLocation();
if (location == NULL)
return B_NO_MEMORY;

ValuePieceLocation piece;
piece.SetToMemory(fLocation.ToUInt64());
piece.SetSize(sizeof(int32));
location->AddPiece(piece);

_location = location;
return B_OK;
}


//#pragma mark - BListValueNode

BListValueNode::BListValueNode(ValueNodeChild* nodeChild,
Expand All @@ -102,6 +164,7 @@ BListValueNode::BListValueNode(ValueNodeChild* nodeChild,
ValueNode(nodeChild),
fType(type),
fLoader(NULL),
fItemCountType(NULL),
fItemCount(0)
{
fType->AcquireReference();
Expand All @@ -114,6 +177,9 @@ BListValueNode::~BListValueNode()
for (int32 i = 0; i < fChildren.CountItems(); i++)
fChildren.ItemAt(i)->ReleaseReference();

if (fItemCountType != NULL)
fItemCountType->ReleaseReference();

delete fLoader;
}

Expand Down Expand Up @@ -154,7 +220,7 @@ BListValueNode::ResolvedLocationAndValue(ValueLoader* valueLoader,
ValueLocation* memberLocation = NULL;
CompoundType* baseType = dynamic_cast<CompoundType*>(fType);

if (baseType->CountTemplateParameters()) {
if (baseType->CountTemplateParameters() != 0) {
// for BObjectList we need to walk up
// the hierarchy: BObjectList -> _PointerList_ -> BList
baseType = dynamic_cast<CompoundType*>(baseType->BaseTypeAt(0)
Expand Down Expand Up @@ -200,6 +266,11 @@ BListValueNode::ResolvedLocationAndValue(ValueLoader* valueLoader,
return error;
}

fItemCountType = member->GetType();
fItemCountType->AcquireReference();

fItemCountLocation = memberLocation->PieceAt(0).address;

BVariant listSize;
error = valueLoader->LoadValue(memberLocation, valueType,
false, listSize);
Expand Down Expand Up @@ -229,11 +300,19 @@ BListValueNode::ResolvedLocationAndValue(ValueLoader* valueLoader,
status_t
BListValueNode::CreateChildren()
{
if (fItemCount == 0 || fChildrenCreated) {
fChildrenCreated = true;
if (fChildrenCreated)
return B_OK;
}

BListItemCountNodeChild* countChild = new(std::nothrow)
BListItemCountNodeChild(fItemCountLocation, this, fItemCountType);

if (countChild == NULL)
return B_NO_MEMORY;

countChild->SetContainer(fContainer);
fChildren.AddItem(countChild);

BReference<Type> addressTypeRef;
Type* type = NULL;
CompoundType* objectType = dynamic_cast<CompoundType*>(fType);
if (objectType->CountTemplateParameters() != 0) {
Expand All @@ -244,6 +323,7 @@ BListValueNode::CreateChildren()
return result;

type = addressType;
addressTypeRef.SetTo(type, true);
} else {
BString typeName;
TypeLookupConstraints constraints;
Expand Down
4 changes: 4 additions & 0 deletions src/apps/debugger/value/value_nodes/BListValueNode.h
Expand Up @@ -38,9 +38,11 @@ class BListValueNode : public ValueNode {

private:
class BListElementNodeChild;
class BListItemCountNodeChild;

// for GCC2
friend class BListElementNodeChild;
friend class BListItemCountNodeChild;

typedef BObjectList<ValueNodeChild> ChildNodeList;

Expand All @@ -50,6 +52,8 @@ class BListValueNode : public ValueNode {
ChildNodeList fChildren;
ValueLoader* fLoader;
BVariant fDataLocation;
BVariant fItemCountLocation;
Type* fItemCountType;
int32 fItemCount;
};

Expand Down

0 comments on commit e402c5e

Please sign in to comment.