OdbDesignLib
OdbDesign ODB++ Parsing Library
parse_error.h
1 #pragma once
2 
3 #include <exception>
4 #include <string>
5 #include <filesystem>
6 #include "parse_info.h"
7 
8 namespace Odb::Lib::FileModel
9 {
10 
11 #ifndef throw_parse_error
12 # define throw_parse_error(dataFile, dataLine, dataToken, dataLineNumber) throw parse_error(dataFile, dataLine, dataToken, dataLineNumber, __LINE__, __FILE__)
13 #endif
14 
15  class parse_error : public std::exception
16  {
17  public:
18 
19  parse_error(std::filesystem::path dataFile, const std::string& szDataLine, const std::string& szDataToken, int dataLineNumber, int sourceLine, const char* szSourceFile)
20  : m_parseInfo(dataFile, szDataLine, szDataToken, dataLineNumber), sourceLine(sourceLine), sourceFile(szSourceFile)
21  {
22  }
23 
24  parse_error(const char* szDataFile, const char* szDataLine, const char* szDataToken, int sourceLine, const char* szSourceFile)
25  : parse_error(szDataFile, szDataLine, szDataToken, -1, sourceLine, szSourceFile)
26  {
27  }
28 
29  parse_error(const char* szDataFile, const char* szDataLine, int sourceLine, const char* szSourceFile)
30  : parse_error(szDataFile, szDataLine, "", -1, sourceLine, szSourceFile)
31  {
32  }
33 
34  parse_error(const char* szDataFile, int sourceLine, const char* szSourceFile)
35  : parse_error(szDataFile, "", "", -1, sourceLine, szSourceFile)
36  {
37  }
38 
39  std::string toString(const std::string& message = "") const;
40 
41  const parse_info& getParseInfo() const;
42 
43  [[nodiscard]] char const* what() const noexcept;
44 
45  private:
46  // data file
47  const parse_info m_parseInfo;
48 
49  // source file
50  int sourceLine;
51  std::filesystem::path sourceFile;
52 
53  constexpr inline static const char WHAT_STR[] = "Parse error";
54 
55  };
56 }