-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.hpp
More file actions
41 lines (35 loc) · 1.14 KB
/
util.hpp
File metadata and controls
41 lines (35 loc) · 1.14 KB
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
#ifndef UTIL_HPP
#define UTIL_HPP
#include <cstdint>
#include <exception>
#include <boost/format.hpp>
namespace hexutil {
/// A class to represent a source code location.
class Location {
size_t line, position;
bool null;
public:
Location() : line(0), position(0), null(true) {}
Location(size_t line, size_t position) : line(line), position(position), null(false) {}
std::string str() const {
return null ? "no location" : (boost::format("line %d:%d") % line % position).str();
}
bool isNull() const { return null; }
};
/// General error class with location information.
class Error : public std::runtime_error {
Location location;
public:
Error(const std::string &what) :
std::runtime_error(what) {}
Error(const char *what) :
std::runtime_error(what) {}
Error(Location location, const std::string &what) :
std::runtime_error(what), location(location) {}
Error(Location location, const char *what) :
std::runtime_error(what), location(location) {}
bool hasLocation() const { return !location.isNull(); }
const Location &getLocation() const { return location; }
};
} // End namespace hexutil
#endif // UTIL_HPP