mirror of
https://github.com/inspircd/inspircd.git
synced 2025-03-09 18:49:03 -04:00
Add stdalgo::isin() and use it to simplify code
This commit is contained in:
parent
fbc73e2078
commit
48f8f79317
@ -112,4 +112,16 @@ namespace stdalgo
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if an element with the given value is in a container. Equivalent to (std::find(cont.begin(), cont.end(), val) != cont.end()).
|
||||
* @param cont Container to find the element in
|
||||
* @param val Value of the element to look for
|
||||
* @return True if the element was found in the container, false otherwise
|
||||
*/
|
||||
template <template<typename, typename> class Cont, typename T, typename Alloc>
|
||||
inline bool isin(const Cont<T, Alloc>& cont, const T& val)
|
||||
{
|
||||
return (std::find(cont.begin(), cont.end(), val) != cont.end());
|
||||
}
|
||||
}
|
||||
|
@ -367,7 +367,7 @@ void ParseStack::DoReadFile(const std::string& key, const std::string& name, int
|
||||
bool ParseStack::ParseFile(const std::string& path, int flags, const std::string& mandatory_tag, bool isexec)
|
||||
{
|
||||
ServerInstance->Logs->Log("CONFIG", LOG_DEBUG, "Reading (isexec=%d) %s", isexec, path.c_str());
|
||||
if (std::find(reading.begin(), reading.end(), path) != reading.end())
|
||||
if (stdalgo::isin(reading, path))
|
||||
throw CoreException((isexec ? "Executable " : "File ") + path + " is included recursively (looped inclusion)");
|
||||
|
||||
/* It's not already included, add it to the list of files we've loaded */
|
||||
|
@ -288,7 +288,7 @@ void LogManager::Log(const std::string &type, LogLevel loglevel, const std::stri
|
||||
|
||||
for (std::map<LogStream *, std::vector<std::string> >::iterator gi = GlobalLogStreams.begin(); gi != GlobalLogStreams.end(); ++gi)
|
||||
{
|
||||
if (std::find(gi->second.begin(), gi->second.end(), type) != gi->second.end())
|
||||
if (stdalgo::isin(gi->second, type))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
@ -178,7 +178,7 @@ ModuleManager::~ModuleManager()
|
||||
|
||||
bool ModuleManager::Attach(Implementation i, Module* mod)
|
||||
{
|
||||
if (std::find(EventHandlers[i].begin(), EventHandlers[i].end(), mod) != EventHandlers[i].end())
|
||||
if (stdalgo::isin(EventHandlers[i], mod))
|
||||
return false;
|
||||
|
||||
EventHandlers[i].push_back(mod);
|
||||
|
@ -113,7 +113,7 @@ class ModuleShowFile : public Module
|
||||
|
||||
// This is our command, make sure we don't have the same entry twice
|
||||
sfcmd = static_cast<CommandShowFile*>(handler);
|
||||
if (std::find(newcmds.begin(), newcmds.end(), sfcmd) != newcmds.end())
|
||||
if (stdalgo::isin(newcmds, sfcmd))
|
||||
throw ModuleException("Command " + cmdname + " is already used in a <showfile> tag");
|
||||
}
|
||||
else
|
||||
|
Loading…
x
Reference in New Issue
Block a user