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