mirror of
https://github.com/zeek/zeek.git
synced 2025-10-06 00:28:21 +00:00
Unify all of the Tag types into one type
- Remove tag types for each component type (analyzer, etc) - Add deprecated versions of the old types - Remove unnecessary tag element from templates for TaggedComponent and ComponentManager - Enable TaggedComponent to pass an EnumType when initializing Tag objects - Update some tests that are affected by the tag enum values changing order
This commit is contained in:
parent
4f9f46a0c4
commit
331161138a
46 changed files with 352 additions and 955 deletions
|
@ -7,6 +7,7 @@
|
|||
#include "zeek/DebugLogger.h"
|
||||
#include "zeek/Reporter.h"
|
||||
#include "zeek/Scope.h"
|
||||
#include "zeek/Tag.h"
|
||||
#include "zeek/Type.h"
|
||||
#include "zeek/Val.h"
|
||||
#include "zeek/Var.h" // for add_type()
|
||||
|
@ -20,10 +21,9 @@ namespace zeek::plugin
|
|||
* installs identifiers in the script-layer to identify them by a unique tag,
|
||||
* (a script-layer enum value).
|
||||
*
|
||||
* @tparam T A ::Tag type or derivative.
|
||||
* @tparam C A plugin::TaggedComponent type derivative.
|
||||
*/
|
||||
template <class T, class C> class ComponentManager
|
||||
template <class C> class ComponentManager
|
||||
{
|
||||
public:
|
||||
/**
|
||||
|
@ -59,7 +59,7 @@ public:
|
|||
* @param tag A component's tag.
|
||||
* @return The canonical component name.
|
||||
*/
|
||||
const std::string& GetComponentName(T tag) const;
|
||||
const std::string& GetComponentName(zeek::Tag tag) const;
|
||||
|
||||
/**
|
||||
* Get a component name from it's enum value.
|
||||
|
@ -76,7 +76,7 @@ public:
|
|||
* @return The component's tag, or a tag representing an error if
|
||||
* no such component assoicated with the name exists.
|
||||
*/
|
||||
T GetComponentTag(const std::string& name) const;
|
||||
zeek::Tag GetComponentTag(const std::string& name) const;
|
||||
|
||||
/**
|
||||
* Get a component tag from its enum value.
|
||||
|
@ -85,7 +85,7 @@ public:
|
|||
* @return The component's tag, or a tag representing an error if
|
||||
* no such component assoicated with the value exists.
|
||||
*/
|
||||
T GetComponentTag(Val* v) const;
|
||||
zeek::Tag GetComponentTag(Val* v) const;
|
||||
|
||||
/**
|
||||
* Add a component the internal maps used to keep track of it and create
|
||||
|
@ -110,7 +110,7 @@ public:
|
|||
* @return The component associated with the tag or a null pointer if no
|
||||
* such component exists.
|
||||
*/
|
||||
C* Lookup(const T& tag) const;
|
||||
C* Lookup(const zeek::Tag& tag) const;
|
||||
|
||||
/**
|
||||
* @param name A component's enum value.
|
||||
|
@ -123,12 +123,12 @@ private:
|
|||
std::string module; /**< Script layer module in which component tags live. */
|
||||
EnumTypePtr tag_enum_type; /**< Enum type of component tags. */
|
||||
std::map<std::string, C*> components_by_name;
|
||||
std::map<T, C*> components_by_tag;
|
||||
std::map<zeek::Tag, C*> components_by_tag;
|
||||
std::map<int, C*> components_by_val;
|
||||
};
|
||||
|
||||
template <class T, class C>
|
||||
ComponentManager<T, C>::ComponentManager(const std::string& arg_module, const std::string& local_id)
|
||||
template <class C>
|
||||
ComponentManager<C>::ComponentManager(const std::string& arg_module, const std::string& local_id)
|
||||
: module(arg_module), tag_enum_type(make_intrusive<EnumType>(module + "::" + local_id))
|
||||
{
|
||||
auto id = zeek::detail::install_ID(local_id.c_str(), module.c_str(), true, true);
|
||||
|
@ -136,15 +136,15 @@ ComponentManager<T, C>::ComponentManager(const std::string& arg_module, const st
|
|||
zeek::detail::zeekygen_mgr->Identifier(std::move(id));
|
||||
}
|
||||
|
||||
template <class T, class C> const std::string& ComponentManager<T, C>::GetModule() const
|
||||
template <class C> const std::string& ComponentManager<C>::GetModule() const
|
||||
{
|
||||
return module;
|
||||
}
|
||||
|
||||
template <class T, class C> std::list<C*> ComponentManager<T, C>::GetComponents() const
|
||||
template <class C> std::list<C*> ComponentManager<C>::GetComponents() const
|
||||
{
|
||||
std::list<C*> rval;
|
||||
typename std::map<T, C*>::const_iterator i;
|
||||
typename std::map<zeek::Tag, C*>::const_iterator i;
|
||||
|
||||
for ( i = components_by_tag.begin(); i != components_by_tag.end(); ++i )
|
||||
rval.push_back(i->second);
|
||||
|
@ -152,12 +152,12 @@ template <class T, class C> std::list<C*> ComponentManager<T, C>::GetComponents(
|
|||
return rval;
|
||||
}
|
||||
|
||||
template <class T, class C> const EnumTypePtr& ComponentManager<T, C>::GetTagType() const
|
||||
template <class C> const EnumTypePtr& ComponentManager<C>::GetTagType() const
|
||||
{
|
||||
return tag_enum_type;
|
||||
}
|
||||
|
||||
template <class T, class C> const std::string& ComponentManager<T, C>::GetComponentName(T tag) const
|
||||
template <class C> const std::string& ComponentManager<C>::GetComponentName(zeek::Tag tag) const
|
||||
{
|
||||
static const std::string error = "<error>";
|
||||
|
||||
|
@ -173,45 +173,44 @@ template <class T, class C> const std::string& ComponentManager<T, C>::GetCompon
|
|||
return error;
|
||||
}
|
||||
|
||||
template <class T, class C>
|
||||
const std::string& ComponentManager<T, C>::GetComponentName(EnumValPtr val) const
|
||||
template <class C> const std::string& ComponentManager<C>::GetComponentName(EnumValPtr val) const
|
||||
{
|
||||
return GetComponentName(T(std::move(val)));
|
||||
return GetComponentName(zeek::Tag(std::move(val)));
|
||||
}
|
||||
|
||||
template <class T, class C> T ComponentManager<T, C>::GetComponentTag(const std::string& name) const
|
||||
template <class C> zeek::Tag ComponentManager<C>::GetComponentTag(const std::string& name) const
|
||||
{
|
||||
C* c = Lookup(name);
|
||||
return c ? c->Tag() : T();
|
||||
return c ? c->Tag() : zeek::Tag();
|
||||
}
|
||||
|
||||
template <class T, class C> T ComponentManager<T, C>::GetComponentTag(Val* v) const
|
||||
template <class C> zeek::Tag ComponentManager<C>::GetComponentTag(Val* v) const
|
||||
{
|
||||
C* c = Lookup(v->AsEnumVal());
|
||||
return c ? c->Tag() : T();
|
||||
return c ? c->Tag() : zeek::Tag();
|
||||
}
|
||||
|
||||
template <class T, class C> C* ComponentManager<T, C>::Lookup(const std::string& name) const
|
||||
template <class C> C* ComponentManager<C>::Lookup(const std::string& name) const
|
||||
{
|
||||
typename std::map<std::string, C*>::const_iterator i = components_by_name.find(
|
||||
util::to_upper(name));
|
||||
return i != components_by_name.end() ? i->second : 0;
|
||||
}
|
||||
|
||||
template <class T, class C> C* ComponentManager<T, C>::Lookup(const T& tag) const
|
||||
template <class C> C* ComponentManager<C>::Lookup(const zeek::Tag& tag) const
|
||||
{
|
||||
typename std::map<T, C*>::const_iterator i = components_by_tag.find(tag);
|
||||
typename std::map<zeek::Tag, C*>::const_iterator i = components_by_tag.find(tag);
|
||||
return i != components_by_tag.end() ? i->second : 0;
|
||||
}
|
||||
|
||||
template <class T, class C> C* ComponentManager<T, C>::Lookup(EnumVal* val) const
|
||||
template <class C> C* ComponentManager<C>::Lookup(EnumVal* val) const
|
||||
{
|
||||
typename std::map<int, C*>::const_iterator i = components_by_val.find(val->InternalInt());
|
||||
return i != components_by_val.end() ? i->second : 0;
|
||||
}
|
||||
|
||||
template <class T, class C>
|
||||
void ComponentManager<T, C>::RegisterComponent(C* component, const std::string& prefix)
|
||||
template <class C>
|
||||
void ComponentManager<C>::RegisterComponent(C* component, const std::string& prefix)
|
||||
{
|
||||
std::string cname = component->CanonicalName();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue