errors.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /*-----------------------------------------------------------------------------
  2. | Copyright (c) 2013-2017, Nucleic Development Team.
  3. |
  4. | Distributed under the terms of the Modified BSD License.
  5. |
  6. | The full license is in the file LICENSE, distributed with this software.
  7. |----------------------------------------------------------------------------*/
  8. #pragma once
  9. #include <exception>
  10. #include <string>
  11. #include "constraint.h"
  12. #include "variable.h"
  13. namespace kiwi
  14. {
  15. class UnsatisfiableConstraint : public std::exception
  16. {
  17. public:
  18. UnsatisfiableConstraint(Constraint constraint) : m_constraint(std::move(constraint)) {}
  19. ~UnsatisfiableConstraint() noexcept {}
  20. const char *what() const noexcept
  21. {
  22. return "The constraint can not be satisfied.";
  23. }
  24. const Constraint &constraint() const
  25. {
  26. return m_constraint;
  27. }
  28. private:
  29. Constraint m_constraint;
  30. };
  31. class UnknownConstraint : public std::exception
  32. {
  33. public:
  34. UnknownConstraint(Constraint constraint) : m_constraint(std::move(constraint)) {}
  35. ~UnknownConstraint() noexcept {}
  36. const char *what() const noexcept
  37. {
  38. return "The constraint has not been added to the solver.";
  39. }
  40. const Constraint &constraint() const
  41. {
  42. return m_constraint;
  43. }
  44. private:
  45. Constraint m_constraint;
  46. };
  47. class DuplicateConstraint : public std::exception
  48. {
  49. public:
  50. DuplicateConstraint(Constraint constraint) : m_constraint(std::move(constraint)) {}
  51. ~DuplicateConstraint() noexcept {}
  52. const char *what() const noexcept
  53. {
  54. return "The constraint has already been added to the solver.";
  55. }
  56. const Constraint &constraint() const
  57. {
  58. return m_constraint;
  59. }
  60. private:
  61. Constraint m_constraint;
  62. };
  63. class UnknownEditVariable : public std::exception
  64. {
  65. public:
  66. UnknownEditVariable(Variable variable) : m_variable(std::move(variable)) {}
  67. ~UnknownEditVariable() noexcept {}
  68. const char *what() const noexcept
  69. {
  70. return "The edit variable has not been added to the solver.";
  71. }
  72. const Variable &variable() const
  73. {
  74. return m_variable;
  75. }
  76. private:
  77. Variable m_variable;
  78. };
  79. class DuplicateEditVariable : public std::exception
  80. {
  81. public:
  82. DuplicateEditVariable(Variable variable) : m_variable(std::move(variable)) {}
  83. ~DuplicateEditVariable() noexcept {}
  84. const char *what() const noexcept
  85. {
  86. return "The edit variable has already been added to the solver.";
  87. }
  88. const Variable &variable() const
  89. {
  90. return m_variable;
  91. }
  92. private:
  93. Variable m_variable;
  94. };
  95. class BadRequiredStrength : public std::exception
  96. {
  97. public:
  98. BadRequiredStrength() {}
  99. ~BadRequiredStrength() noexcept {}
  100. const char *what() const noexcept
  101. {
  102. return "A required strength cannot be used in this context.";
  103. }
  104. };
  105. class InternalSolverError : public std::exception
  106. {
  107. public:
  108. InternalSolverError() : m_msg("An internal solver error ocurred.") {}
  109. InternalSolverError(const char *msg) : m_msg(msg) {}
  110. InternalSolverError(std::string msg) : m_msg(std::move(msg)) {}
  111. ~InternalSolverError() noexcept {}
  112. const char *what() const noexcept
  113. {
  114. return m_msg.c_str();
  115. }
  116. private:
  117. std::string m_msg;
  118. };
  119. } // namespace kiwi