1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
#pragma once
#include "../std/algorithm.hpp"
#include "../std/sstream.hpp"
#include "../std/string.hpp"
#ifndef SRC_LOGGING
#define SRC_LOGGING 1
#endif
#if SRC_LOGGING
#ifndef __OBJC__
#define SRC() my::SrcPoint(__FILE__, __LINE__, __FUNCTION__, "()")
#else
#define SRC() my::SrcPoint(__FILE__, __LINE__, __FUNCTION__)
#endif
#else
#define SRC() my::SrcPoint()
#endif
namespace my
{
class SrcPoint
{
public:
SrcPoint() : m_fileName(""), m_line(-1), m_function(""), m_postfix("")
{
TruncateFileName();
}
SrcPoint(char const * fileName, int line, char const * function, char const * postfix = "")
: m_fileName(fileName), m_line(line), m_function(function), m_postfix(postfix)
{
TruncateFileName();
}
inline char const * FileName() const
{
return m_fileName;
}
inline int Line() const
{
return m_line;
}
inline char const * Function() const
{
return m_function;
}
inline char const * Postfix() const
{
return m_postfix;
}
private:
void TruncateFileName()
{
size_t const maxLen = 10000;
char const * p[] = { m_fileName, m_fileName };
for (size_t i = 0; i < maxLen && m_fileName[i]; ++i)
{
if (m_fileName[i] == '\\' || m_fileName[i] == '/')
{
swap(p[0], p[1]);
p[0] = m_fileName + i + 1;
}
}
m_fileName = p[1];
}
char const * m_fileName;
int m_line;
char const * m_function;
char const * m_postfix;
};
}
inline string DebugPrint(my::SrcPoint const & srcPoint)
{
ostringstream out;
if (srcPoint.Line() > 0)
out << srcPoint.FileName() << ":" << srcPoint.Line() << " " << srcPoint.Function()
<< srcPoint.Postfix() << " ";
return out.str();
}
|