This repository has been archived on 2024-10-22. You can view files and clone it, but cannot push or open issues or pull requests.
YimMenu/BigBaseV2/src/memory/pattern_batch.cpp
2019-06-23 22:00:18 +02:00

40 lines
828 B
C++

#include "../common.hpp"
#include "../logger.hpp"
#include "pattern_batch.hpp"
#include "range.hpp"
namespace memory
{
void pattern_batch::add(std::string name, pattern pattern, std::function<void(handle)> callback)
{
m_entries.emplace_back(std::move(name), std::move(pattern), std::move(callback));
}
void pattern_batch::run(range region)
{
bool all_found = true;
for (auto &entry : m_entries)
{
if (auto result = region.scan(entry.m_pattern))
{
if (entry.m_callback)
{
std::invoke(std::move(entry.m_callback), result);
LOG_INFO("Found '{}'.", entry.m_name);
}
else
{
all_found = false;
LOG_ERROR("Failed to find '{}'.", entry.m_name);
}
}
}
m_entries.clear();
if (!all_found)
{
throw std::runtime_error("Failed to find some patterns.");
}
}
}