mirror of
https://github.com/zeek/zeek.git
synced 2025-10-09 01:58:20 +00:00
Use type aliases for IntrusivePtr definitions
This commit is contained in:
parent
f6a251cdac
commit
ec9eff0bd5
180 changed files with 2026 additions and 1893 deletions
265
src/Val.h
265
src/Val.h
|
@ -34,6 +34,9 @@ class Func;
|
|||
class BroFile;
|
||||
class PrefixTable;
|
||||
|
||||
using BroFilePtr = zeek::IntrusivePtr<BroFile>;
|
||||
using FuncPtr = zeek::IntrusivePtr<Func>;
|
||||
|
||||
class Val;
|
||||
class PortVal;
|
||||
class AddrVal;
|
||||
|
@ -49,6 +52,16 @@ class OpaqueVal;
|
|||
class VectorVal;
|
||||
class TableEntryVal;
|
||||
|
||||
using AddrValPtr = zeek::IntrusivePtr<AddrVal>;
|
||||
using EnumValPtr = zeek::IntrusivePtr<EnumVal>;
|
||||
using ListValPtr = zeek::IntrusivePtr<ListVal>;
|
||||
using PortValPtr = zeek::IntrusivePtr<PortVal>;
|
||||
using RecordValPtr = zeek::IntrusivePtr<RecordVal>;
|
||||
using StringValPtr = zeek::IntrusivePtr<StringVal>;
|
||||
using TableValPtr = zeek::IntrusivePtr<TableVal>;
|
||||
using ValPtr = zeek::IntrusivePtr<Val>;
|
||||
using VectorValPtr = zeek::IntrusivePtr<VectorVal>;
|
||||
|
||||
class IPAddr;
|
||||
class IPPrefix;
|
||||
|
||||
|
@ -77,8 +90,8 @@ union BroValUnion {
|
|||
BroFile* file_val;
|
||||
RE_Matcher* re_val;
|
||||
PDict<TableEntryVal>* table_val;
|
||||
std::vector<zeek::IntrusivePtr<Val>>* record_val;
|
||||
std::vector<zeek::IntrusivePtr<Val>>* vector_val;
|
||||
std::vector<ValPtr>* record_val;
|
||||
std::vector<ValPtr>* vector_val;
|
||||
|
||||
BroValUnion() = default;
|
||||
|
||||
|
@ -115,7 +128,7 @@ union BroValUnion {
|
|||
|
||||
class Val : public BroObj {
|
||||
public:
|
||||
static inline const zeek::IntrusivePtr<Val> nil;
|
||||
static inline const ValPtr nil;
|
||||
|
||||
[[deprecated("Remove in v4.1. Use IntervalVal(), TimeVal(), or DoubleVal() constructors.")]]
|
||||
Val(double d, zeek::TypeTag t)
|
||||
|
@ -124,16 +137,16 @@ public:
|
|||
|
||||
[[deprecated("Remove in v4.1. Construct from IntrusivePtr instead.")]]
|
||||
explicit Val(Func* f);
|
||||
explicit Val(zeek::IntrusivePtr<Func> f);
|
||||
explicit Val(FuncPtr f);
|
||||
|
||||
[[deprecated("Remove in v4.1. Construct from IntrusivePtr instead.")]]
|
||||
explicit Val(BroFile* f);
|
||||
// Note, the file will be closed after this Val is destructed if there's
|
||||
// no other remaining references.
|
||||
explicit Val(zeek::IntrusivePtr<BroFile> f);
|
||||
explicit Val(BroFilePtr f);
|
||||
|
||||
// Extra arg to differentiate from protected version.
|
||||
Val(zeek::IntrusivePtr<zeek::Type> t, bool type_type)
|
||||
Val(zeek::TypePtr t, bool type_type)
|
||||
: type(zeek::make_intrusive<zeek::TypeType>(std::move(t)))
|
||||
{}
|
||||
|
||||
|
@ -148,7 +161,7 @@ public:
|
|||
~Val() override;
|
||||
|
||||
Val* Ref() { ::Ref(this); return this; }
|
||||
zeek::IntrusivePtr<Val> Clone();
|
||||
ValPtr Clone();
|
||||
|
||||
bool IsZero() const;
|
||||
bool IsOne() const;
|
||||
|
@ -163,7 +176,7 @@ public:
|
|||
|
||||
// Returns a new Val with the "size" of this Val. What constitutes
|
||||
// size depends on the Val's type.
|
||||
virtual zeek::IntrusivePtr<Val> SizeVal() const;
|
||||
virtual ValPtr SizeVal() const;
|
||||
|
||||
// Bytes in total value object.
|
||||
virtual unsigned int MemoryAllocation() const;
|
||||
|
@ -182,7 +195,7 @@ public:
|
|||
[[deprecated("Remove in v4.1. Use GetType().")]]
|
||||
const zeek::Type* Type() const { return type.get(); }
|
||||
|
||||
const zeek::IntrusivePtr<zeek::Type>& GetType() const
|
||||
const zeek::TypePtr& GetType() const
|
||||
{ return type; }
|
||||
|
||||
template <class T>
|
||||
|
@ -215,10 +228,10 @@ public:
|
|||
CONST_ACCESSOR(zeek::TYPE_STRING, BroString*, string_val, AsString)
|
||||
CONST_ACCESSOR(zeek::TYPE_FUNC, Func*, func_val, AsFunc)
|
||||
CONST_ACCESSOR(zeek::TYPE_TABLE, PDict<TableEntryVal>*, table_val, AsTable)
|
||||
CONST_ACCESSOR(zeek::TYPE_RECORD, std::vector<zeek::IntrusivePtr<Val>>*, record_val, AsRecord)
|
||||
CONST_ACCESSOR(zeek::TYPE_RECORD, std::vector<ValPtr>*, record_val, AsRecord)
|
||||
CONST_ACCESSOR(zeek::TYPE_FILE, BroFile*, file_val, AsFile)
|
||||
CONST_ACCESSOR(zeek::TYPE_PATTERN, RE_Matcher*, re_val, AsPattern)
|
||||
CONST_ACCESSOR(zeek::TYPE_VECTOR, std::vector<zeek::IntrusivePtr<Val>>*, vector_val, AsVector)
|
||||
CONST_ACCESSOR(zeek::TYPE_VECTOR, std::vector<ValPtr>*, vector_val, AsVector)
|
||||
|
||||
const IPPrefix& AsSubNet() const
|
||||
{
|
||||
|
@ -252,9 +265,9 @@ public:
|
|||
ACCESSOR(zeek::TYPE_FUNC, Func*, func_val, AsFunc)
|
||||
ACCESSOR(zeek::TYPE_FILE, BroFile*, file_val, AsFile)
|
||||
ACCESSOR(zeek::TYPE_PATTERN, RE_Matcher*, re_val, AsPattern)
|
||||
ACCESSOR(zeek::TYPE_VECTOR, std::vector<zeek::IntrusivePtr<Val>>*, vector_val, AsVector)
|
||||
ACCESSOR(zeek::TYPE_VECTOR, std::vector<ValPtr>*, vector_val, AsVector)
|
||||
|
||||
zeek::IntrusivePtr<Func> AsFuncPtr() const;
|
||||
FuncPtr AsFuncPtr() const;
|
||||
|
||||
const IPPrefix& AsSubNet()
|
||||
{
|
||||
|
@ -328,9 +341,9 @@ public:
|
|||
|
||||
static bool WouldOverflow(const zeek::Type* from_type, const zeek::Type* to_type, const Val* val);
|
||||
|
||||
zeek::IntrusivePtr<TableVal> GetRecordFields();
|
||||
TableValPtr GetRecordFields();
|
||||
|
||||
zeek::IntrusivePtr<StringVal> ToJSON(bool only_loggable=false, RE_Matcher* re=nullptr);
|
||||
StringValPtr ToJSON(bool only_loggable=false, RE_Matcher* re=nullptr);
|
||||
|
||||
protected:
|
||||
|
||||
|
@ -344,9 +357,9 @@ protected:
|
|||
virtual void ValDescribe(ODesc* d) const;
|
||||
virtual void ValDescribeReST(ODesc* d) const;
|
||||
|
||||
static zeek::IntrusivePtr<Val> MakeBool(bool b);
|
||||
static zeek::IntrusivePtr<Val> MakeInt(bro_int_t i);
|
||||
static zeek::IntrusivePtr<Val> MakeCount(bro_uint_t u);
|
||||
static ValPtr MakeBool(bool b);
|
||||
static ValPtr MakeInt(bro_int_t i);
|
||||
static ValPtr MakeCount(bro_uint_t u);
|
||||
|
||||
template<typename V>
|
||||
Val(V&& v, zeek::TypeTag t) noexcept
|
||||
|
@ -354,32 +367,32 @@ protected:
|
|||
{}
|
||||
|
||||
template<typename V>
|
||||
Val(V&& v, zeek::IntrusivePtr<zeek::Type> t) noexcept
|
||||
Val(V&& v, zeek::TypePtr t) noexcept
|
||||
: val(std::forward<V>(v)), type(std::move(t))
|
||||
{}
|
||||
|
||||
explicit Val(zeek::IntrusivePtr<zeek::Type> t) noexcept
|
||||
explicit Val(zeek::TypePtr t) noexcept
|
||||
: type(std::move(t))
|
||||
{}
|
||||
|
||||
ACCESSOR(zeek::TYPE_TABLE, PDict<TableEntryVal>*, table_val, AsNonConstTable)
|
||||
ACCESSOR(zeek::TYPE_RECORD, std::vector<zeek::IntrusivePtr<Val>>*, record_val, AsNonConstRecord)
|
||||
ACCESSOR(zeek::TYPE_RECORD, std::vector<ValPtr>*, record_val, AsNonConstRecord)
|
||||
|
||||
// For internal use by the Val::Clone() methods.
|
||||
struct CloneState {
|
||||
// Caches a cloned value for later reuse during the same
|
||||
// cloning operation. For recursive types, call this *before*
|
||||
// descending down.
|
||||
zeek::IntrusivePtr<Val> NewClone(Val* src, zeek::IntrusivePtr<Val> dst);
|
||||
ValPtr NewClone(Val* src, ValPtr dst);
|
||||
|
||||
std::unordered_map<Val*, Val*> clones;
|
||||
};
|
||||
|
||||
zeek::IntrusivePtr<Val> Clone(CloneState* state);
|
||||
virtual zeek::IntrusivePtr<Val> DoClone(CloneState* state);
|
||||
ValPtr Clone(CloneState* state);
|
||||
virtual ValPtr DoClone(CloneState* state);
|
||||
|
||||
BroValUnion val;
|
||||
zeek::IntrusivePtr<zeek::Type> type;
|
||||
zeek::TypePtr type;
|
||||
|
||||
#ifdef DEBUG
|
||||
// For debugging, we keep the name of the ID to which a Val is bound.
|
||||
|
@ -405,21 +418,21 @@ public:
|
|||
inline Val* GetTrue() const
|
||||
{ return b_true->Ref(); }
|
||||
|
||||
inline const zeek::IntrusivePtr<Val>& True() const
|
||||
inline const ValPtr& True() const
|
||||
{ return b_true; }
|
||||
|
||||
[[deprecated("Remove in v4.1. Use val_mgr->False() instead.")]]
|
||||
inline Val* GetFalse() const
|
||||
{ return b_false->Ref(); }
|
||||
|
||||
inline const zeek::IntrusivePtr<Val>& False() const
|
||||
inline const ValPtr& False() const
|
||||
{ return b_false; }
|
||||
|
||||
[[deprecated("Remove in v4.1. Use val_mgr->Bool() instead.")]]
|
||||
inline Val* GetBool(bool b) const
|
||||
{ return b ? b_true->Ref() : b_false->Ref(); }
|
||||
|
||||
inline const zeek::IntrusivePtr<Val>& Bool(bool b) const
|
||||
inline const ValPtr& Bool(bool b) const
|
||||
{ return b ? b_true : b_false; }
|
||||
|
||||
[[deprecated("Remove in v4.1. Use val_mgr->Int() instead.")]]
|
||||
|
@ -429,7 +442,7 @@ public:
|
|||
Val::MakeInt(i).release() : ints[i - PREALLOCATED_INT_LOWEST]->Ref();
|
||||
}
|
||||
|
||||
inline zeek::IntrusivePtr<Val> Int(int64_t i) const
|
||||
inline ValPtr Int(int64_t i) const
|
||||
{
|
||||
return i < PREALLOCATED_INT_LOWEST || i > PREALLOCATED_INT_HIGHEST ?
|
||||
Val::MakeInt(i) : ints[i - PREALLOCATED_INT_LOWEST];
|
||||
|
@ -441,7 +454,7 @@ public:
|
|||
return i >= PREALLOCATED_COUNTS ? Val::MakeCount(i).release() : counts[i]->Ref();
|
||||
}
|
||||
|
||||
inline zeek::IntrusivePtr<Val> Count(uint64_t i) const
|
||||
inline ValPtr Count(uint64_t i) const
|
||||
{
|
||||
return i >= PREALLOCATED_COUNTS ? Val::MakeCount(i) : counts[i];
|
||||
}
|
||||
|
@ -449,7 +462,7 @@ public:
|
|||
[[deprecated("Remove in v4.1. Use val_mgr->EmptyString() instead.")]]
|
||||
StringVal* GetEmptyString() const;
|
||||
|
||||
inline const zeek::IntrusivePtr<StringVal>& EmptyString() const
|
||||
inline const StringValPtr& EmptyString() const
|
||||
{ return empty_string; }
|
||||
|
||||
// Port number given in host order.
|
||||
|
@ -457,23 +470,23 @@ public:
|
|||
PortVal* GetPort(uint32_t port_num, TransportProto port_type) const;
|
||||
|
||||
// Port number given in host order.
|
||||
const zeek::IntrusivePtr<PortVal>& Port(uint32_t port_num, TransportProto port_type) const;
|
||||
const PortValPtr& Port(uint32_t port_num, TransportProto port_type) const;
|
||||
|
||||
// Host-order port number already masked with port space protocol mask.
|
||||
[[deprecated("Remove in v4.1. Use val_mgr->Port() instead.")]]
|
||||
PortVal* GetPort(uint32_t port_num) const;
|
||||
|
||||
// Host-order port number already masked with port space protocol mask.
|
||||
const zeek::IntrusivePtr<PortVal>& Port(uint32_t port_num) const;
|
||||
const PortValPtr& Port(uint32_t port_num) const;
|
||||
|
||||
private:
|
||||
|
||||
std::array<std::array<zeek::IntrusivePtr<PortVal>, 65536>, NUM_PORT_SPACES> ports;
|
||||
std::array<zeek::IntrusivePtr<Val>, PREALLOCATED_COUNTS> counts;
|
||||
std::array<zeek::IntrusivePtr<Val>, PREALLOCATED_INTS> ints;
|
||||
zeek::IntrusivePtr<StringVal> empty_string;
|
||||
zeek::IntrusivePtr<Val> b_true;
|
||||
zeek::IntrusivePtr<Val> b_false;
|
||||
std::array<std::array<PortValPtr, 65536>, NUM_PORT_SPACES> ports;
|
||||
std::array<ValPtr, PREALLOCATED_COUNTS> counts;
|
||||
std::array<ValPtr, PREALLOCATED_INTS> ints;
|
||||
StringValPtr empty_string;
|
||||
ValPtr b_true;
|
||||
ValPtr b_false;
|
||||
};
|
||||
|
||||
extern ValManager* val_mgr;
|
||||
|
@ -511,7 +524,7 @@ public:
|
|||
|
||||
class PortVal final : public Val {
|
||||
public:
|
||||
zeek::IntrusivePtr<Val> SizeVal() const override;
|
||||
ValPtr SizeVal() const override;
|
||||
|
||||
// Returns the port number in host order (not including the mask).
|
||||
uint32_t Port() const;
|
||||
|
@ -542,7 +555,7 @@ protected:
|
|||
PortVal(uint32_t p);
|
||||
|
||||
void ValDescribe(ODesc* d) const override;
|
||||
zeek::IntrusivePtr<Val> DoClone(CloneState* state) override;
|
||||
ValPtr DoClone(CloneState* state) override;
|
||||
};
|
||||
|
||||
class AddrVal final : public Val {
|
||||
|
@ -551,7 +564,7 @@ public:
|
|||
explicit AddrVal(const std::string& text);
|
||||
~AddrVal() override;
|
||||
|
||||
zeek::IntrusivePtr<Val> SizeVal() const override;
|
||||
ValPtr SizeVal() const override;
|
||||
|
||||
// Constructor for address already in network order.
|
||||
explicit AddrVal(uint32_t addr); // IPv4.
|
||||
|
@ -561,7 +574,7 @@ public:
|
|||
unsigned int MemoryAllocation() const override;
|
||||
|
||||
protected:
|
||||
zeek::IntrusivePtr<Val> DoClone(CloneState* state) override;
|
||||
ValPtr DoClone(CloneState* state) override;
|
||||
};
|
||||
|
||||
class SubNetVal final : public Val {
|
||||
|
@ -574,7 +587,7 @@ public:
|
|||
explicit SubNetVal(const IPPrefix& prefix);
|
||||
~SubNetVal() override;
|
||||
|
||||
zeek::IntrusivePtr<Val> SizeVal() const override;
|
||||
ValPtr SizeVal() const override;
|
||||
|
||||
const IPAddr& Prefix() const;
|
||||
int Width() const;
|
||||
|
@ -586,7 +599,7 @@ public:
|
|||
|
||||
protected:
|
||||
void ValDescribe(ODesc* d) const override;
|
||||
zeek::IntrusivePtr<Val> DoClone(CloneState* state) override;
|
||||
ValPtr DoClone(CloneState* state) override;
|
||||
};
|
||||
|
||||
class StringVal final : public Val {
|
||||
|
@ -596,7 +609,7 @@ public:
|
|||
explicit StringVal(const std::string& s);
|
||||
StringVal(int length, const char* s);
|
||||
|
||||
zeek::IntrusivePtr<Val> SizeVal() const override;
|
||||
ValPtr SizeVal() const override;
|
||||
|
||||
int Len();
|
||||
const u_char* Bytes();
|
||||
|
@ -612,7 +625,7 @@ public:
|
|||
|
||||
unsigned int MemoryAllocation() const override;
|
||||
|
||||
zeek::IntrusivePtr<StringVal> Replace(RE_Matcher* re, const BroString& repl,
|
||||
StringValPtr Replace(RE_Matcher* re, const BroString& repl,
|
||||
bool do_all);
|
||||
|
||||
[[deprecated("Remove in v4.1. Use Replace().")]]
|
||||
|
@ -621,7 +634,7 @@ public:
|
|||
|
||||
protected:
|
||||
void ValDescribe(ODesc* d) const override;
|
||||
zeek::IntrusivePtr<Val> DoClone(CloneState* state) override;
|
||||
ValPtr DoClone(CloneState* state) override;
|
||||
};
|
||||
|
||||
class PatternVal final : public Val {
|
||||
|
@ -637,7 +650,7 @@ public:
|
|||
|
||||
protected:
|
||||
void ValDescribe(ODesc* d) const override;
|
||||
zeek::IntrusivePtr<Val> DoClone(CloneState* state) override;
|
||||
ValPtr DoClone(CloneState* state) override;
|
||||
};
|
||||
|
||||
// ListVals are mainly used to index tables that have more than one
|
||||
|
@ -650,11 +663,11 @@ public:
|
|||
|
||||
zeek::TypeTag BaseTag() const { return tag; }
|
||||
|
||||
zeek::IntrusivePtr<Val> SizeVal() const override;
|
||||
ValPtr SizeVal() const override;
|
||||
|
||||
int Length() const { return vals.size(); }
|
||||
|
||||
const zeek::IntrusivePtr<Val>& Idx(size_t i) const { return vals[i]; }
|
||||
const ValPtr& Idx(size_t i) const { return vals[i]; }
|
||||
|
||||
[[deprecated("Remove in v4.1. Use Idx() instead")]]
|
||||
Val* Index(const int n) { return vals[n].get(); }
|
||||
|
@ -675,27 +688,27 @@ public:
|
|||
* Appends a value to the list.
|
||||
* @param v the value to append.
|
||||
*/
|
||||
void Append(zeek::IntrusivePtr<Val> v);
|
||||
void Append(ValPtr v);
|
||||
|
||||
[[deprecated("Remove in v4.1. Use Append(IntrusivePtr) instead.")]]
|
||||
void Append(Val* v);
|
||||
|
||||
// Returns a Set representation of the list (which must be homogeneous).
|
||||
zeek::IntrusivePtr<TableVal> ToSetVal() const;
|
||||
TableValPtr ToSetVal() const;
|
||||
|
||||
[[deprecated("Remove in v4.1. Use ToSetVal() instead.")]]
|
||||
TableVal* ConvertToSet() const;
|
||||
|
||||
const std::vector<zeek::IntrusivePtr<Val>>& Vals() const { return vals; }
|
||||
const std::vector<ValPtr>& Vals() const { return vals; }
|
||||
|
||||
void Describe(ODesc* d) const override;
|
||||
|
||||
unsigned int MemoryAllocation() const override;
|
||||
|
||||
protected:
|
||||
zeek::IntrusivePtr<Val> DoClone(CloneState* state) override;
|
||||
ValPtr DoClone(CloneState* state) override;
|
||||
|
||||
std::vector<zeek::IntrusivePtr<Val>> vals;
|
||||
std::vector<ValPtr> vals;
|
||||
zeek::TypeTag tag;
|
||||
};
|
||||
|
||||
|
@ -703,7 +716,7 @@ extern double bro_start_network_time;
|
|||
|
||||
class TableEntryVal {
|
||||
public:
|
||||
explicit TableEntryVal(zeek::IntrusivePtr<Val> v)
|
||||
explicit TableEntryVal(ValPtr v)
|
||||
: val(std::move(v))
|
||||
{
|
||||
expire_access_time =
|
||||
|
@ -715,7 +728,7 @@ public:
|
|||
[[deprecated("Remove in v4.1. Use GetVal().")]]
|
||||
Val* Value() { return val.get(); }
|
||||
|
||||
const zeek::IntrusivePtr<Val>& GetVal() const
|
||||
const ValPtr& GetVal() const
|
||||
{ return val; }
|
||||
|
||||
// Returns/sets time of last expiration relevant access to this value.
|
||||
|
@ -727,7 +740,7 @@ public:
|
|||
protected:
|
||||
friend class TableVal;
|
||||
|
||||
zeek::IntrusivePtr<Val> val;
|
||||
ValPtr val;
|
||||
|
||||
// The next entry stores seconds since Bro's start. We use ints here
|
||||
// to save a few bytes, as we do not need a high resolution for these
|
||||
|
@ -754,7 +767,7 @@ class Frame;
|
|||
|
||||
class TableVal final : public Val, public notifier::Modifiable {
|
||||
public:
|
||||
explicit TableVal(zeek::IntrusivePtr<zeek::TableType> t, zeek::IntrusivePtr<zeek::detail::Attributes> attrs = nullptr);
|
||||
explicit TableVal(zeek::TableTypePtr t, zeek::detail::AttributesPtr attrs = nullptr);
|
||||
|
||||
[[deprecated("Remove in v4.1. Construct from IntrusivePtrs instead.")]]
|
||||
explicit TableVal(zeek::TableType* t, zeek::detail::Attributes* attrs = nullptr)
|
||||
|
@ -771,7 +784,7 @@ public:
|
|||
* must be nullptr.
|
||||
* @return True if the assignment type-checked.
|
||||
*/
|
||||
bool Assign(zeek::IntrusivePtr<Val> index, zeek::IntrusivePtr<Val> new_val);
|
||||
bool Assign(ValPtr index, ValPtr new_val);
|
||||
|
||||
/**
|
||||
* Assigns a value at an associated index in the table (or in the
|
||||
|
@ -783,8 +796,8 @@ public:
|
|||
* must be nullptr.
|
||||
* @return True if the assignment type-checked.
|
||||
*/
|
||||
bool Assign(zeek::IntrusivePtr<Val> index, std::unique_ptr<HashKey> k,
|
||||
zeek::IntrusivePtr<Val> new_val);
|
||||
bool Assign(ValPtr index, std::unique_ptr<HashKey> k,
|
||||
ValPtr new_val);
|
||||
|
||||
// Returns true if the assignment typechecked, false if not. The
|
||||
// methods take ownership of new_val, but not of the index. If we're
|
||||
|
@ -797,7 +810,7 @@ public:
|
|||
[[deprecated("Remove in v4.1. Use IntrusivePtr overload instead.")]]
|
||||
bool Assign(Val* index, HashKey* k, Val* new_val);
|
||||
|
||||
zeek::IntrusivePtr<Val> SizeVal() const override;
|
||||
ValPtr SizeVal() const override;
|
||||
|
||||
// Add the entire contents of the table to the given value,
|
||||
// which must also be a TableVal.
|
||||
|
@ -825,7 +838,7 @@ public:
|
|||
* @param v The intersecting table.
|
||||
* @return The intersection of this table and the given one.
|
||||
*/
|
||||
zeek::IntrusivePtr<TableVal> Intersection(const TableVal& v) const;
|
||||
TableValPtr Intersection(const TableVal& v) const;
|
||||
|
||||
[[deprecated("Remove in v4.1. Use Intersection() instead.")]]
|
||||
TableVal* Intersect(const TableVal* v) const
|
||||
|
@ -851,7 +864,7 @@ public:
|
|||
|
||||
// Expands any lists in the index into multiple initializations.
|
||||
// Returns true if the initializations typecheck, false if not.
|
||||
bool ExpandAndInit(zeek::IntrusivePtr<Val> index, zeek::IntrusivePtr<Val> new_val);
|
||||
bool ExpandAndInit(ValPtr index, ValPtr new_val);
|
||||
|
||||
/**
|
||||
* Finds an index in the table and returns its associated value.
|
||||
|
@ -862,7 +875,7 @@ public:
|
|||
* non-existent index (nullptr), but otherwise has no meaning in relation
|
||||
* to the set's contents.
|
||||
*/
|
||||
const zeek::IntrusivePtr<Val>& Find(const zeek::IntrusivePtr<Val>& index);
|
||||
const ValPtr& Find(const ValPtr& index);
|
||||
|
||||
/**
|
||||
* Finds an index in the table and returns its associated value or else
|
||||
|
@ -872,7 +885,7 @@ public:
|
|||
* exist, instead returns the &default value. If there's no &default
|
||||
* attribute, then nullptr is still returned for non-existent index.
|
||||
*/
|
||||
zeek::IntrusivePtr<Val> FindOrDefault(const zeek::IntrusivePtr<Val>& index);
|
||||
ValPtr FindOrDefault(const ValPtr& index);
|
||||
|
||||
// Returns the element's value if it exists in the table,
|
||||
// nil otherwise. Note, "index" is not const because we
|
||||
|
@ -883,12 +896,12 @@ public:
|
|||
// For a table[subnet]/set[subnet], return all subnets that cover
|
||||
// the given subnet.
|
||||
// Causes an internal error if called for any other kind of table.
|
||||
zeek::IntrusivePtr<VectorVal> LookupSubnets(const SubNetVal* s);
|
||||
VectorValPtr LookupSubnets(const SubNetVal* s);
|
||||
|
||||
// For a set[subnet]/table[subnet], return a new table that only contains
|
||||
// entries that cover the given subnet.
|
||||
// Causes an internal error if called for any other kind of table.
|
||||
zeek::IntrusivePtr<TableVal> LookupSubnetValues(const SubNetVal* s);
|
||||
TableValPtr LookupSubnetValues(const SubNetVal* s);
|
||||
|
||||
// Sets the timestamp for the given index to network time.
|
||||
// Returns false if index does not exist.
|
||||
|
@ -897,7 +910,7 @@ public:
|
|||
/**
|
||||
* @return The index corresponding to the given HashKey.
|
||||
*/
|
||||
zeek::IntrusivePtr<ListVal> RecreateIndex(const HashKey& k) const;
|
||||
ListValPtr RecreateIndex(const HashKey& k) const;
|
||||
|
||||
[[deprecated("Remove in v4.1. Use RecreateIndex().")]]
|
||||
ListVal* RecoverIndex(const HashKey* k) const
|
||||
|
@ -911,14 +924,14 @@ public:
|
|||
* value is returned to differentiate it from non-existent index (nullptr),
|
||||
* but otherwise has no meaning in relation to the set's contents.
|
||||
*/
|
||||
zeek::IntrusivePtr<Val> Remove(const Val& index);
|
||||
ValPtr Remove(const Val& index);
|
||||
|
||||
/**
|
||||
* Same as Remove(const Val&), but uses a precomputed hash key.
|
||||
* @param k The hash key to lookup.
|
||||
* @return Same as Remove(const Val&).
|
||||
*/
|
||||
zeek::IntrusivePtr<Val> Remove(const HashKey& k);
|
||||
ValPtr Remove(const HashKey& k);
|
||||
|
||||
[[deprecated("Remove in v4.1. Use Remove().")]]
|
||||
Val* Delete(const Val* index)
|
||||
|
@ -929,25 +942,25 @@ public:
|
|||
{ return Remove(*k).release(); }
|
||||
|
||||
// Returns a ListVal representation of the table (which must be a set).
|
||||
zeek::IntrusivePtr<ListVal> ToListVal(zeek::TypeTag t = zeek::TYPE_ANY) const;
|
||||
ListValPtr ToListVal(zeek::TypeTag t = zeek::TYPE_ANY) const;
|
||||
|
||||
// Returns a ListVal representation of the table (which must be a set
|
||||
// with non-composite index type).
|
||||
zeek::IntrusivePtr<ListVal> ToPureListVal() const;
|
||||
ListValPtr ToPureListVal() const;
|
||||
|
||||
[[deprecated("Remove in v4.1. Use ToListVal() instead.")]]
|
||||
ListVal* ConvertToList(zeek::TypeTag t=zeek::TYPE_ANY) const;
|
||||
[[deprecated("Remove in v4.1. Use ToPureListVal() instead.")]]
|
||||
ListVal* ConvertToPureList() const; // must be single index type
|
||||
|
||||
void SetAttrs(zeek::IntrusivePtr<zeek::detail::Attributes> attrs);
|
||||
void SetAttrs(zeek::detail::AttributesPtr attrs);
|
||||
|
||||
const zeek::IntrusivePtr<zeek::detail::Attr>& GetAttr(zeek::detail::AttrTag t) const;
|
||||
const zeek::detail::AttrPtr& GetAttr(zeek::detail::AttrTag t) const;
|
||||
|
||||
[[deprecated("Remove in v4.1. Use GetAttrs().")]]
|
||||
zeek::detail::Attributes* Attrs() { return attrs.get(); }
|
||||
|
||||
const zeek::IntrusivePtr<zeek::detail::Attributes>& GetAttrs() const
|
||||
const zeek::detail::AttributesPtr& GetAttrs() const
|
||||
{ return attrs; }
|
||||
|
||||
// Returns the size of the table.
|
||||
|
@ -1003,22 +1016,22 @@ public:
|
|||
static void DoneParsing();
|
||||
|
||||
protected:
|
||||
void Init(zeek::IntrusivePtr<zeek::TableType> t);
|
||||
void Init(zeek::TableTypePtr t);
|
||||
|
||||
using TableRecordDependencies = std::unordered_map<zeek::RecordType*, std::vector<zeek::IntrusivePtr<TableVal>>>;
|
||||
using TableRecordDependencies = std::unordered_map<zeek::RecordType*, std::vector<TableValPtr>>;
|
||||
|
||||
using ParseTimeTableState = std::vector<std::pair<zeek::IntrusivePtr<Val>, zeek::IntrusivePtr<Val>>>;
|
||||
using ParseTimeTableState = std::vector<std::pair<ValPtr, ValPtr>>;
|
||||
using ParseTimeTableStates = std::unordered_map<TableVal*, ParseTimeTableState>;
|
||||
|
||||
ParseTimeTableState DumpTableState();
|
||||
void RebuildTable(ParseTimeTableState ptts);
|
||||
|
||||
void CheckExpireAttr(zeek::detail::AttrTag at);
|
||||
bool ExpandCompoundAndInit(ListVal* lv, int k, zeek::IntrusivePtr<Val> new_val);
|
||||
bool CheckAndAssign(zeek::IntrusivePtr<Val> index, zeek::IntrusivePtr<Val> new_val);
|
||||
bool ExpandCompoundAndInit(ListVal* lv, int k, ValPtr new_val);
|
||||
bool CheckAndAssign(ValPtr index, ValPtr new_val);
|
||||
|
||||
// Calculates default value for index. Returns nullptr if none.
|
||||
zeek::IntrusivePtr<Val> Default(const zeek::IntrusivePtr<Val>& index);
|
||||
ValPtr Default(const ValPtr& index);
|
||||
|
||||
// Returns true if item expiration is enabled.
|
||||
bool ExpirationEnabled() { return expire_time != nullptr; }
|
||||
|
@ -1029,27 +1042,27 @@ protected:
|
|||
double GetExpireTime();
|
||||
|
||||
// Calls &expire_func and returns its return interval;
|
||||
double CallExpireFunc(zeek::IntrusivePtr<ListVal> idx);
|
||||
double CallExpireFunc(ListValPtr idx);
|
||||
|
||||
// Enum for the different kinds of changes an &on_change handler can see
|
||||
enum OnChangeType { ELEMENT_NEW, ELEMENT_CHANGED, ELEMENT_REMOVED, ELEMENT_EXPIRED };
|
||||
|
||||
// Calls &change_func. Does not take ownership of values. (Refs if needed).
|
||||
void CallChangeFunc(const Val* index, const zeek::IntrusivePtr<Val>& old_value,
|
||||
void CallChangeFunc(const Val* index, const ValPtr& old_value,
|
||||
OnChangeType tpe);
|
||||
|
||||
zeek::IntrusivePtr<Val> DoClone(CloneState* state) override;
|
||||
ValPtr DoClone(CloneState* state) override;
|
||||
|
||||
zeek::IntrusivePtr<zeek::TableType> table_type;
|
||||
zeek::TableTypePtr table_type;
|
||||
CompositeHash* table_hash;
|
||||
zeek::IntrusivePtr<zeek::detail::Attributes> attrs;
|
||||
zeek::IntrusivePtr<zeek::detail::Expr> expire_time;
|
||||
zeek::IntrusivePtr<zeek::detail::Expr> expire_func;
|
||||
zeek::detail::AttributesPtr attrs;
|
||||
zeek::detail::ExprPtr expire_time;
|
||||
zeek::detail::ExprPtr expire_func;
|
||||
TableValTimer* timer;
|
||||
IterCookie* expire_cookie;
|
||||
PrefixTable* subnets;
|
||||
zeek::IntrusivePtr<Val> def_val;
|
||||
zeek::IntrusivePtr<zeek::detail::Expr> change_func;
|
||||
ValPtr def_val;
|
||||
zeek::detail::ExprPtr change_func;
|
||||
// prevent recursion of change functions
|
||||
bool in_change_func = false;
|
||||
|
||||
|
@ -1061,18 +1074,18 @@ class RecordVal final : public Val, public notifier::Modifiable {
|
|||
public:
|
||||
[[deprecated("Remove in v4.1. Construct from IntrusivePtr instead.")]]
|
||||
explicit RecordVal(zeek::RecordType* t, bool init_fields = true);
|
||||
explicit RecordVal(zeek::IntrusivePtr<zeek::RecordType> t, bool init_fields = true);
|
||||
explicit RecordVal(zeek::RecordTypePtr t, bool init_fields = true);
|
||||
|
||||
~RecordVal() override;
|
||||
|
||||
zeek::IntrusivePtr<Val> SizeVal() const override;
|
||||
ValPtr SizeVal() const override;
|
||||
|
||||
/**
|
||||
* Assign a value to a record field.
|
||||
* @param field The field index to assign.
|
||||
* @param new_val The value to assign.
|
||||
*/
|
||||
void Assign(int field, zeek::IntrusivePtr<Val> new_val);
|
||||
void Assign(int field, ValPtr new_val);
|
||||
|
||||
/**
|
||||
* Assign a value of type @c T to a record field, as constructed from
|
||||
|
@ -1089,7 +1102,7 @@ public:
|
|||
void Assign(int field, Val* new_val);
|
||||
// Note: the following nullptr method can also go upon removing the above.
|
||||
void Assign(int field, std::nullptr_t)
|
||||
{ Assign(field, zeek::IntrusivePtr<Val>{}); }
|
||||
{ Assign(field, ValPtr{}); }
|
||||
|
||||
[[deprecated("Remove in v4.1. Use GetField().")]]
|
||||
Val* Lookup(int field) const // Does not Ref() value.
|
||||
|
@ -1100,7 +1113,7 @@ public:
|
|||
* @param field The field index to retrieve.
|
||||
* @return The value at the given field index.
|
||||
*/
|
||||
const zeek::IntrusivePtr<Val>& GetField(int field) const
|
||||
const ValPtr& GetField(int field) const
|
||||
{ return (*AsRecord())[field]; }
|
||||
|
||||
/**
|
||||
|
@ -1120,7 +1133,7 @@ public:
|
|||
* @return The value at the given field index or the default value if
|
||||
* the field hasn't been assigned yet.
|
||||
*/
|
||||
zeek::IntrusivePtr<Val> GetFieldOrDefault(int field) const;
|
||||
ValPtr GetFieldOrDefault(int field) const;
|
||||
|
||||
[[deprecated("Remove in v4.1. Use GetFieldOrDefault().")]]
|
||||
Val* LookupWithDefault(int field) const
|
||||
|
@ -1132,7 +1145,7 @@ public:
|
|||
* @return The value of the given field. If no such field name exists,
|
||||
* a fatal error occurs.
|
||||
*/
|
||||
const zeek::IntrusivePtr<Val>& GetField(const char* field) const;
|
||||
const ValPtr& GetField(const char* field) const;
|
||||
|
||||
/**
|
||||
* Returns the value of a given field name as cast to type @c T.
|
||||
|
@ -1153,7 +1166,7 @@ public:
|
|||
* if the field hasn't been assigned yet. If no such field name exists,
|
||||
* a fatal error occurs.
|
||||
*/
|
||||
zeek::IntrusivePtr<Val> GetFieldOrDefault(const char* field) const;
|
||||
ValPtr GetFieldOrDefault(const char* field) const;
|
||||
|
||||
/**
|
||||
* Returns the value of a given field name or its default value
|
||||
|
@ -1183,7 +1196,7 @@ public:
|
|||
/**
|
||||
* Returns a "record_field_table" value for introspection purposes.
|
||||
*/
|
||||
zeek::IntrusivePtr<TableVal> GetRecordFieldsVal() const;
|
||||
TableValPtr GetRecordFieldsVal() const;
|
||||
|
||||
// This is an experiment to associate a BroObj within the
|
||||
// event engine to a record value in bro script.
|
||||
|
@ -1201,13 +1214,11 @@ public:
|
|||
//
|
||||
// The *allow_orphaning* parameter allows for a record to be demoted
|
||||
// down to a record type that contains less fields.
|
||||
zeek::IntrusivePtr<RecordVal> CoerceTo(
|
||||
zeek::IntrusivePtr<zeek::RecordType> other,
|
||||
zeek::IntrusivePtr<RecordVal> aggr,
|
||||
bool allow_orphaning = false) const;
|
||||
zeek::IntrusivePtr<RecordVal> CoerceTo(
|
||||
zeek::IntrusivePtr<zeek::RecordType> other,
|
||||
bool allow_orphaning = false);
|
||||
RecordValPtr CoerceTo(zeek::RecordTypePtr other,
|
||||
RecordValPtr aggr,
|
||||
bool allow_orphaning = false) const;
|
||||
RecordValPtr CoerceTo(zeek::RecordTypePtr other,
|
||||
bool allow_orphaning = false);
|
||||
|
||||
unsigned int MemoryAllocation() const override;
|
||||
void DescribeReST(ODesc* d) const override;
|
||||
|
@ -1222,17 +1233,17 @@ public:
|
|||
static void DoneParsing();
|
||||
|
||||
protected:
|
||||
zeek::IntrusivePtr<Val> DoClone(CloneState* state) override;
|
||||
ValPtr DoClone(CloneState* state) override;
|
||||
|
||||
BroObj* origin;
|
||||
|
||||
using RecordTypeValMap = std::unordered_map<zeek::RecordType*, std::vector<zeek::IntrusivePtr<RecordVal>>>;
|
||||
using RecordTypeValMap = std::unordered_map<zeek::RecordType*, std::vector<RecordValPtr>>;
|
||||
static RecordTypeValMap parse_time_records;
|
||||
};
|
||||
|
||||
class EnumVal final : public Val {
|
||||
public:
|
||||
zeek::IntrusivePtr<Val> SizeVal() const override;
|
||||
ValPtr SizeVal() const override;
|
||||
|
||||
protected:
|
||||
friend class Val;
|
||||
|
@ -1241,11 +1252,11 @@ protected:
|
|||
template<class T, class... Ts>
|
||||
friend zeek::IntrusivePtr<T> zeek::make_intrusive(Ts&&... args);
|
||||
|
||||
EnumVal(zeek::IntrusivePtr<zeek::EnumType> t, int i) : Val(bro_int_t(i), std::move(t))
|
||||
EnumVal(zeek::EnumTypePtr t, int i) : Val(bro_int_t(i), std::move(t))
|
||||
{}
|
||||
|
||||
void ValDescribe(ODesc* d) const override;
|
||||
zeek::IntrusivePtr<Val> DoClone(CloneState* state) override;
|
||||
ValPtr DoClone(CloneState* state) override;
|
||||
};
|
||||
|
||||
|
||||
|
@ -1253,10 +1264,10 @@ class VectorVal final : public Val, public notifier::Modifiable {
|
|||
public:
|
||||
[[deprecated("Remove in v4.1. Construct from IntrusivePtr instead.")]]
|
||||
explicit VectorVal(zeek::VectorType* t);
|
||||
explicit VectorVal(zeek::IntrusivePtr<zeek::VectorType> t);
|
||||
explicit VectorVal(zeek::VectorTypePtr t);
|
||||
~VectorVal() override;
|
||||
|
||||
zeek::IntrusivePtr<Val> SizeVal() const override;
|
||||
ValPtr SizeVal() const override;
|
||||
|
||||
/**
|
||||
* Assigns an element to a given vector index.
|
||||
|
@ -1265,7 +1276,7 @@ public:
|
|||
* @return True if the element was successfully assigned, or false if
|
||||
* the element was the wrong type.
|
||||
*/
|
||||
bool Assign(unsigned int index, zeek::IntrusivePtr<Val> element);
|
||||
bool Assign(unsigned int index, ValPtr element);
|
||||
|
||||
// Note: does NOT Ref() the element! Remember to do so unless
|
||||
// the element was just created and thus has refcount 1.
|
||||
|
@ -1274,7 +1285,7 @@ public:
|
|||
{ return Assign(index, {zeek::AdoptRef{}, element}); }
|
||||
// Note: the following nullptr method can also go upon removing the above.
|
||||
void Assign(unsigned int index, std::nullptr_t)
|
||||
{ Assign(index, zeek::IntrusivePtr<Val>{}); }
|
||||
{ Assign(index, ValPtr{}); }
|
||||
|
||||
[[deprecated("Remove in v4.1. Assign using integer index and IntrusivePtr element.")]]
|
||||
bool Assign(Val* index, Val* element)
|
||||
|
@ -1291,7 +1302,7 @@ public:
|
|||
* the element was the wrong type.
|
||||
*/
|
||||
bool AssignRepeat(unsigned int index, unsigned int how_many,
|
||||
zeek::IntrusivePtr<Val> element);
|
||||
ValPtr element);
|
||||
|
||||
[[deprecated("Remove in v4.1. Assign an IntrusivePtr instead.")]]
|
||||
bool AssignRepeat(unsigned int index, unsigned int how_many, Val* element)
|
||||
|
@ -1307,7 +1318,7 @@ public:
|
|||
* @return The element at the given index or nullptr if the index
|
||||
* does not exist (it's greater than or equal to vector's current size).
|
||||
*/
|
||||
const zeek::IntrusivePtr<Val>& At(unsigned int index) const;
|
||||
const ValPtr& At(unsigned int index) const;
|
||||
|
||||
[[deprecated("Remove in v4.1. Use At().")]]
|
||||
Val* Lookup(unsigned int index) const
|
||||
|
@ -1339,7 +1350,7 @@ public:
|
|||
* @return True if the element was inserted or false if the element was
|
||||
* the wrong type.
|
||||
*/
|
||||
bool Insert(unsigned int index, zeek::IntrusivePtr<Val> element);
|
||||
bool Insert(unsigned int index, ValPtr element);
|
||||
|
||||
[[deprecated("Remove in v4.1. Insert an IntrusivePtr instead.")]]
|
||||
bool Insert(unsigned int index, Val* element)
|
||||
|
@ -1350,33 +1361,33 @@ public:
|
|||
|
||||
protected:
|
||||
void ValDescribe(ODesc* d) const override;
|
||||
zeek::IntrusivePtr<Val> DoClone(CloneState* state) override;
|
||||
ValPtr DoClone(CloneState* state) override;
|
||||
};
|
||||
|
||||
// Checks the given value for consistency with the given type. If an
|
||||
// exact match, returns it. If promotable, returns the promoted version.
|
||||
// If not a match, generates an error message and return nil. If is_init is
|
||||
// true, then the checking is done in the context of an initialization.
|
||||
extern zeek::IntrusivePtr<Val> check_and_promote(
|
||||
zeek::IntrusivePtr<Val> v, const zeek::Type* t, bool is_init,
|
||||
extern ValPtr check_and_promote(
|
||||
ValPtr v, const zeek::Type* t, bool is_init,
|
||||
const Location* expr_location = nullptr);
|
||||
|
||||
extern bool same_val(const Val* v1, const Val* v2);
|
||||
extern bool same_atomic_val(const Val* v1, const Val* v2);
|
||||
extern bool is_atomic_val(const Val* v);
|
||||
extern void describe_vals(const val_list* vals, ODesc* d, int offset=0);
|
||||
extern void describe_vals(const std::vector<zeek::IntrusivePtr<Val>>& vals,
|
||||
extern void describe_vals(const std::vector<ValPtr>& vals,
|
||||
ODesc* d, size_t offset = 0);
|
||||
extern void delete_vals(val_list* vals);
|
||||
|
||||
// True if the given Val* has a vector type.
|
||||
inline bool is_vector(Val* v) { return v->GetType()->Tag() == zeek::TYPE_VECTOR; }
|
||||
inline bool is_vector(const zeek::IntrusivePtr<Val>& v) { return is_vector(v.get()); }
|
||||
inline bool is_vector(const ValPtr& v) { return is_vector(v.get()); }
|
||||
|
||||
// Returns v casted to type T if the type supports that. Returns null if not.
|
||||
//
|
||||
// Note: This implements the script-level cast operator.
|
||||
extern zeek::IntrusivePtr<Val> cast_value_to_type(Val* v, zeek::Type* t);
|
||||
extern ValPtr cast_value_to_type(Val* v, zeek::Type* t);
|
||||
|
||||
// Returns true if v can be casted to type T. If so, check_and_cast() will
|
||||
// succeed as well.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue