You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
2.3 KiB

  1. // Copyright 2005-2024 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the 'License');
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an 'AS IS' BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. //
  15. #ifndef FST_ERROR_WEIGHT_H_
  16. #define FST_ERROR_WEIGHT_H_
  17. #include <cstdint>
  18. #include <ostream>
  19. #include <string>
  20. #include <fst/log.h>
  21. #include <fst/util.h>
  22. namespace fst {
  23. // A Weight that can never be instantiated. This is not a semi-ring.
  24. // It is used for the arc type of empty FAR files.
  25. struct ErrorWeight {
  26. using ReverseWeight = ErrorWeight;
  27. ErrorWeight() { FSTERROR() << "ErrorWeight::ErrorWeight called"; }
  28. uint64_t Hash() const { return 0; }
  29. bool Member() const { return false; }
  30. ErrorWeight Quantize(float = 0.0) const { return ErrorWeight(); }
  31. ReverseWeight Reverse() const { return ErrorWeight(); }
  32. void Write(std::ostream &) const { }
  33. static constexpr uint64_t Properties() { return 0; }
  34. static ErrorWeight Zero() { return ErrorWeight(); }
  35. static ErrorWeight One() { return ErrorWeight(); }
  36. static ErrorWeight NoWeight() { return ErrorWeight(); }
  37. static const std::string &Type() {
  38. static const auto *const type = new std::string("error");
  39. return *type;
  40. }
  41. };
  42. inline bool operator==(const ErrorWeight &, const ErrorWeight &) {
  43. return false;
  44. }
  45. inline bool operator!=(const ErrorWeight &, const ErrorWeight &) {
  46. return false;
  47. }
  48. inline bool ApproxEqual(const ErrorWeight &, const ErrorWeight &, float) {
  49. return false;
  50. }
  51. inline ErrorWeight Plus(const ErrorWeight &, const ErrorWeight &) {
  52. return ErrorWeight();
  53. }
  54. inline ErrorWeight Times(const ErrorWeight &, const ErrorWeight &) {
  55. return ErrorWeight();
  56. }
  57. inline ErrorWeight Divide(const ErrorWeight &, const ErrorWeight &) {
  58. return ErrorWeight();
  59. }
  60. inline std::ostream &operator<<(std::ostream &strm, const ErrorWeight &) {
  61. return strm;
  62. }
  63. } // namespace fst
  64. #endif // FST_ERROR_WEIGHT_H_