28 #include <string_view> 38 std::string_view weight_str) {
40 const auto stw = reg->GetEntry(weight_type);
42 FSTERROR() <<
"WeightClass: Unknown weight type: " << weight_type;
46 impl_ = stw(weight_str);
63 std::string_view op_name) {
65 FSTERROR() << op_name <<
": Weights with non-matching types: " << lhs.
Type()
66 <<
" and " << rhs.
Type();
73 const auto *lhs_impl = lhs.GetImpl();
74 const auto *rhs_impl = rhs.GetImpl();
75 if (!(lhs_impl && rhs_impl &&
79 return *lhs_impl == *rhs_impl;
87 const auto *rhs_impl = rhs.GetImpl();
88 if (!(lhs.GetImpl() && rhs_impl &&
93 result.GetImpl()->
PlusEq(*rhs_impl);
98 const auto *rhs_impl = rhs.GetImpl();
99 if (!(lhs.GetImpl() && rhs_impl &&
104 result.GetImpl()->
TimesEq(*rhs_impl);
109 const auto *rhs_impl = rhs.GetImpl();
110 if (!(lhs.GetImpl() && rhs_impl &&
115 result.GetImpl()->
DivideEq(*rhs_impl);
127 weight.impl_->Print(&ostrm);
friend WeightClass Plus(const WeightClass &lhs, const WeightClass &rhs)
friend bool operator==(const WeightClass &lhs, const WeightClass &rhs)
static constexpr std::string_view __ONE__
virtual WeightImplBase & PowerEq(size_t n)=0
const std::string & Type() const
static WeightClassRegister * GetRegister()
static constexpr std::string_view __NOWEIGHT__
friend std::ostream & operator<<(std::ostream &o, const WeightClass &c)
virtual WeightImplBase & DivideEq(const WeightImplBase &other)=0
virtual WeightImplBase & PlusEq(const WeightImplBase &other)=0
REGISTER_FST_WEIGHT(StdArc::Weight)
friend WeightClass Power(const WeightClass &w, size_t n)
static bool WeightTypesMatch(const WeightClass &lhs, const WeightClass &rhs, std::string_view op_name)
static WeightClass Zero(std::string_view weight_type)
static WeightClass NoWeight(std::string_view weight_type)
virtual WeightImplBase & TimesEq(const WeightImplBase &other)=0
static WeightClass One(std::string_view weight_type)
bool operator!=(const WeightClass &lhs, const WeightClass &rhs)
friend WeightClass Times(const WeightClass &lhs, const WeightClass &rhs)
friend WeightClass Divide(const WeightClass &lhs, const WeightClass &rhs)
static constexpr std::string_view __ZERO__