ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
logging.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #pragma once
9 
10 #include <glog/logging.h>
11 
12 #include <iostream>
13 
14 #include "util/string.h"
15 
16 // Option checker macros. In contrast to glog, this function does not abort the
17 // program, but simply returns false on failure.
18 #define CHECK_OPTION_IMPL(expr) \
19  __CheckOptionImpl(__FILE__, __LINE__, (expr), #expr)
20 #define CHECK_OPTION(expr) \
21  if (!__CheckOptionImpl(__FILE__, __LINE__, (expr), #expr)) { \
22  return false; \
23  }
24 #define CHECK_OPTION_OP(name, op, val1, val2) \
25  if (!__CheckOptionOpImpl(__FILE__, __LINE__, (val1 op val2), val1, val2, \
26  #val1, #val2, #op)) { \
27  return false; \
28  }
29 #define CHECK_OPTION_EQ(val1, val2) CHECK_OPTION_OP(_EQ, ==, val1, val2)
30 #define CHECK_OPTION_NE(val1, val2) CHECK_OPTION_OP(_NE, !=, val1, val2)
31 #define CHECK_OPTION_LE(val1, val2) CHECK_OPTION_OP(_LE, <=, val1, val2)
32 #define CHECK_OPTION_LT(val1, val2) CHECK_OPTION_OP(_LT, <, val1, val2)
33 #define CHECK_OPTION_GE(val1, val2) CHECK_OPTION_OP(_GE, >=, val1, val2)
34 #define CHECK_OPTION_GT(val1, val2) CHECK_OPTION_OP(_GT, >, val1, val2)
35 
36 namespace colmap {
37 
38 // Initialize glog at the beginning of the program.
39 void InitializeGlog(char** argv);
40 
42 // Implementation
44 
45 const char* __GetConstFileBaseName(const char* file);
46 
47 bool __CheckOptionImpl(const char* file,
48  const int line,
49  const bool result,
50  const char* expr_str);
51 
52 template <typename T1, typename T2>
53 bool __CheckOptionOpImpl(const char* file,
54  const int line,
55  const bool result,
56  const T1& val1,
57  const T2& val2,
58  const char* val1_str,
59  const char* val2_str,
60  const char* op_str) {
61  if (result) {
62  return true;
63  } else {
64  std::cerr
65  << StringPrintf(
66  "[WARNING %s:%d] Check failed: %s %s %s (%s vs. %s)",
67  __GetConstFileBaseName(file), line, val1_str, op_str,
68  val2_str, std::to_string(val1).c_str(),
69  std::to_string(val2).c_str())
70  << "\n";
71  return false;
72  }
73 }
74 
75 } // namespace colmap
core::Tensor result
Definition: VtkUtils.cpp:76
void InitializeGlog(char **argv)
Definition: logging.cc:36
bool __CheckOptionOpImpl(const char *file, const int line, const bool result, const T1 &val1, const T2 &val2, const char *val1_str, const char *val2_str, const char *op_str)
Definition: logging.h:53
bool __CheckOptionImpl(const char *file, const int line, const bool result, const char *expr_str)
Definition: logging.cc:51
const char * __GetConstFileBaseName(const char *file)
Definition: logging.cc:43
std::string StringPrintf(const char *format,...)
Definition: string.cc:131
std::string to_string(const T &n)
Definition: Common.h:20