mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
new RecordVal Remove() method to clear a field
This commit is contained in:
parent
931cec4e06
commit
c757db2714
2 changed files with 19 additions and 6 deletions
12
src/Val.cc
12
src/Val.cc
|
@ -2879,24 +2879,30 @@ ValPtr RecordVal::SizeVal() const
|
|||
|
||||
void RecordVal::Assign(int field, ValPtr new_val)
|
||||
{
|
||||
auto t = rt->GetFieldType(field);
|
||||
|
||||
if ( new_val )
|
||||
{
|
||||
auto t = rt->GetFieldType(field);
|
||||
(*record_val)[field] = ZVal(new_val, t);
|
||||
(*is_in_record)[field] = true;
|
||||
Modified();
|
||||
}
|
||||
else
|
||||
Remove(field);
|
||||
}
|
||||
|
||||
void RecordVal::Remove(int field)
|
||||
{
|
||||
if ( HasField(field) )
|
||||
{
|
||||
auto t = rt->GetFieldType(field);
|
||||
DeleteIfManaged((*record_val)[field], t);
|
||||
|
||||
(*record_val)[field] = ZVal();
|
||||
(*is_in_record)[field] = false;
|
||||
}
|
||||
|
||||
Modified();
|
||||
}
|
||||
}
|
||||
|
||||
ValPtr RecordVal::GetFieldOrDefault(int field) const
|
||||
{
|
||||
|
|
|
@ -1061,6 +1061,13 @@ public:
|
|||
void Assign(int field, Ts&&... args)
|
||||
{ Assign(field, make_intrusive<T>(std::forward<Ts>(args)...)); }
|
||||
|
||||
/**
|
||||
* Sets the given record field to not-in-record. Equivalent to
|
||||
* Assign using a nil ValPtr.
|
||||
* @param field The field index to remove.
|
||||
*/
|
||||
void Remove(int field);
|
||||
|
||||
/**
|
||||
* Appends a value to the record's fields. The caller is responsible
|
||||
* for ensuring that fields are appended in the correct order and
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue