mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
Added TableVal::ToMap to retrieve a table's entire contents as a unordered_map
This commit is contained in:
parent
4aa73f6f7d
commit
6e8baafeb9
2 changed files with 21 additions and 0 deletions
16
src/Val.cc
16
src/Val.cc
|
@ -2311,6 +2311,22 @@ ListValPtr TableVal::ToPureListVal() const
|
||||||
return ToListVal(tl[0]->Tag());
|
return ToListVal(tl[0]->Tag());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::unordered_map<Val*, ValPtr> TableVal::ToMap() const
|
||||||
|
{
|
||||||
|
std::unordered_map<Val*, ValPtr> res;
|
||||||
|
|
||||||
|
for ( const auto& iter : *table_val )
|
||||||
|
{
|
||||||
|
auto k = iter.GetHashKey();
|
||||||
|
auto v = iter.GetValue<TableEntryVal*>();
|
||||||
|
auto vl = table_hash->RecoverVals(*k);
|
||||||
|
|
||||||
|
res[vl.release()] = v->GetVal();
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
const detail::AttrPtr& TableVal::GetAttr(detail::AttrTag t) const
|
const detail::AttrPtr& TableVal::GetAttr(detail::AttrTag t) const
|
||||||
{
|
{
|
||||||
return attrs ? attrs->Find(t) : detail::Attr::nil;
|
return attrs ? attrs->Find(t) : detail::Attr::nil;
|
||||||
|
|
|
@ -895,6 +895,11 @@ public:
|
||||||
// with non-composite index type).
|
// with non-composite index type).
|
||||||
ListValPtr ToPureListVal() const;
|
ListValPtr ToPureListVal() const;
|
||||||
|
|
||||||
|
// Returns a map of index-to-value's. The value is nil for sets.
|
||||||
|
// It's up to the caller to Unref() the index Val* when done
|
||||||
|
// with it.
|
||||||
|
std::unordered_map<Val*, ValPtr> ToMap() const;
|
||||||
|
|
||||||
void SetAttrs(detail::AttributesPtr attrs);
|
void SetAttrs(detail::AttributesPtr attrs);
|
||||||
|
|
||||||
const detail::AttrPtr& GetAttr(detail::AttrTag t) const;
|
const detail::AttrPtr& GetAttr(detail::AttrTag t) const;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue