FST  openfst-1.8.1
OpenFst Library
log.h
Go to the documentation of this file.
1 // Licensed under the Apache License, Version 2.0 (the "License");
2 // you may not use this file except in compliance with the License.
3 // You may obtain a copy of the License at
4 //
5 // http://www.apache.org/licenses/LICENSE-2.0
6 //
7 // Unless required by applicable law or agreed to in writing, software
8 // distributed under the License is distributed on an "AS IS" BASIS,
9 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 // See the License for the specific language governing permissions and
11 // limitations under the License.
12 //
13 // See www.openfst.org for extensive documentation on this weighted
14 // finite-state transducer library.
15 //
16 // Google-style logging declarations and inline definitions.
17 
18 #ifndef FST_LIB_LOG_H_
19 #define FST_LIB_LOG_H_
20 
21 #include <cassert>
22 #include <iostream>
23 #include <string>
24 
25 #include <fst/types.h>
26 #include <fst/flags.h>
27 
28 DECLARE_int32(v);
29 
30 class LogMessage {
31  public:
32  LogMessage(const std::string &type) : fatal_(type == "FATAL") {
33  std::cerr << type << ": ";
34  }
36  std::cerr << std::endl;
37  if(fatal_)
38  exit(1);
39  }
40  std::ostream &stream() { return std::cerr; }
41 
42  private:
43  bool fatal_;
44 };
45 
46 #define LOG(type) LogMessage(#type).stream()
47 #define VLOG(level) if ((level) <= FST_FLAGS_v) LOG(INFO)
48 
49 // Checks
50 inline void FstCheck(bool x, const char* expr,
51  const char *file, int line) {
52  if (!x) {
53  LOG(FATAL) << "Check failed: \"" << expr
54  << "\" file: " << file
55  << " line: " << line;
56  }
57 }
58 
59 #define CHECK(x) FstCheck(static_cast<bool>(x), #x, __FILE__, __LINE__)
60 #define CHECK_EQ(x, y) CHECK((x) == (y))
61 #define CHECK_LT(x, y) CHECK((x) < (y))
62 #define CHECK_GT(x, y) CHECK((x) > (y))
63 #define CHECK_LE(x, y) CHECK((x) <= (y))
64 #define CHECK_GE(x, y) CHECK((x) >= (y))
65 #define CHECK_NE(x, y) CHECK((x) != (y))
66 
67 // Debug checks
68 #define DCHECK(x) assert(x)
69 #define DCHECK_EQ(x, y) DCHECK((x) == (y))
70 #define DCHECK_LT(x, y) DCHECK((x) < (y))
71 #define DCHECK_GT(x, y) DCHECK((x) > (y))
72 #define DCHECK_LE(x, y) DCHECK((x) <= (y))
73 #define DCHECK_GE(x, y) DCHECK((x) >= (y))
74 #define DCHECK_NE(x, y) DCHECK((x) != (y))
75 
76 
77 // Ports
78 #define ATTRIBUTE_DEPRECATED __attribute__((deprecated))
79 
80 #endif // FST_LIB_LOG_H_
~LogMessage()
Definition: log.h:35
#define LOG(type)
Definition: log.h:46
Definition: log.h:30
std::ostream & stream()
Definition: log.h:40
DECLARE_int32(v)
void FstCheck(bool x, const char *expr, const char *file, int line)
Definition: log.h:50
LogMessage(const std::string &type)
Definition: log.h:32