From e4ae853058e951b145fc673ea993936b10f8a64b Mon Sep 17 00:00:00 2001 From: Vern Paxson Date: Sun, 2 May 2021 12:32:40 -0700 Subject: [PATCH] added constructors for directly building ZVal's --- src/ZVal.h | 49 +++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 45 insertions(+), 4 deletions(-) diff --git a/src/ZVal.h b/src/ZVal.h index 1e1af6e900..a0d9939242 100644 --- a/src/ZVal.h +++ b/src/ZVal.h @@ -8,19 +8,31 @@ namespace zeek { -class StringVal; class AddrVal; -class SubNetVal; class File; class Func; class ListVal; class OpaqueVal; class PatternVal; -class TableVal; class RecordVal; -class VectorVal; +class StringVal; +class SubNetVal; +class TableVal; class Type; class Val; +class VectorVal; + +using AddrValPtr = IntrusivePtr; +using EnumValPtr = IntrusivePtr; +using ListValPtr = IntrusivePtr; +using OpaqueValPtr = IntrusivePtr; +using PatternValPtr = IntrusivePtr; +using RecordValPtr = IntrusivePtr; +using StringValPtr = IntrusivePtr; +using SubNetValPtr = IntrusivePtr; +using TableValPtr = IntrusivePtr; +using ValPtr = IntrusivePtr; +using VectorValPtr = IntrusivePtr; // 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 @@ -43,6 +55,35 @@ union ZVal { // Construct an empty value compatible with the given type. 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 // ensure that they're providing the correct type. ValPtr ToVal(const TypePtr& t) const;