FST  openfst-1.7.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 using std::string;
29 
30 DECLARE_int32(v);
31 
32 class LogMessage {
33  public:
34  LogMessage(const string &type) : fatal_(type == "FATAL") {
35  std::cerr << type << ": ";
36  }
38  std::cerr << std::endl;
39  if(fatal_)
40  exit(1);
41  }
42  std::ostream &stream() { return std::cerr; }
43 
44  private:
45  bool fatal_;
46 };
47 
48 #define LOG(type) LogMessage(#type).stream()
49 #define VLOG(level) if ((level) <= FLAGS_v) LOG(INFO)
50 
51 // Checks
52 inline void FstCheck(bool x, const char* expr,
53  const char *file, int line) {
54  if (!x) {
55  LOG(FATAL) << "Check failed: \"" << expr
56  << "\" file: " << file
57  << " line: " << line;
58  }
59 }
60 
61 #define CHECK(x) FstCheck(static_cast<bool>(x), #x, __FILE__, __LINE__)
62 #define CHECK_EQ(x, y) CHECK((x) == (y))
63 #define CHECK_LT(x, y) CHECK((x) < (y))
64 #define CHECK_GT(x, y) CHECK((x) > (y))
65 #define CHECK_LE(x, y) CHECK((x) <= (y))
66 #define CHECK_GE(x, y) CHECK((x) >= (y))
67 #define CHECK_NE(x, y) CHECK((x) != (y))
68 
69 // Debug checks
70 #define DCHECK(x) assert(x)
71 #define DCHECK_EQ(x, y) DCHECK((x) == (y))
72 #define DCHECK_LT(x, y) DCHECK((x) < (y))
73 #define DCHECK_GT(x, y) DCHECK((x) > (y))
74 #define DCHECK_LE(x, y) DCHECK((x) <= (y))
75 #define DCHECK_GE(x, y) DCHECK((x) >= (y))
76 #define DCHECK_NE(x, y) DCHECK((x) != (y))
77 
78 
79 // Ports
80 #define ATTRIBUTE_DEPRECATED __attribute__((deprecated))
81 
82 #endif // FST_LIB_LOG_H_
~LogMessage()
Definition: log.h:37
#define LOG(type)
Definition: log.h:48
LogMessage(const string &type)
Definition: log.h:34
Definition: log.h:32
std::ostream & stream()
Definition: log.h:42
DECLARE_int32(v)
void FstCheck(bool x, const char *expr, const char *file, int line)
Definition: log.h:52