92 #ifndef FST_SCRIPT_SCRIPT_IMPL_H_ 93 #define FST_SCRIPT_SCRIPT_IMPL_H_ 110 #include <string_view> 122 template <
class OperationSignature>
124 :
public GenericRegister<std::pair<std::string_view, std::string_view>,
126 GenericOperationRegister<OperationSignature>> {
129 std::string_view arc_type) {
130 return this->GetEntry(std::make_pair(operation_name, arc_type));
135 const std::pair<std::string_view, std::string_view> &key)
const final {
137 std::string legal_type(key.second);
139 legal_type.append(
"-arc.so");
151 template <
class Args>
165 #define REGISTER_FST_OPERATION(Op, Arc, ArgPack) \ 166 static fst::script::Operation<ArgPack>::Registerer \ 167 arc_dispatched_operation_##ArgPack##Op##Arc##_registerer \ 168 ({#Op, Arc::Type()}, Op<Arc>) 171 #define REGISTER_FST_OPERATION_3ARCS(Op, ArgPack) \ 172 REGISTER_FST_OPERATION(Op, StdArc, ArgPack); \ 173 REGISTER_FST_OPERATION(Op, LogArc, ArgPack); \ 174 REGISTER_FST_OPERATION(Op, Log64Arc, ArgPack) 177 template <
class OpReg>
178 void Apply(
const std::string &op_name,
const std::string &arc_type,
179 typename OpReg::ArgPack *args) {
181 OpReg::Register::GetRegister()->GetOperation(op_name, arc_type);
183 FSTERROR() << op_name <<
": No operation found on arc type " << arc_type;
194 template <
class M,
class N>
196 if (m.ArcType() != n.ArcType()) {
197 FSTERROR() << op_name <<
": Arguments with non-matching arc types " 198 << m.ArcType() <<
" and " << n.ArcType();
205 template <
class Weight>
207 std::vector<Weight> *typed_weights) {
208 typed_weights->clear();
209 typed_weights->reserve(weights.size());
210 for (
const auto &weight : weights) {
211 typed_weights->emplace_back(*weight.GetWeight<Weight>());
216 template <
class Weight>
218 std::vector<WeightClass> *weights) {
220 weights->reserve(typed_weights.size());
221 for (
const auto &typed_weight : typed_weights) {
222 weights->emplace_back(typed_weight);
229 inline std::vector<std::pair<int64_t, const FstClass *>>
BorrowPairs(
230 const std::vector<std::pair<int64_t, std::unique_ptr<const FstClass>>>
232 std::vector<std::pair<int64_t, const FstClass *>> borrowed_pairs;
233 borrowed_pairs.reserve(pairs.size());
234 for (
const auto &pair : pairs) {
235 borrowed_pairs.emplace_back(pair.first, pair.second.get());
237 return borrowed_pairs;
243 #endif // FST_SCRIPT_SCRIPT_IMPL_H_
void CopyWeights(const std::vector< Weight > &typed_weights, std::vector< WeightClass > *weights)
void ConvertToLegalCSymbol(std::string *s)
std::string ConvertKeyToSoFilename(const std::pair< std::string_view, std::string_view > &key) const final
void Apply(const std::string &op_name, const std::string &arc_type, typename OpReg::ArgPack *args)
bool ArcTypesMatch(const M &m, const N &n, const std::string &op_name)
void(*)(ArgPack *args) OpType
std::vector< std::pair< int64_t, const FstClass * > > BorrowPairs(const std::vector< std::pair< int64_t, std::unique_ptr< const FstClass >>> &pairs)
OperationSignature GetOperation(std::string_view operation_name, std::string_view arc_type)