mirror of
https://github.com/zeek/zeek.git
synced 2025-10-08 09:38:19 +00:00
Type: use class IntrusivePtr in EnumType
This commit is contained in:
parent
7704d52d28
commit
cc8af19bf9
3 changed files with 11 additions and 25 deletions
24
src/Type.cc
24
src/Type.cc
|
@ -1058,18 +1058,10 @@ EnumType::EnumType(const string& name)
|
|||
}
|
||||
|
||||
EnumType::EnumType(const EnumType* e)
|
||||
: BroType(TYPE_ENUM)
|
||||
: BroType(TYPE_ENUM), names(e->names), vals(e->vals)
|
||||
{
|
||||
counter = e->counter;
|
||||
SetName(e->GetName());
|
||||
|
||||
for ( auto it = e->names.begin(); it != e->names.end(); ++it )
|
||||
names[it->first] = it->second;
|
||||
|
||||
vals = e->vals;
|
||||
|
||||
for ( auto& kv : vals )
|
||||
::Ref(kv.second);
|
||||
}
|
||||
|
||||
EnumType* EnumType::ShallowClone()
|
||||
|
@ -1080,11 +1072,7 @@ EnumType* EnumType::ShallowClone()
|
|||
return new EnumType(this);
|
||||
}
|
||||
|
||||
EnumType::~EnumType()
|
||||
{
|
||||
for ( auto& kv : vals )
|
||||
Unref(kv.second);
|
||||
}
|
||||
EnumType::~EnumType() = default;
|
||||
|
||||
// Note, we use reporter->Error() here (not Error()) to include the current script
|
||||
// location in the error message, rather than the one where the type was
|
||||
|
@ -1157,7 +1145,7 @@ void EnumType::CheckAndAddName(const string& module_name, const char* name,
|
|||
AddNameInternal(module_name, name, val, is_export);
|
||||
|
||||
if ( vals.find(val) == vals.end() )
|
||||
vals[val] = new EnumVal(this, val);
|
||||
vals[val] = make_intrusive<EnumVal>(this, val);
|
||||
|
||||
set<BroType*> types = BroType::GetAliases(GetName());
|
||||
set<BroType*>::const_iterator it;
|
||||
|
@ -1209,17 +1197,17 @@ EnumType::enum_name_list EnumType::Names() const
|
|||
IntrusivePtr<EnumVal> EnumType::GetVal(bro_int_t i)
|
||||
{
|
||||
auto it = vals.find(i);
|
||||
EnumVal* rval;
|
||||
IntrusivePtr<EnumVal> rval;
|
||||
|
||||
if ( it == vals.end() )
|
||||
{
|
||||
rval = new EnumVal(this, i);
|
||||
rval = make_intrusive<EnumVal>(this, i);
|
||||
vals[i] = rval;
|
||||
}
|
||||
else
|
||||
rval = it->second;
|
||||
|
||||
return {NewRef{}, rval};
|
||||
return rval;
|
||||
}
|
||||
|
||||
void EnumType::DescribeReST(ODesc* d, bool roles_only) const
|
||||
|
|
|
@ -627,8 +627,6 @@ public:
|
|||
IntrusivePtr<EnumVal> GetVal(bro_int_t i);
|
||||
|
||||
protected:
|
||||
EnumType() { counter = 0; }
|
||||
|
||||
void AddNameInternal(const std::string& module_name,
|
||||
const char* name, bro_int_t val, bool is_export);
|
||||
|
||||
|
@ -639,7 +637,7 @@ protected:
|
|||
typedef std::map<std::string, bro_int_t> NameMap;
|
||||
NameMap names;
|
||||
|
||||
using ValMap = std::unordered_map<bro_int_t, EnumVal*>;
|
||||
using ValMap = std::unordered_map<bro_int_t, IntrusivePtr<EnumVal>>;
|
||||
ValMap vals;
|
||||
|
||||
// The counter is initialized to 0 and incremented on every implicit
|
||||
|
|
|
@ -924,16 +924,16 @@ protected:
|
|||
|
||||
class EnumVal : public Val {
|
||||
public:
|
||||
EnumVal(EnumType* t, int i) : Val(bro_int_t(i), t)
|
||||
{
|
||||
}
|
||||
|
||||
IntrusivePtr<Val> SizeVal() const override;
|
||||
|
||||
protected:
|
||||
friend class Val;
|
||||
friend class EnumType;
|
||||
|
||||
EnumVal(EnumType* t, int i) : Val(bro_int_t(i), t)
|
||||
{
|
||||
}
|
||||
|
||||
void ValDescribe(ODesc* d) const override;
|
||||
IntrusivePtr<Val> DoClone(CloneState* state) override;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue