summaryrefslogtreecommitdiff
path: root/libs/cassowary/cassowary/ClErrors.h
blob: 867c578dbcadb52621917b4c752daff6c4d38a5c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
// $Id$
//
// Cassowary Incremental Constraint Solver
// Original Smalltalk Implementation by Alan Borning
// This C++ Implementation by Greg J. Badros, <gjb@cs.washington.edu>
// http://www.cs.washington.edu/homes/gjb
// (C) 1998, 1999 Greg J. Badros and Alan Borning
// See ../LICENSE for legal details regarding this software
//
// ClErrors.h

#ifndef ClErrors_H
#define ClErrors_H

#if defined(HAVE_CONFIG_H) && !defined(CONFIG_H_INCLUDED) && !defined(CONFIG_INLINE_H_INCLUDED)
#include <cassowary/config-inline.h>
#define CONFIG_INLINE_H_INCLUDED
#endif

#include "Cassowary.h"
#include "ClTypedefs.h"
#include <string>
#include <exception>

using std::string;
using std::exception;

class ExCLError : public exception {
 public:
  ExCLError() : _msg(0) { }
  virtual ~ExCLError() throw() {}
  virtual string description() const
    { return "(ExCLError) An error has occured in CL"; }
 protected:
  char *_msg;
};

class ExCLInternalError : public ExCLError {
 public:
  ExCLInternalError(const char *sz)
    { _msg = strdup(sz); }
  virtual string description() const
    { 
      if (_msg) return _msg;
      else return "(ExCLInternalError) An internal error has occurred"; 
    }
};

class ExCLBadResolve : public ExCLError {
 public:
  ExCLBadResolve(const char *sz)
    { _msg = strdup(sz); }
  virtual string description() const
    {
      if (_msg) return _msg;
      else return "(ExCLBadResolve) Number of resolve values did not match number of edit vars"; 
    }
};

class ExCLEditMisuse : public ExCLError {
 public:
  ExCLEditMisuse(const char *sz)
    { _msg = strdup(sz); }
  virtual string description() const
    {
      if (_msg) return _msg;
      return "(ExCLEditMisuse) Edit protocol usage violation"; 
    }
};

class ExCLTooDifficult : public ExCLError {
 public:
  virtual string description() const
    { return "(ExCLTooDifficult) The constraints are too difficult to solve"; }
};

class ExCLTooDifficultSpecial : public ExCLTooDifficult {
 public:
  ExCLTooDifficultSpecial(const char *sz)
    { _msg = strdup(sz); }
  virtual string description() const
    {
      if (_msg) return _msg;
      else return "(ExCLTooDifficultSpecial) Solver requirements are not satisfied";
    }
};

class ExCLReadOnlyNotAllowed : public ExCLTooDifficult {
 public:
  virtual string description() const
  { return "(ExCLReadOnlyNotAllowed) The read-only annotation is not permitted by the solver"; }
};

class ExCLCycleNotAllowed : public ExCLTooDifficult {
 public:
  virtual string description() const
  { return "(ExCLCycleNotAllowed) A cyclic constraint graph is not permitted by the solver"; }
};

class ExCLStrictInequalityNotAllowed : public ExCLTooDifficult {
 public:
  virtual string description() const
  { return "(ExCLStrictInequalityNotAllowed) The strict inequality is not permitted by the solver"; }
};

class ExCLRequiredFailure : public ExCLError {
 public:
  virtual ~ExCLRequiredFailure() throw() {}
  virtual string description() const
    { return "(ExCLRequiredFailure) A required constraint cannot be satisfied"; }
};

class ExCLNotEnoughStays : public ExCLError {
 public:
  virtual string description() const
    { return "(ExCLNotEnoughStays) There are not enough stays to give specific values to every variable"; }
};

class ExCLNonlinearExpression : public ExCLError {
 public:
  virtual string description() const
    { return "(ExCLNonlinearExpression) The resulting expression would be nonlinear"; }
};
  
class ExCLConstraintNotFound : public ExCLError {
 public:
  virtual string description() const
    { return "(ExCLConstraintNotFound) Tried to remove a constraint that was never added"; }
};

class ExCLParseError : public ExCLError {
 public:
  virtual ~ExCLParseError() throw() {}
  virtual string description() const
    { return "(ExCLParseError)"; }
};

class ExCLParseErrorMisc : public ExCLParseError {
 public:
  ExCLParseErrorMisc(const string &s) 
      : _msg("(ExCLParseError) ")
    { _msg += s; }
  virtual ~ExCLParseErrorMisc() throw() {}
  virtual string description() const
    { return _msg; }
 private:
  string _msg;
};

class ExCLParseErrorBadIdentifier : public ExCLParseError {
 public:
  ExCLParseErrorBadIdentifier(const string &id) 
      : _msg("(ExCLParseErrorBadIdentifier) Did not recognize identifier '")
    { 
      _msg += id;
      _msg += "'";
    }
  virtual ~ExCLParseErrorBadIdentifier() throw() {}
  virtual string description() const
    { return _msg; }
 private:
  string _msg;
};

class ExCLRequiredFailureWithExplanation : public ExCLRequiredFailure 
{
public:
  virtual ~ExCLRequiredFailureWithExplanation() throw() {} 
  virtual string description() const
    { return "(ExCLRequiredFailureWithExplanation) A required constraint cannot be satisfied"; }
  virtual void AddConstraint(const ClConstraint *cnExpl)
    { _explanation.insert(cnExpl); }
  virtual const ClConstraintSet & explanation() const
    { return _explanation; }
protected:
  ClConstraintSet _explanation;
};

#endif // ClErrors_H