added constructors for directly building ZVal's

This commit is contained in:
Vern Paxson 2021-05-02 12:32:40 -07:00
parent 9e8eb30620
commit e4ae853058

View file

@ -8,19 +8,31 @@
namespace zeek { namespace zeek {
class StringVal;
class AddrVal; class AddrVal;
class SubNetVal;
class File; class File;
class Func; class Func;
class ListVal; class ListVal;
class OpaqueVal; class OpaqueVal;
class PatternVal; class PatternVal;
class TableVal;
class RecordVal; class RecordVal;
class VectorVal; class StringVal;
class SubNetVal;
class TableVal;
class Type; class Type;
class Val; class Val;
class VectorVal;
using AddrValPtr = IntrusivePtr<AddrVal>;
using EnumValPtr = IntrusivePtr<EnumVal>;
using ListValPtr = IntrusivePtr<ListVal>;
using OpaqueValPtr = IntrusivePtr<OpaqueVal>;
using PatternValPtr = IntrusivePtr<PatternVal>;
using RecordValPtr = IntrusivePtr<RecordVal>;
using StringValPtr = IntrusivePtr<StringVal>;
using SubNetValPtr = IntrusivePtr<SubNetVal>;
using TableValPtr = IntrusivePtr<TableVal>;
using ValPtr = IntrusivePtr<Val>;
using VectorValPtr = IntrusivePtr<VectorVal>;
// Note that a ZVal by itself is ambiguous: it doesn't track its type. // Note that a ZVal by itself is ambiguous: it doesn't track its type.
// This makes them consume less memory and cheaper to copy. It does // This makes them consume less memory and cheaper to copy. It does
@ -43,6 +55,35 @@ union ZVal {
// Construct an empty value compatible with the given type. // Construct an empty value compatible with the given type.
ZVal(const TypePtr& t); ZVal(const TypePtr& t);
// Construct directly.
ZVal(bro_int_t v) { int_val = v; }
ZVal(bro_uint_t v) { uint_val = v; }
ZVal(double v) { double_val = v; }
ZVal(StringVal* v) { string_val = v; }
ZVal(AddrVal* v) { addr_val = v; }
ZVal(SubNetVal* v) { subnet_val = v; }
ZVal(File* v) { file_val = v; }
ZVal(Func* v) { func_val = v; }
ZVal(ListVal* v) { list_val = v; }
ZVal(OpaqueVal* v) { opaque_val = v; }
ZVal(PatternVal* v) { re_val = v; }
ZVal(TableVal* v) { table_val = v; }
ZVal(RecordVal* v) { record_val = v; }
ZVal(VectorVal* v) { vector_val = v; }
ZVal(Type* v) { type_val = v; }
ZVal(StringValPtr v) { string_val = v.release(); }
ZVal(AddrValPtr v) { addr_val = v.release(); }
ZVal(SubNetValPtr v) { subnet_val = v.release(); }
ZVal(ListValPtr v) { list_val = v.release(); }
ZVal(OpaqueValPtr v) { opaque_val = v.release(); }
ZVal(PatternValPtr v) { re_val = v.release(); }
ZVal(TableValPtr v) { table_val = v.release(); }
ZVal(RecordValPtr v) { record_val = v.release(); }
ZVal(VectorValPtr v) { vector_val = v.release(); }
ZVal(TypePtr v) { type_val = v.release(); }
// Convert to a higher-level script value. The caller needs to // Convert to a higher-level script value. The caller needs to
// ensure that they're providing the correct type. // ensure that they're providing the correct type.
ValPtr ToVal(const TypePtr& t) const; ValPtr ToVal(const TypePtr& t) const;