| 1 |
/*----------------------------------------------------------------------------- |
| 2 |
| Copyright (c) 2013-2026, 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 |
|
| 14 |
namespace kiwi |
| 15 |
{ |
| 16 |
|
| 17 |
class UnsatisfiableConstraint : public std::exception |
| 18 |
{ |
| 19 |
|
| 20 |
public: |
| 21 |
UnsatisfiableConstraint(Constraint constraint) : m_constraint(std::move(constraint)) {} |
| 22 |
|
| 23 |
~UnsatisfiableConstraint() noexcept {} |
| 24 |
|
| 25 |
const char *what() const noexcept |
| 26 |
{ |
| 27 |
return "The constraint can not be satisfied."; |
| 28 |
} |
| 29 |
|
| 30 |
const Constraint &constraint() const |
| 31 |
{ |
| 32 |
return m_constraint; |
| 33 |
} |
| 34 |
|
| 35 |
private: |
| 36 |
Constraint m_constraint; |
| 37 |
}; |
| 38 |
|
| 39 |
class UnknownConstraint : public std::exception |
| 40 |
{ |
| 41 |
|
| 42 |
public: |
| 43 |
UnknownConstraint(Constraint constraint) : m_constraint(std::move(constraint)) {} |
| 44 |
|
| 45 |
~UnknownConstraint() noexcept {} |
| 46 |
|
| 47 |
const char *what() const noexcept |
| 48 |
{ |
| 49 |
return "The constraint has not been added to the solver."; |
| 50 |
} |
| 51 |
|
| 52 |
const Constraint &constraint() const |
| 53 |
{ |
| 54 |
return m_constraint; |
| 55 |
} |
| 56 |
|
| 57 |
private: |
| 58 |
Constraint m_constraint; |
| 59 |
}; |
| 60 |
|
| 61 |
class DuplicateConstraint : public std::exception |
| 62 |
{ |
| 63 |
|
| 64 |
public: |
| 65 |
DuplicateConstraint(Constraint constraint) : m_constraint(std::move(constraint)) {} |
| 66 |
|
| 67 |
~DuplicateConstraint() noexcept {} |
| 68 |
|
| 69 |
const char *what() const noexcept |
| 70 |
{ |
| 71 |
return "The constraint has already been added to the solver."; |
| 72 |
} |
| 73 |
|
| 74 |
const Constraint &constraint() const |
| 75 |
{ |
| 76 |
return m_constraint; |
| 77 |
} |
| 78 |
|
| 79 |
private: |
| 80 |
Constraint m_constraint; |
| 81 |
}; |
| 82 |
|
| 83 |
class UnknownEditVariable : public std::exception |
| 84 |
{ |
| 85 |
|
| 86 |
public: |
| 87 |
UnknownEditVariable(Variable variable) : m_variable(std::move(variable)) {} |
| 88 |
|
| 89 |
~UnknownEditVariable() noexcept {} |
| 90 |
|
| 91 |
const char *what() const noexcept |
| 92 |
{ |
| 93 |
return "The edit variable has not been added to the solver."; |
| 94 |
} |
| 95 |
|
| 96 |
const Variable &variable() const |
| 97 |
{ |
| 98 |
return m_variable; |
| 99 |
} |
| 100 |
|
| 101 |
private: |
| 102 |
Variable m_variable; |
| 103 |
}; |
| 104 |
|
| 105 |
class DuplicateEditVariable : public std::exception |
| 106 |
{ |
| 107 |
|
| 108 |
public: |
| 109 |
DuplicateEditVariable(Variable variable) : m_variable(std::move(variable)) {} |
| 110 |
|
| 111 |
~DuplicateEditVariable() noexcept {} |
| 112 |
|
| 113 |
const char *what() const noexcept |
| 114 |
{ |
| 115 |
return "The edit variable has already been added to the solver."; |
| 116 |
} |
| 117 |
|
| 118 |
const Variable &variable() const |
| 119 |
{ |
| 120 |
return m_variable; |
| 121 |
} |
| 122 |
|
| 123 |
private: |
| 124 |
Variable m_variable; |
| 125 |
}; |
| 126 |
|
| 127 |
class BadRequiredStrength : public std::exception |
| 128 |
{ |
| 129 |
|
| 130 |
public: |
| 131 |
BadRequiredStrength() {} |
| 132 |
|
| 133 |
~BadRequiredStrength() noexcept {} |
| 134 |
|
| 135 |
const char *what() const noexcept |
| 136 |
{ |
| 137 |
return "A required strength cannot be used in this context."; |
| 138 |
} |
| 139 |
}; |
| 140 |
|
| 141 |
class InternalSolverError : public std::exception |
| 142 |
{ |
| 143 |
|
| 144 |
public: |
| 145 |
InternalSolverError() : m_msg("An internal solver error ocurred.") {} |
| 146 |
|
| 147 |
InternalSolverError(const char *msg) : m_msg(msg) {} |
| 148 |
|
| 149 |
InternalSolverError(std::string msg) : m_msg(std::move(msg)) {} |
| 150 |
|
| 151 |
~InternalSolverError() noexcept {} |
| 152 |
|
| 153 |
const char *what() const noexcept |
| 154 |
{ |
| 155 |
return m_msg.c_str(); |
| 156 |
} |
| 157 |
|
| 158 |
private: |
| 159 |
std::string m_msg; |
| 160 |
}; |
| 161 |
|
| 162 |
} // namespace kiwi |