sptk2 logo
SPTK Home Page
Location.h
1/*
2╔══════════════════════════════════════════════════════════════════════════════╗
3║ SIMPLY POWERFUL TOOLKIT (SPTK) ║
4╟──────────────────────────────────────────────────────────────────────────────╢
5║ copyright © 1999-2022 Alexey Parshin. All rights reserved. ║
6║ email alexeyp@gmail.com ║
7╚══════════════════════════════════════════════════════════════════════════════╝
8┌──────────────────────────────────────────────────────────────────────────────┐
9│ This library is free software; you can redistribute it and/or modify it │
10│ under the terms of the GNU Library General Public License as published by │
11│ the Free Software Foundation; either version 2 of the License, or (at your │
12│ option) any later version. │
13│ │
14│ This library is distributed in the hope that it will be useful, but │
15│ WITHOUT ANY WARRANTY; without even the implied warranty of │
16│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library │
17│ General Public License for more details. │
18│ │
19│ You should have received a copy of the GNU Library General Public License │
20│ along with this library; if not, write to the Free Software Foundation, │
21│ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. │
22│ │
23│ Please report all bugs and problems to alexeyp@gmail.com. │
24└──────────────────────────────────────────────────────────────────────────────┘
25*/
26
27#pragma once
28
29#include <mutex>
30#include <sptk5/Strings.h>
31#include <sptk5/sptk.h>
32#include <sptk5/string_ext.h>
33
34namespace sptk {
35
46class SP_EXPORT CLocation
47{
51 mutable std::mutex m_mutex;
52
56 const char* m_file;
57
61 int m_line;
62
63
64public:
70 CLocation(const char* file, int line)
71 : m_file(file)
72 , m_line(line)
73 {
74 }
75
81 void set(const char* file, int line)
82 {
83 std::scoped_lock > lock(m_mutex);
84 m_file = file;
85 m_line = line;
86 }
87
91 const char* file() const
92 {
93 std::scoped_lock lock(m_mutex);
94 return m_file;
95 }
96
100 int line() const
101 {
102 std::scoped_lock lock(m_mutex);
103 return m_line;
104 }
105
110 {
111 std::scoped_lock lock(m_mutex);
112 return String(m_file) + "(" + int2string(m_line) + ")";
113 }
114
118 bool empty() const
119 {
120 std::scoped_lock lock(m_mutex);
121 return (m_file == NULL) && (m_line == 0);
122 }
123};
124
128} // namespace sptk
Location object.
Definition: Location.h:47
void set(const char *file, int line)
Modifies location.
Definition: Location.h:81
int line() const
Returns location line number.
Definition: Location.h:100
bool empty() const
Returns true if location is empty.
Definition: Location.h:118
String toString() const
Returns string presentation of location.
Definition: Location.h:109
const char * file() const
Returns location file name.
Definition: Location.h:91
CLocation(const char *file, int line)
Constructor.
Definition: Location.h:70
Definition: String.h:49
String SP_EXPORT int2string(int32_t)

Fri Oct 14 2022 09:58:32: SPTK 5.4.1