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

@ -8,25 +8,16 @@
namespace zeek::plugin
{
Component::Component(component::Type arg_type, const std::string& arg_name)
Tag::type_t Component::type_counter(0);
Component::Component(component::Type arg_type, const std::string& arg_name,
Tag::subtype_t tag_subtype, zeek::EnumTypePtr etype)
: type(arg_type), name(arg_name), tag(etype, 1, 0), etype(std::move(etype)),
tag_subtype(tag_subtype)
{
type = arg_type;
name = arg_name;
canon_name = util::canonify_name(name);
}
Component::~Component() { }
const std::string& Component::Name() const
{
return name;
}
component::Type Component::Type() const
{
return type;
}
void Component::Describe(ODesc* d) const
{
d->Add(" ");
@ -84,4 +75,20 @@ void Component::Describe(ODesc* d) const
d->Add(")");
}
void Component::InitializeTag()
{
assert(tag_initialized == false);
tag_initialized = true;
tag = zeek::Tag(etype, ++type_counter, tag_subtype);
}
/**
* @return The component's tag.
*/
zeek::Tag Component::Tag() const
{
assert(tag_initialized);
return tag;
}
} // namespace zeek::plugin