errors.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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 COPYING.txt, 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( const Constraint& constraint ) :
  19. m_constraint( constraint ) {}
  20. ~UnsatisfiableConstraint() throw() {}
  21. const char* what() const throw()
  22. {
  23. return "The constraint can not be satisfied.";
  24. }
  25. const Constraint& constraint() const
  26. {
  27. return m_constraint;
  28. }
  29. private:
  30. Constraint m_constraint;
  31. };
  32. class UnknownConstraint : public std::exception
  33. {
  34. public:
  35. UnknownConstraint( const Constraint& constraint ) :
  36. m_constraint( constraint ) {}
  37. ~UnknownConstraint() throw() {}
  38. const char* what() const throw()
  39. {
  40. return "The constraint has not been added to the solver.";
  41. }
  42. const Constraint& constraint() const
  43. {
  44. return m_constraint;
  45. }
  46. private:
  47. Constraint m_constraint;
  48. };
  49. class DuplicateConstraint : public std::exception
  50. {
  51. public:
  52. DuplicateConstraint( const Constraint& constraint ) :
  53. m_constraint( constraint ) {}
  54. ~DuplicateConstraint() throw() {}
  55. const char* what() const throw()
  56. {
  57. return "The constraint has already been added to the solver.";
  58. }
  59. const Constraint& constraint() const
  60. {
  61. return m_constraint;
  62. }
  63. private:
  64. Constraint m_constraint;
  65. };
  66. class UnknownEditVariable : public std::exception
  67. {
  68. public:
  69. UnknownEditVariable( const Variable& variable ) :
  70. m_variable( variable ) {}
  71. ~UnknownEditVariable() throw() {}
  72. const char* what() const throw()
  73. {
  74. return "The edit variable has not been added to the solver.";
  75. }
  76. const Variable& variable() const
  77. {
  78. return m_variable;
  79. }
  80. private:
  81. Variable m_variable;
  82. };
  83. class DuplicateEditVariable : public std::exception
  84. {
  85. public:
  86. DuplicateEditVariable( const Variable& variable ) :
  87. m_variable( variable ) {}
  88. ~DuplicateEditVariable() throw() {}
  89. const char* what() const throw()
  90. {
  91. return "The edit variable has already been added to the solver.";
  92. }
  93. const Variable& variable() const
  94. {
  95. return m_variable;
  96. }
  97. private:
  98. Variable m_variable;
  99. };
  100. class BadRequiredStrength : public std::exception
  101. {
  102. public:
  103. BadRequiredStrength() {}
  104. ~BadRequiredStrength() throw() {}
  105. const char* what() const throw()
  106. {
  107. return "A required strength cannot be used in this context.";
  108. }
  109. };
  110. class InternalSolverError : public std::exception
  111. {
  112. public:
  113. InternalSolverError() : m_msg( "An internal solver error ocurred." ) {}
  114. InternalSolverError( const char* msg ) : m_msg( msg ) {}
  115. InternalSolverError( const std::string& msg ) : m_msg( msg ) {}
  116. ~InternalSolverError() throw() {}
  117. const char* what() const throw()
  118. {
  119. return m_msg.c_str();
  120. }
  121. private:
  122. std::string m_msg;
  123. };
  124. } // namespace kiwi