2 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
7 #include "StackFrameValues.h"
11 #include "FunctionID.h"
12 #include "TypeComponentPath.h"
15 struct StackFrameValues::Key
{
17 TypeComponentPath
* path
;
19 Key(ObjectID
* variable
, TypeComponentPath
* path
)
26 uint32
HashValue() const
28 return variable
->HashValue() ^ path
->HashValue();
31 bool operator==(const Key
& other
) const
33 return *variable
== *other
.variable
&& *path
== *other
.path
;
38 struct StackFrameValues::ValueEntry
: Key
{
42 ValueEntry(ObjectID
* variable
, TypeComponentPath
* path
)
46 variable
->AcquireReference();
47 path
->AcquireReference();
52 variable
->ReleaseReference();
53 path
->ReleaseReference();
58 struct StackFrameValues::ValueEntryHashDefinition
{
60 typedef ValueEntry ValueType
;
62 size_t HashKey(const Key
& key
) const
64 return key
.HashValue();
67 size_t Hash(const ValueEntry
* value
) const
69 return value
->HashValue();
72 bool Compare(const Key
& key
, const ValueEntry
* value
) const
77 ValueEntry
*& GetLink(ValueEntry
* value
) const
84 StackFrameValues::StackFrameValues()
91 StackFrameValues::StackFrameValues(const StackFrameValues
& other
)
98 throw std::bad_alloc();
101 for (ValueTable::Iterator it
= other
.fValues
->GetIterator();
102 ValueEntry
* entry
= it
.Next();) {
103 if (SetValue(entry
->variable
, entry
->path
, entry
->value
) != B_OK
)
104 throw std::bad_alloc();
113 StackFrameValues::~StackFrameValues()
120 StackFrameValues::Init()
122 fValues
= new(std::nothrow
) ValueTable
;
126 return fValues
->Init();
131 StackFrameValues::GetValue(ObjectID
* variable
, const TypeComponentPath
* path
,
132 BVariant
& _value
) const
134 ValueEntry
* entry
= fValues
->Lookup(
135 Key(variable
, (TypeComponentPath
*)path
));
139 _value
= entry
->value
;
145 StackFrameValues::HasValue(ObjectID
* variable
, const TypeComponentPath
* path
)
148 return fValues
->Lookup(Key(variable
, (TypeComponentPath
*)path
)) != NULL
;
153 StackFrameValues::SetValue(ObjectID
* variable
, TypeComponentPath
* path
,
154 const BVariant
& value
)
156 ValueEntry
* entry
= fValues
->Lookup(Key(variable
, path
));
158 entry
= new(std::nothrow
) ValueEntry(variable
, path
);
161 fValues
->Insert(entry
);
164 entry
->value
= value
;
170 StackFrameValues::_Cleanup()
172 if (fValues
!= NULL
) {
173 ValueEntry
* entry
= fValues
->Clear(true);
175 while (entry
!= NULL
) {
176 ValueEntry
* next
= entry
->next
;