20 #include <string_view> 30 std::string_view weight_str) {
32 const auto stw = reg->GetEntry(weight_type);
34 FSTERROR() <<
"WeightClass: Unknown weight type: " << weight_type;
38 impl_ = stw(weight_str);
55 std::string_view op_name) {
57 FSTERROR() << op_name <<
": Weights with non-matching types: " << lhs.
Type()
58 <<
" and " << rhs.
Type();
65 const auto *lhs_impl = lhs.GetImpl();
66 const auto *rhs_impl = rhs.GetImpl();
67 if (!(lhs_impl && rhs_impl &&
71 return *lhs_impl == *rhs_impl;
79 const auto *rhs_impl = rhs.GetImpl();
80 if (!(lhs.GetImpl() && rhs_impl &&
85 result.GetImpl()->
PlusEq(*rhs_impl);
90 const auto *rhs_impl = rhs.GetImpl();
91 if (!(lhs.GetImpl() && rhs_impl &&
96 result.GetImpl()->
TimesEq(*rhs_impl);
101 const auto *rhs_impl = rhs.GetImpl();
102 if (!(lhs.GetImpl() && rhs_impl &&
107 result.GetImpl()->
DivideEq(*rhs_impl);
119 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__