many fixes to audio file code, SMPTE offset now works correctly
[ardour.git] / libs / cassowary / cassowary / ClErrors.h
1 // $Id$
2 //
3 // Cassowary Incremental Constraint Solver
4 // Original Smalltalk Implementation by Alan Borning
5 // This C++ Implementation by Greg J. Badros, <gjb@cs.washington.edu>
6 // http://www.cs.washington.edu/homes/gjb
7 // (C) 1998, 1999 Greg J. Badros and Alan Borning
8 // See ../LICENSE for legal details regarding this software
9 //
10 // ClErrors.h
11
12 #ifndef ClErrors_H
13 #define ClErrors_H
14
15 #if defined(HAVE_CONFIG_H) && !defined(CONFIG_H_INCLUDED) && !defined(CONFIG_INLINE_H_INCLUDED)
16 #include <cassowary/config-inline.h>
17 #define CONFIG_INLINE_H_INCLUDED
18 #endif
19
20 #include "Cassowary.h"
21 #include "ClTypedefs.h"
22 #include <string>
23 #include <exception>
24
25 using std::string;
26 using std::exception;
27
28 class ExCLError : public exception {
29  public:
30   ExCLError() : _msg(0) { }
31   virtual ~ExCLError() throw() {}
32   virtual string description() const
33     { return "(ExCLError) An error has occured in CL"; }
34  protected:
35   char *_msg;
36 };
37
38 class ExCLInternalError : public ExCLError {
39  public:
40   ExCLInternalError(const char *sz)
41     { _msg = strdup(sz); }
42   virtual string description() const
43     { 
44       if (_msg) return _msg;
45       else return "(ExCLInternalError) An internal error has occurred"; 
46     }
47 };
48
49 class ExCLBadResolve : public ExCLError {
50  public:
51   ExCLBadResolve(const char *sz)
52     { _msg = strdup(sz); }
53   virtual string description() const
54     {
55       if (_msg) return _msg;
56       else return "(ExCLBadResolve) Number of resolve values did not match number of edit vars"; 
57     }
58 };
59
60 class ExCLEditMisuse : public ExCLError {
61  public:
62   ExCLEditMisuse(const char *sz)
63     { _msg = strdup(sz); }
64   virtual string description() const
65     {
66       if (_msg) return _msg;
67       return "(ExCLEditMisuse) Edit protocol usage violation"; 
68     }
69 };
70
71 class ExCLTooDifficult : public ExCLError {
72  public:
73   virtual string description() const
74     { return "(ExCLTooDifficult) The constraints are too difficult to solve"; }
75 };
76
77 class ExCLTooDifficultSpecial : public ExCLTooDifficult {
78  public:
79   ExCLTooDifficultSpecial(const char *sz)
80     { _msg = strdup(sz); }
81   virtual string description() const
82     {
83       if (_msg) return _msg;
84       else return "(ExCLTooDifficultSpecial) Solver requirements are not satisfied";
85     }
86 };
87
88 class ExCLReadOnlyNotAllowed : public ExCLTooDifficult {
89  public:
90   virtual string description() const
91   { return "(ExCLReadOnlyNotAllowed) The read-only annotation is not permitted by the solver"; }
92 };
93
94 class ExCLCycleNotAllowed : public ExCLTooDifficult {
95  public:
96   virtual string description() const
97   { return "(ExCLCycleNotAllowed) A cyclic constraint graph is not permitted by the solver"; }
98 };
99
100 class ExCLStrictInequalityNotAllowed : public ExCLTooDifficult {
101  public:
102   virtual string description() const
103   { return "(ExCLStrictInequalityNotAllowed) The strict inequality is not permitted by the solver"; }
104 };
105
106 class ExCLRequiredFailure : public ExCLError {
107  public:
108   virtual ~ExCLRequiredFailure() throw() {}
109   virtual string description() const
110     { return "(ExCLRequiredFailure) A required constraint cannot be satisfied"; }
111 };
112
113 class ExCLNotEnoughStays : public ExCLError {
114  public:
115   virtual string description() const
116     { return "(ExCLNotEnoughStays) There are not enough stays to give specific values to every variable"; }
117 };
118
119 class ExCLNonlinearExpression : public ExCLError {
120  public:
121   virtual string description() const
122     { return "(ExCLNonlinearExpression) The resulting expression would be nonlinear"; }
123 };
124   
125 class ExCLConstraintNotFound : public ExCLError {
126  public:
127   virtual string description() const
128     { return "(ExCLConstraintNotFound) Tried to remove a constraint that was never added"; }
129 };
130
131 class ExCLParseError : public ExCLError {
132  public:
133   virtual ~ExCLParseError() throw() {}
134   virtual string description() const
135     { return "(ExCLParseError)"; }
136 };
137
138 class ExCLParseErrorMisc : public ExCLParseError {
139  public:
140   ExCLParseErrorMisc(const string &s) 
141       : _msg("(ExCLParseError) ")
142     { _msg += s; }
143   virtual ~ExCLParseErrorMisc() throw() {}
144   virtual string description() const
145     { return _msg; }
146  private:
147   string _msg;
148 };
149
150 class ExCLParseErrorBadIdentifier : public ExCLParseError {
151  public:
152   ExCLParseErrorBadIdentifier(const string &id) 
153       : _msg("(ExCLParseErrorBadIdentifier) Did not recognize identifier '")
154     { 
155       _msg += id;
156       _msg += "'";
157     }
158   virtual ~ExCLParseErrorBadIdentifier() throw() {}
159   virtual string description() const
160     { return _msg; }
161  private:
162   string _msg;
163 };
164
165 class ExCLRequiredFailureWithExplanation : public ExCLRequiredFailure 
166 {
167 public:
168   virtual ~ExCLRequiredFailureWithExplanation() throw() {} 
169   virtual string description() const
170     { return "(ExCLRequiredFailureWithExplanation) A required constraint cannot be satisfied"; }
171   virtual void AddConstraint(const ClConstraint *cnExpl)
172     { _explanation.insert(cnExpl); }
173   virtual const ClConstraintSet & explanation() const
174     { return _explanation; }
175 protected:
176   ClConstraintSet _explanation;
177 };
178
179 #endif // ClErrors_H