/usr/include/fst/script/register.h is in libfst-dev 1.5.3+r3-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | // See www.openfst.org for extensive documentation on this weighted
// finite-state transducer library.
#ifndef FST_SCRIPT_REGISTER_H_
#define FST_SCRIPT_REGISTER_H_
#include <istream>
#include <string>
#include <fst/generic-register.h>
#include <fst/script/fst-class.h>
#include <fst/script/weight-class.h>
// Holds methods and classes responsible for maintaining
// the register for FstClass arc types.
namespace fst {
namespace script {
// Registers for reading and converting various kinds of FST classes.
// This class definition is to avoid a nested class definition inside
// the IORegistration struct.
template <class Reader, class Creator, class Converter>
struct FstClassRegEntry {
Reader reader;
Creator creator;
Converter converter;
FstClassRegEntry(Reader r, Creator cr, Converter co)
: reader(r), creator(cr), converter(co) {}
FstClassRegEntry()
: reader(NullReader), creator(NullCreator), converter(NullConverter) {}
// Null-returning reader, creator, and converter, used when registry lookup
// fails.
template <class FstClassType>
static FstClassType *NullReader(std::istream &strm,
const FstReadOptions &opts) {
return nullptr;
}
static FstClassImplBase *NullCreator() { return nullptr; }
static FstClassImplBase *NullConverter(const FstClass &other) {
return nullptr;
}
};
template <class Reader, class Creator, class Converter>
class FstClassIORegister
: public GenericRegister<string,
FstClassRegEntry<Reader, Creator, Converter>,
FstClassIORegister<Reader, Creator, Converter>> {
public:
Reader GetReader(const string &arc_type) const {
return this->GetEntry(arc_type).reader;
}
Creator GetCreator(const string &arc_type) const {
return this->GetEntry(arc_type).creator;
}
Converter GetConverter(const string &arc_type) const {
return this->GetEntry(arc_type).converter;
}
protected:
string ConvertKeyToSoFilename(const string &key) const override {
string legal_type(key);
ConvertToLegalCSymbol(&legal_type);
return legal_type + "-arc.so";
}
};
//
// Struct containing everything needed to register a particular type
// of FST class (e.g. a plain FstClass, or a MutableFstClass, etc)
//
template <class FstClassType>
struct IORegistration {
typedef FstClassType *(*Reader)(std::istream &stream,
const FstReadOptions &opts);
typedef FstClassImplBase *(*Creator)();
typedef FstClassImplBase *(*Converter)(const FstClass &other);
typedef FstClassRegEntry<Reader, Creator, Converter> Entry;
// FST class Register
typedef FstClassIORegister<Reader, Creator, Converter> Register;
// FST class Register-er
typedef GenericRegisterer<FstClassIORegister<Reader, Creator, Converter>>
Registerer;
};
//
// REGISTRATION MACROS
//
#define REGISTER_FST_CLASS(Class, Arc) \
static IORegistration<Class>::Registerer Class##_##Arc##_registerer( \
Arc::Type(), \
IORegistration<Class>::Entry(Class::Read<Arc>, Class::Create<Arc>, \
Class::Convert<Arc>))
#define REGISTER_FST_CLASSES(Arc) \
REGISTER_FST_CLASS(FstClass, Arc); \
REGISTER_FST_CLASS(MutableFstClass, Arc); \
REGISTER_FST_CLASS(VectorFstClass, Arc);
} // namespace script
} // namespace fst
#endif // FST_SCRIPT_REGISTER_H_
|