#include "registrator.h" #include "re.h" #include #include #include #include #include namespace NReWrapper { namespace NRegistrator { struct TLib { ui64 Id = 0; TCompiler Compiler; TDeserializer Deserializer; }; using TModules = TVector; TModules* GetModules() { return Singleton(); } void AddLibrary(ui32 id, TCompiler compiler, TDeserializer deserializer) { Y_ABORT_UNLESS(id > 0); if (GetModules()->size() < id) { GetModules()->resize(id); } GetModules()->at(id - 1) = TLib{id, compiler, deserializer}; } } namespace NDispatcher { void ThrowOnOutOfRange(ui32 id) { if (NRegistrator::GetModules()->size() < id || id == 0) { ythrow yexception() << "Libs with id: " << id << " was not found. Total added libs: " << NRegistrator::GetModules()->size(); } } bool Has(ui32 id) { if (id == 0 || id > NRegistrator::GetModules()->size()) { return false; } return NRegistrator::GetModules()->at(id).Id == id; } IRePtr Deserialize(const TStringBuf& serializedRegex) { TSerialization proto; TString str(serializedRegex); auto res = proto.ParseFromString(str); if (!res) { proto.SetHyperscan(str); } ui64 id = (ui64)proto.GetDataCase();; ThrowOnOutOfRange(id); return NRegistrator::GetModules()->at(id - 1).Deserializer(proto); } IRePtr Compile(const TStringBuf& regex, unsigned int flags, ui32 id) { ThrowOnOutOfRange(id); return NRegistrator::GetModules()->at(id - 1).Compiler(regex, flags); } } }