• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *
3  * Copyright 2017 gRPC authors.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 #ifndef GRPC_CORE_LIB_GPRPP_DEBUG_LOCATION_H
20 #define GRPC_CORE_LIB_GPRPP_DEBUG_LOCATION_H
21 
22 namespace grpc_core {
23 
24 // Used for tracking file and line where a call is made for debug builds.
25 // No-op for non-debug builds.
26 // Callers can use the DEBUG_LOCATION macro in either case.
27 #ifndef NDEBUG
28 class DebugLocation {
29  public:
DebugLocation(const char * file,int line)30   DebugLocation(const char* file, int line) : file_(file), line_(line) {}
Log()31   bool Log() const { return true; }
file()32   const char* file() const { return file_; }
line()33   int line() const { return line_; }
34 
35  private:
36   const char* file_;
37   const int line_;
38 };
39 #define DEBUG_LOCATION ::grpc_core::DebugLocation(__FILE__, __LINE__)
40 #else
41 class DebugLocation {
42  public:
43   bool Log() const { return false; }
44   const char* file() const { return nullptr; }
45   int line() const { return -1; }
46 };
47 #define DEBUG_LOCATION ::grpc_core::DebugLocation()
48 #endif
49 
50 }  // namespace grpc_core
51 
52 #endif /* GRPC_CORE_LIB_GPRPP_DEBUG_LOCATION_H */
53