FST  openfst-1.8.3
OpenFst Library
error-weight.h
Go to the documentation of this file.
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 
18 #include <cstdint>
19 #include <ostream>
20 #include <string>
21 
22 #include <fst/log.h>
23 #include <fst/util.h>
24 
25 namespace fst {
26 
27 // A Weight that can never be instantiated. This is not a semi-ring.
28 // It is used for the arc type of empty FAR files.
29 struct ErrorWeight {
31 
32  ErrorWeight() { FSTERROR() << "ErrorWeight::ErrorWeight called"; }
33 
34  uint64_t Hash() const { return 0; }
35  bool Member() const { return false; }
36  ErrorWeight Quantize(float = 0.0) const { return ErrorWeight(); }
37  ReverseWeight Reverse() const { return ErrorWeight(); }
38  void Write(std::ostream &) const { }
39 
40  static constexpr uint64_t Properties() { return 0; }
41  static ErrorWeight Zero() { return ErrorWeight(); }
42  static ErrorWeight One() { return ErrorWeight(); }
43  static ErrorWeight NoWeight() { return ErrorWeight(); }
44 
45  static const std::string &Type() {
46  static const auto *const type = new std::string("error");
47  return *type;
48  }
49 };
50 
51 inline bool operator==(const ErrorWeight &, const ErrorWeight &) {
52  return false;
53 }
54 inline bool operator!=(const ErrorWeight &, const ErrorWeight &) {
55  return false;
56 }
57 
58 inline bool ApproxEqual(const ErrorWeight &, const ErrorWeight &, float) {
59  return false;
60 }
61 inline ErrorWeight Plus(const ErrorWeight &, const ErrorWeight &) {
62  return ErrorWeight();
63 }
64 inline ErrorWeight Times(const ErrorWeight &, const ErrorWeight &) {
65  return ErrorWeight();
66 }
67 inline ErrorWeight Divide(const ErrorWeight &, const ErrorWeight &) {
68  return ErrorWeight();
69 }
70 
71 inline std::ostream &operator<<(std::ostream &strm, const ErrorWeight &) {
72  return strm;
73 }
74 
75 } // namespace fst
76 
77 #endif // FST_ERROR_WEIGHT_H_
bool Member() const
Definition: error-weight.h:35
static ErrorWeight Zero()
Definition: error-weight.h:41
static constexpr uint64_t Properties()
Definition: error-weight.h:40
ErrorWeight Plus(const ErrorWeight &, const ErrorWeight &)
Definition: error-weight.h:61
ErrorWeight Times(const ErrorWeight &, const ErrorWeight &)
Definition: error-weight.h:64
ErrorWeight Quantize(float=0.0) const
Definition: error-weight.h:36
#define FSTERROR()
Definition: util.h:56
bool operator!=(const ErrorWeight &, const ErrorWeight &)
Definition: error-weight.h:54
std::ostream & operator<<(std::ostream &strm, const ErrorWeight &)
Definition: error-weight.h:71
uint64_t Hash() const
Definition: error-weight.h:34
void Write(std::ostream &) const
Definition: error-weight.h:38
static ErrorWeight NoWeight()
Definition: error-weight.h:43
ReverseWeight Reverse() const
Definition: error-weight.h:37
static const std::string & Type()
Definition: error-weight.h:45
static ErrorWeight One()
Definition: error-weight.h:42
ErrorWeight Divide(const ErrorWeight &, const ErrorWeight &)
Definition: error-weight.h:67
bool operator==(const ErrorWeight &, const ErrorWeight &)
Definition: error-weight.h:51
bool ApproxEqual(const ErrorWeight &, const ErrorWeight &, float)
Definition: error-weight.h:58