46 lines
828 B
C++
46 lines
828 B
C++
|
#ifndef wg_LOC_HPP
|
||
|
#define wg_LOC_HPP
|
||
|
|
||
|
#include "commons.hpp"
|
||
|
#include <sstream>
|
||
|
|
||
|
namespace wg
|
||
|
{
|
||
|
class Loc
|
||
|
{
|
||
|
public:
|
||
|
explicit Loc(std::filesystem::path origin = "???", int line = 0);
|
||
|
virtual ~Loc();
|
||
|
|
||
|
std::filesystem::path origin() const { return m_origin; }
|
||
|
int line() const { return m_line; }
|
||
|
|
||
|
template <typename T>
|
||
|
void error(std::string const& what);
|
||
|
|
||
|
template <typename T>
|
||
|
void error(std::stringstream const& what);
|
||
|
|
||
|
private:
|
||
|
std::filesystem::path m_origin;
|
||
|
int m_line = 0;
|
||
|
};
|
||
|
|
||
|
template <typename T>
|
||
|
void Loc::error(std::string const& what)
|
||
|
{
|
||
|
std::stringstream ss;
|
||
|
ss << m_origin.string() << ": ERROR " << what;
|
||
|
|
||
|
throw T {ss.str() };
|
||
|
}
|
||
|
|
||
|
template <typename T>
|
||
|
void Loc::error(std::stringstream const& what)
|
||
|
{
|
||
|
error<T>(what.str());
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#endif
|