18 #ifndef FST_GENERIC_REGISTER_H_ 19 #define FST_GENERIC_REGISTER_H_ 24 #include <string_view> 26 #ifndef FST_NO_DYNAMIC_LINKING 57 using type = std::string_view;
61 template <
class KeyType,
class EntryType,
class RegisterType>
69 static auto reg =
new RegisterType;
73 void SetEntry(
const KeyType &key,
const EntryType &entry) {
75 register_table_.emplace(key, entry);
79 const auto *entry = LookupEntry(key);
83 return LoadEntryFromSharedObject(key);
93 #ifdef FST_NO_DYNAMIC_LINKING 96 const auto so_filename = ConvertKeyToSoFilename(key);
97 void *handle = dlopen(so_filename.c_str(), RTLD_LAZY);
98 if (handle ==
nullptr) {
99 LOG(ERROR) <<
"GenericRegister::GetEntry: " << dlerror();
102 #ifdef RUN_MODULE_INITIALIZERS 103 RUN_MODULE_INITIALIZERS();
108 const auto *entry = this->LookupEntry(key);
109 if (entry ==
nullptr) {
110 LOG(ERROR) <<
"GenericRegister::GetEntry: " 111 <<
"lookup failed in shared object: " << so_filename;
115 #endif // FST_NO_DYNAMIC_LINKING 119 virtual std::string ConvertKeyToSoFilename(
KeyLookupRef key)
const = 0;
123 if (
const auto it = register_table_.find(key);
124 it != register_table_.end()) {
132 mutable Mutex register_lock_;
133 std::map<KeyType, EntryType, std::less<>> register_table_;
141 template <
class RegisterType>
144 using Key =
typename RegisterType::Key;
145 using Entry =
typename RegisterType::Entry;
148 RegisterType::GetRegister()->SetEntry(key, entry);
154 #endif // FST_GENERIC_REGISTER_H_ typename FstRegister< FST::Arc >::Key Key
GenericRegisterer(Key key, Entry entry)
virtual EntryType LoadEntryFromSharedObject(KeyLookupRef key) const
static RegisterType * GetRegister()
EntryType GetEntry(KeyLookupRef key) const
EncodeMapperClassRegEntry< Reader, Creator > Entry
typename internal::KeyLookupReferenceType< std::string >::type KeyLookupRef
virtual const EntryType * LookupEntry(KeyLookupRef key) const
void SetEntry(const KeyType &key, const EntryType &entry)
typename FstRegister< FST::Arc >::Entry Entry