Issue.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #pragma once
  2. #include <lanelet2_core/Forward.h>
  3. #include <sstream>
  4. #include <vector>
  5. namespace lanelet {
  6. namespace validation {
  7. enum class Severity { Error, Warning, Info };
  8. enum class Primitive { Point, LineString, Polygon, Lanelet, Area, RegulatoryElement, Primitive };
  9. inline const char* toString(Severity severity) {
  10. switch (severity) {
  11. case Severity::Error:
  12. return "Error";
  13. case Severity::Warning:
  14. return "Warning";
  15. case Severity::Info:
  16. return "info";
  17. }
  18. return "";
  19. }
  20. inline const char* toString(Primitive primitive) {
  21. switch (primitive) {
  22. case Primitive::Point:
  23. return "point";
  24. case Primitive::LineString:
  25. return "linestring";
  26. case Primitive::Polygon:
  27. return "polygon";
  28. case Primitive::Lanelet:
  29. return "lanelet";
  30. case Primitive::Area:
  31. return "area";
  32. case Primitive::RegulatoryElement:
  33. return "regulatory element";
  34. case Primitive::Primitive:
  35. return "primitive";
  36. }
  37. return "";
  38. }
  39. struct Issue {
  40. Issue() = default;
  41. Issue(Severity severity, std::string message) : severity{severity}, message{std::move(message)} {}
  42. Issue(Severity severity, Primitive primitive, Id id, std::string message)
  43. : severity{severity}, primitive{primitive}, id{id}, message{std::move(message)} {}
  44. std::string buildReport() const {
  45. std::stringstream ss;
  46. ss << toString(severity) << ": ";
  47. if (id != InvalId) {
  48. ss << toString(primitive) << " " << std::to_string(id) << " ";
  49. }
  50. ss << message;
  51. return ss.str();
  52. }
  53. Severity severity{Severity::Error}; //!< Severity class of issue
  54. Primitive primitive{Primitive::Point}; //!< Type of primitive that caused the issue
  55. Id id{InvalId}; //!< the id of primitive that caused the issue
  56. std::string message; //!< Message to be displayed
  57. };
  58. using Issues = std::vector<Issue>;
  59. } // namespace validation
  60. } // namespace lanelet