mirror of
https://github.com/zeek/zeek.git
synced 2025-10-16 21:48:21 +00:00
Migrate Tag classes to use IntrusivePtr
Deprecates various methods that previously took raw pointers
This commit is contained in:
parent
b096e552d3
commit
1abed4fd4c
20 changed files with 174 additions and 85 deletions
45
src/Tag.cc
45
src/Tag.cc
|
@ -4,37 +4,40 @@
|
|||
#include "Val.h"
|
||||
#include "IntrusivePtr.h"
|
||||
|
||||
Tag::Tag(EnumType* etype, type_t arg_type, subtype_t arg_subtype)
|
||||
Tag::Tag(const IntrusivePtr<EnumType>& etype, type_t arg_type, subtype_t arg_subtype)
|
||||
{
|
||||
assert(arg_type > 0);
|
||||
|
||||
type = arg_type;
|
||||
subtype = arg_subtype;
|
||||
int64_t i = (int64_t)(type) | ((int64_t)subtype << 31);
|
||||
Ref(etype);
|
||||
val = etype->GetVal(i).release();
|
||||
val = etype->GetVal(i);
|
||||
}
|
||||
|
||||
Tag::Tag(EnumVal* arg_val)
|
||||
Tag::Tag(EnumType* etype, type_t arg_type, subtype_t arg_subtype)
|
||||
: Tag({NewRef{}, etype}, arg_type, arg_subtype)
|
||||
{ }
|
||||
|
||||
Tag::Tag(IntrusivePtr<EnumVal> arg_val)
|
||||
{
|
||||
assert(arg_val);
|
||||
|
||||
val = arg_val;
|
||||
Ref(val);
|
||||
val = std::move(arg_val);
|
||||
|
||||
int64_t i = val->InternalInt();
|
||||
type = i & 0xffffffff;
|
||||
subtype = (i >> 31) & 0xffffffff;
|
||||
}
|
||||
|
||||
Tag::Tag(EnumVal* arg_val)
|
||||
: Tag({NewRef{}, arg_val})
|
||||
{ }
|
||||
|
||||
Tag::Tag(const Tag& other)
|
||||
{
|
||||
type = other.type;
|
||||
subtype = other.subtype;
|
||||
val = other.val;
|
||||
|
||||
if ( val )
|
||||
Ref(val);
|
||||
}
|
||||
|
||||
Tag::Tag()
|
||||
|
@ -44,11 +47,7 @@ Tag::Tag()
|
|||
val = nullptr;
|
||||
}
|
||||
|
||||
Tag::~Tag()
|
||||
{
|
||||
Unref(val);
|
||||
val = nullptr;
|
||||
}
|
||||
Tag::~Tag() = default;
|
||||
|
||||
Tag& Tag::operator=(const Tag& other)
|
||||
{
|
||||
|
@ -56,11 +55,7 @@ Tag& Tag::operator=(const Tag& other)
|
|||
{
|
||||
type = other.type;
|
||||
subtype = other.subtype;
|
||||
Unref(val);
|
||||
val = other.val;
|
||||
|
||||
if ( val )
|
||||
Ref(val);
|
||||
}
|
||||
|
||||
return *this;
|
||||
|
@ -72,26 +67,28 @@ Tag& Tag::operator=(const Tag&& other) noexcept
|
|||
{
|
||||
type = other.type;
|
||||
subtype = other.subtype;
|
||||
Unref(val);
|
||||
val = other.val;
|
||||
other.val = nullptr;
|
||||
val = std::move(other.val);
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
EnumVal* Tag::AsEnumVal(EnumType* etype) const
|
||||
const IntrusivePtr<EnumVal>& Tag::AsVal(const IntrusivePtr<EnumType>& etype) const
|
||||
{
|
||||
if ( ! val )
|
||||
{
|
||||
assert(type == 0 && subtype == 0);
|
||||
Ref(etype);
|
||||
val = etype->GetVal(0).release();
|
||||
val = etype->GetVal(0);
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
EnumVal* Tag::AsEnumVal(EnumType* etype) const
|
||||
{
|
||||
return AsVal({NewRef{}, etype}).get();
|
||||
}
|
||||
|
||||
std::string Tag::AsString() const
|
||||
{
|
||||
return fmt("%" PRIu32 "/%" PRIu32, type, subtype);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue