Unify plugin::Component and plugin::TaggedComponent into a single class

These two are almost always used in conjunction with each other, and
TaggedComponent is never used by itself. Combining them together into
a single class will help simplify some of the code around managing
the mapping between Tags and Components.
This commit is contained in:
Tim Wojtulewicz 2021-09-30 13:34:42 -07:00
parent 8b544d648d
commit 7d66f4252f
18 changed files with 90 additions and 158 deletions

View file

@ -17,7 +17,9 @@ Tag::Tag(const EnumTypePtr& etype, type_t arg_type, subtype_t arg_subtype)
assert(arg_type > 0);
int64_t i = (int64_t)(type) | ((int64_t)subtype << 31);
val = etype->GetEnumVal(i);
if ( etype )
val = etype->GetEnumVal(i);
}
Tag::Tag(EnumValPtr arg_val)
@ -36,13 +38,13 @@ Tag::Tag(const Tag& other)
type = other.type;
subtype = other.subtype;
val = other.val;
etype = other.etype;
}
Tag::Tag()
{
type = 0;
subtype = 0;
val = nullptr;
etype = nullptr;
}
Tag::~Tag() = default;
@ -54,6 +56,7 @@ Tag& Tag::operator=(const Tag& other)
type = other.type;
subtype = other.subtype;
val = other.val;
etype = other.etype;
}
return *this;
@ -66,24 +69,12 @@ Tag& Tag::operator=(const Tag&& other) noexcept
type = other.type;
subtype = other.subtype;
val = std::move(other.val);
etype = std::move(other.etype);
}
return *this;
}
const EnumValPtr& Tag::AsVal() const
{
// TODO: this probably isn't valid, and we should just return the null val
// if it's null.
if ( ! val )
{
assert(type == 0 && subtype == 0 && etype != nullptr);
val = etype->GetEnumVal(0);
}
return val;
}
std::string Tag::AsString() const
{
return util::fmt("%" PRIu32 "/%" PRIu32, type, subtype);