new RecordVal Remove() method to clear a field

This commit is contained in:
Vern Paxson 2021-02-25 15:04:46 -08:00
parent 931cec4e06
commit c757db2714
2 changed files with 19 additions and 6 deletions

View file

@ -2879,23 +2879,29 @@ 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) )
{
if ( HasField(field) )
DeleteIfManaged((*record_val)[field], t);
auto t = rt->GetFieldType(field);
DeleteIfManaged((*record_val)[field], t);
(*record_val)[field] = ZVal();
(*is_in_record)[field] = false;
}
Modified();
Modified();
}
}
ValPtr RecordVal::GetFieldOrDefault(int field) const

View file

@ -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