HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
code_location.h
Go to the documentation of this file.
1 // Copyright (c) Microsoft Corporation. All rights reserved.
2 // Licensed under the MIT License.
3 
4 #pragma once
5 
6 #include <sstream>
7 #include <string>
8 #include <vector>
9 
10 namespace onnxruntime {
11 /**
12  CodeLocation captures information on where in the source code a message came from.
13 */
14 struct CodeLocation {
15  /**
16  @param file_path Usually the value of __FILE__
17  @param line Usually the value of __LINE__
18  @param func Usually the value of __PRETTY_FUNCTION__ or __FUNCTION__
19  */
20  CodeLocation(const char* file_path, const int line, const char* func)
21  : file_and_path{file_path}, line_num{line}, function{func} {
22  }
23 
24  /**
25  @param file_path Usually the value of __FILE__
26  @param line Usually the value of __LINE__
27  @param func Usually the value of __PRETTY_FUNCTION__ or __FUNCTION__
28  @param stacktrace Stacktrace from source of message.
29  */
30  CodeLocation(const char* file_path, const int line, const char* func, const std::vector<std::string>& stacktrace)
31  : file_and_path{file_path}, line_num{line}, function{func}, stacktrace(stacktrace) {
32  }
33 
35  // assuming we always have work to do, so not trying to avoid creating a new string if
36  // no path was removed.
37  return file_and_path.substr(file_and_path.find_last_of("/\\") + 1);
38  }
39 
40  enum Format {
43  };
44 
45  std::string ToString(Format format = Format::kFilename) const {
46  std::ostringstream out;
47  out << (format == Format::kFilename ? FileNoPath() : file_and_path) << ":" << line_num << " " << function;
48  return out.str();
49  }
50  // utf-8. Because on Windows we compile our code with "/utf-8". And we assume the other platforms only use utf-8.
52  const int line_num;
53  // utf-8
54  const std::string function;
55  const std::vector<std::string> stacktrace;
56 };
57 
58 } // namespace onnxruntime
GLsizei const GLchar *const * string
Definition: glcorearb.h:814
CodeLocation(const char *file_path, const int line, const char *func)
Definition: code_location.h:20
const std::vector< std::string > stacktrace
Definition: code_location.h:55
const std::string file_and_path
Definition: code_location.h:51
std::string ToString(Format format=Format::kFilename) const
Definition: code_location.h:45
GLint GLint GLsizei GLint GLenum format
Definition: glcorearb.h:108
GLenum func
Definition: glcorearb.h:783
std::string FileNoPath() const
Definition: code_location.h:34
CodeLocation(const char *file_path, const int line, const char *func, const std::vector< std::string > &stacktrace)
Definition: code_location.h:30