mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
Cleanup of plugin component API.
- Move more functionality into base class. - Remove cctors and assignment operators (weren't actually needed anymore) - Switch from const char* to std::string.
This commit is contained in:
parent
e9413c9361
commit
987452beff
18 changed files with 114 additions and 216 deletions
|
@ -37,7 +37,7 @@ public:
|
|||
/**
|
||||
* @return The script-layer module in which the component's "Tag" ID lives.
|
||||
*/
|
||||
const char* GetModule() const;
|
||||
const std::string& GetModule() const;
|
||||
|
||||
/**
|
||||
* @return A list of all registered components.
|
||||
|
@ -55,7 +55,7 @@ public:
|
|||
* @param tag A component's tag.
|
||||
* @return The canonical component name.
|
||||
*/
|
||||
const char* GetComponentName(T tag) const;
|
||||
const std::string& GetComponentName(T tag) const;
|
||||
|
||||
/**
|
||||
* Get a component name from it's enum value.
|
||||
|
@ -63,7 +63,7 @@ public:
|
|||
* @param val A component's enum value.
|
||||
* @return The canonical component name.
|
||||
*/
|
||||
const char* GetComponentName(Val* val) const;
|
||||
const std::string& GetComponentName(Val* val) const;
|
||||
|
||||
/**
|
||||
* Get a component tag from its name.
|
||||
|
@ -134,7 +134,7 @@ ComponentManager<T, C>::ComponentManager(const string& arg_module)
|
|||
}
|
||||
|
||||
template <class T, class C>
|
||||
const char* ComponentManager<T, C>::GetModule() const
|
||||
const std::string& ComponentManager<T, C>::GetModule() const
|
||||
{
|
||||
return module.c_str();
|
||||
}
|
||||
|
@ -158,9 +158,9 @@ EnumType* ComponentManager<T, C>::GetTagEnumType() const
|
|||
}
|
||||
|
||||
template <class T, class C>
|
||||
const char* ComponentManager<T, C>::GetComponentName(T tag) const
|
||||
const std::string& ComponentManager<T, C>::GetComponentName(T tag) const
|
||||
{
|
||||
static const char* error = "<error>";
|
||||
static const std::string& error = "<error>";
|
||||
|
||||
if ( ! tag )
|
||||
return error;
|
||||
|
@ -176,7 +176,7 @@ const char* ComponentManager<T, C>::GetComponentName(T tag) const
|
|||
}
|
||||
|
||||
template <class T, class C>
|
||||
const char* ComponentManager<T, C>::GetComponentName(Val* val) const
|
||||
const std::string& ComponentManager<T, C>::GetComponentName(Val* val) const
|
||||
{
|
||||
return GetComponentName(T(val->AsEnumVal()));
|
||||
}
|
||||
|
@ -222,14 +222,14 @@ template <class T, class C>
|
|||
void ComponentManager<T, C>::RegisterComponent(C* component,
|
||||
const string& prefix)
|
||||
{
|
||||
const char* cname = component->CanonicalName();
|
||||
std::string cname = component->CanonicalName();
|
||||
|
||||
if ( Lookup(cname) )
|
||||
reporter->FatalError("Component '%s::%s' defined more than once",
|
||||
module.c_str(), cname);
|
||||
module.c_str(), cname.c_str());
|
||||
|
||||
DBG_LOG(DBG_PLUGINS, "Registering component %s (tag %s)",
|
||||
component->Name(), component->Tag().AsString().c_str());
|
||||
component->Name().c_str(), component->Tag().AsString().c_str());
|
||||
|
||||
components_by_name.insert(std::make_pair(cname, component));
|
||||
components_by_tag.insert(std::make_pair(component->Tag(), component));
|
||||
|
@ -237,7 +237,7 @@ void ComponentManager<T, C>::RegisterComponent(C* component,
|
|||
component->Tag().AsEnumVal()->InternalInt(), component));
|
||||
|
||||
// Install an identfier for enum value
|
||||
string id = fmt("%s%s", prefix.c_str(), cname);
|
||||
string id = fmt("%s%s", prefix.c_str(), cname.c_str());
|
||||
tag_enum_type->AddName(module, id.c_str(),
|
||||
component->Tag().AsEnumVal()->InternalInt(), true);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue