46 lines
852 B
C++
46 lines
852 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) const;
|
|
|
|
template <typename T>
|
|
void error(std::stringstream const& what) const;
|
|
|
|
private:
|
|
std::filesystem::path m_origin;
|
|
int m_line = 0;
|
|
};
|
|
|
|
template <typename T>
|
|
void Loc::error(std::string const& what) const
|
|
{
|
|
std::stringstream ss;
|
|
ss << m_origin.string() << ": ERROR " << what;
|
|
|
|
throw T {ss.str() };
|
|
}
|
|
|
|
template <typename T>
|
|
void Loc::error(std::stringstream const& what) const
|
|
{
|
|
error<T>(what.str());
|
|
}
|
|
}
|
|
|
|
#endif
|