mirror of
https://github.com/zeek/zeek.git
synced 2025-10-08 09:38:19 +00:00
Deprecate RecordVal::Lookup(const char*, bool)
Replace with GetField(const char*) and GetFieldOrDefault(const char*).
This commit is contained in:
parent
2b4d80c849
commit
5bf2ed02d7
14 changed files with 128 additions and 80 deletions
44
src/Val.h
44
src/Val.h
|
@ -1000,6 +1000,46 @@ public:
|
|||
Val* LookupWithDefault(int field) const
|
||||
{ return GetFieldOrDefault(field).release(); }
|
||||
|
||||
/**
|
||||
* Returns the value of a given field name.
|
||||
* @param field The name of a field to retrieve.
|
||||
* @return The value of the given field. If no such field name exists,
|
||||
* a fatal error occurs.
|
||||
*/
|
||||
const IntrusivePtr<Val>& GetField(const char* field) const;
|
||||
|
||||
/**
|
||||
* Returns the value of a given field name as cast to type @c T.
|
||||
* @param field The name of a field to retrieve.
|
||||
* @return The value of the given field cast to type @c T. If no such
|
||||
* field name exists, a fatal error occurs.
|
||||
*/
|
||||
template <class T>
|
||||
IntrusivePtr<T> GetField(const char* field) const
|
||||
{ return cast_intrusive<T>(GetField(field)); }
|
||||
|
||||
/**
|
||||
* Returns the value of a given field name if it's previously been
|
||||
* assigned, or else returns the value created from evaluating the record
|
||||
* fields' &default expression.
|
||||
* @param field The name of a field to retrieve.
|
||||
* @return The value of the given field. or the default value
|
||||
* if the field hasn't been assigned yet. If no such field name exists,
|
||||
* a fatal error occurs.
|
||||
*/
|
||||
IntrusivePtr<Val> GetFieldOrDefault(const char* field) const;
|
||||
|
||||
/**
|
||||
* Returns the value of a given field name or its default value
|
||||
* as cast to type @c T.
|
||||
* @param field The name of a field to retrieve.
|
||||
* @return The value of the given field or its default value cast to
|
||||
* type @c T. If no such field name exists, a fatal error occurs.
|
||||
*/
|
||||
template <class T>
|
||||
IntrusivePtr<T> GetFieldOrDefault(const char* field) const
|
||||
{ return cast_intrusive<T>(GetField(field)); }
|
||||
|
||||
/**
|
||||
* Looks up the value of a field by field name. If the field doesn't
|
||||
* exist in the record type, it's an internal error: abort.
|
||||
|
@ -1008,7 +1048,9 @@ public:
|
|||
* the field has yet to be initialized.
|
||||
* @return the value in field \a field.
|
||||
*/
|
||||
IntrusivePtr<Val> Lookup(const char* field, bool with_default = false) const;
|
||||
[[deprecated("Remove in v4.1. Use GetField() or GetFieldOrDefault().")]]
|
||||
Val* Lookup(const char* field, bool with_default = false) const
|
||||
{ return with_default ? GetFieldOrDefault(field).release() : GetField(field).get(); }
|
||||
|
||||
void Describe(ODesc* d) const override;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue