This repository has been archived on 2024-03-07. You can view files and clone it, but cannot push or open issues/pull-requests.
wongola/lib/Loc.hpp

46 lines
828 B
C++
Raw Normal View History

#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