CoCoALib-0.9905 date: 23 May 2007


error.H

Go to the documentation of this file.
00001 #ifndef CoCoA_error_H
00002 #define CoCoA_error_H
00003 
00004 //   Copyright (c)  2005  John Abbott
00005 
00006 //   This file is part of the source of CoCoALib, the CoCoA Library.
00007 
00008 //   CoCoALib is free software; you can redistribute it and/or modify
00009 //   it under the terms of the GNU General Public License (version 2)
00010 //   as published by the Free Software Foundation.  A copy of the full
00011 //   licence may be found in the file COPYING in this directory.
00012 
00013 //   CoCoALib is distributed in the hope that it will be useful,
00014 //   but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 //   GNU General Public License for more details.
00017 
00018 //   You should have received a copy of the GNU General Public License
00019 //   along with CoCoA; if not, write to the Free Software
00020 //   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021 
00022 
00023 
00024 // All errors should be thrown by calling the function "error"
00025 // as this makes debugging easier and doesn't adversely affect
00026 // run-time performance.  The function "error" will print a brief
00027 // message if CoCoA_DEBUG is set, and it will throw the error object.
00028 
00029 
00030 #include <exception>
00031 //using std::exception;
00032 #include <string>
00033 //using std::string;
00034 #include <iosfwd>
00035 //using std::ostream;
00036 
00037 namespace CoCoA
00038 {
00039 
00040   namespace ERR
00041   {
00042     struct message
00043     {
00044       explicit message(const char* const mesg): myMessage(mesg==0?"(no message)":mesg) {};
00045       bool operator<(const message&) const;
00046       bool operator==(const message& rhs) const;
00047       bool operator!=(const message& rhs) const;
00048       const char* const myMessage;
00049     };
00050     typedef message code;
00051 
00052     extern const message
00053             LANGUAGE,        // not really an error message, just the name of the language
00054             nonstandard,     // to create a nonstandard error message
00055             UNKNOWN,         // to signal an error of unknown type -- can this ever be used???
00056             ArgTooBig,       // argument too large in a numerical function
00057             AssertFail,      // an assertion failed
00058             BadArg,          // the arg(s) given are unsuitable
00059             BadArraySize,    // unsuitable array size (incompatible with other arguments)
00060             BadCheckedCast,  // checked cast failed
00061             BadCodomain,     // supplied RingHom has wrong codomain
00062             BadColIndex,     // column index too large in a matrix
00063             BadCompose,      // attempt to compose maps with differing domain and codomain
00064             BadComptIndex,   // index too large accessing component of ModuleElem
00065             BadDegIndex,     // index too large accessing degree component
00066             BadIndetIndex,   // indeterminate index too large in a polynomial ring
00067             BadIndetNames,   // duplicate indet names or varied number of indices for a single name
00068             BadInducingHom,  // inducing hom has wrong domain
00069             BadInducingHom2, // inducing hom has wrong codomain
00070             BadInducingHomKer,// inducing hom has unsuitable kernel
00071             BadMatrixSetEntry,// attempt to set a matrix entry where this is forbidden
00072             BadMatrixSize,   // matrix of the wrong size for the requested operation
00073             BadNumBase,      // base for number conversion must be between 2 and 36 (incl)
00074             BadNumIndets,    // wrong number of indet names when creating a PPMonoid or PolyRing
00075             BadPPMonoid,     // PPMonoid supplied is not of the right type
00076             BadProbability,  // probability P must satisfy  0 <= P <= 1
00077             BadPwrZero,      // attempt to compute 0^N where N is not strictly positive
00078             BadPolyRingHomImages,// unsuitable indet images for creating PolyRing hom (wrong number or wrong ring)
00079             BadQuot,         // attempt to compute a quotient which does not exist in a given ring/monoid
00080             BadQuotRing,     // attempt to quotient by ideal(1)
00081             BadRing,         // used ring does not have desired properties
00082             BadRingHomArg,   // argument given to a RingHom is in the wrong ring
00083             BadRingHomArg2,  // argument given to a partial RingHom is outside the domain
00084             BadRowIndex,     // row index too large in a matrix
00085             BadSmallFpChar,  // characteristic (for small finite field) too large or not prime
00086             BadSymbolHead,   // invalid symbolic name head (with illegal characters)
00087             BadSymbolIndex,  // symbolic name does not have that many indices
00088             BadSymbolRange,  // incompatible names given to range
00089             BLASFailed,      // a BLAS function failed
00090             CanonicalHomFail,// Unable to construct canonical homomorphism
00091             ConstMatEntry,   // cannot assign to constant matrix entry
00092             DeadMemPool,     // attempt to use a MemPool after it has been destroyed
00093             DivByZero,       // division by zero or a zero-divisor
00094             ExpTooBig,       // exponent is too large
00095             GlobalManager1,  // no GlobalManager object has been created
00096             GlobalManager2,  // may not create more than one GlobalManager object
00097             IdealNotInRing,  // incompatible ring and ideal
00098             InsuffPrec,      // insufficient precision when using RingFloat values
00099             IntDivByNeg,     // integer division/remainder by negative divisor
00100             LapackFailed,    // a Lapack driver failed
00101             LogZero,         // Cannot compute log of zero
00102             MemPoolZero,     // Cannot use MemPool to manage blocks of zero size
00103             MissNumLibs,     // Numerical libraries not configured in
00104             MixedCoeffRings, // arithmetic operation between polys with different coeff rings
00105             MixedDegrees,    // arithmetic operation between incompatible degrees
00106             MixedModules,    // arithmetic operation between elements of different modules
00107             MixedPolyIters,  // comparison between iterators over different polys
00108             MixedPPMs,       // arithmetic operation between elements of different PPMonoids
00109             MixedRings,      // arithmetic operation between elements of different rings
00110             NegExp,          // negative exponent
00111             NoGlobalMgr,     // GlobalManager must be created before using CoCoALib
00112             NotCommutative,  // ring must be commutative
00113             NotEFGModule,    // module must be EFG, but is not
00114             NotElemFrF,      // operation makes sense only for elements of a fraction field
00115             NotElemGCDDomain,// operation makes sense only for elements of a GCD domain
00116             NotElemPolyRing, // operation makes sense only for elements of a polynomial ring
00117             NotElemQuotientRing,// operation makes sense only for elements of a quotient ring
00118             NotElemSparsePolyRing,// operation makes sense only for elements of a sparse polynomial ring
00119             NotField,        // ring must be a field, but is not
00120             NotFracField,    // ring must be a FractionField, but is not
00121             NYI,             // NOT YET IMPLEMENTED
00122             NotFreeModule,   // module must be free, but is not
00123             NotFullRank,     // matrix must be full rank, but is not
00124             NotGCDDomain,    // ring must be a GCD domain, but is not
00125             NotGradedModule, // module must be graded, but is not
00126             NotIndet,        // poly should be an indeterminate
00127             NotIntegralDomain,// ring must be an integral domain, but is not
00128             NotInvMatrix,    // matrix is not invertible
00129             NotNonNegativeGrading,// grading is not non-negative
00130             NotOrdDom,       // ring must be ordered, but is not
00131             NotPolyRing,     // ring must be a polynomial ring, but is not
00132             NotPositiveGrading,// grading is not positive
00133             NotQuotientRing, // ring must be a quotient ring, but is not
00134             NotRingFloat,    // operation valid only over RingFloat
00135             NotRingZ,        // ring must be the ring of integers, but is not
00136             NotSparsePolyRing,// ring must be a sparse polynomial ring, but is not
00137             NotSquareMatrix, // matrix must be square, but is not
00138             NotTermOrdering, // ordering is not a term-ordering
00139             NotTrueGCDDomain,// ring must be a GCD domain (but not a field), but is not
00140             NotUnit,         // operation is valid only for invertible elements
00141             PolyIterEnded,   // attempt to use an off-the-end iterator
00142             PPOrder,         // PP is not in the right order
00143             ZeroCoeff,       // coefficient must be non-zero
00144             ZeroModulus,     // numerical operation specified a zero modulus
00145             ZeroPoly,        // non-zero polynomial required
00146             SERIOUS;         // execution should never have reached here
00147   }
00148 
00149   /*-----------------------------------------------------------------*/
00150   /** \include error.txt  */
00151   /*-----------------------------------------------------------------*/
00152   class ErrorInfo: public std::exception
00153   {
00154   public:
00155     ErrorInfo(const std::string& mesg, const std::string& func);
00156     ErrorInfo(const std::string& mesg, const std::string& func, const char* file, unsigned long line);
00157     ErrorInfo(ERR::code id, const std::string& func);
00158     ErrorInfo(ERR::code id, const std::string& func, const char* file, unsigned long line);
00159     ~ErrorInfo() throw() {}
00160     const ERR::code& code() const { return myCode; }
00161     const char* what() const throw() { return myMessage.c_str(); }
00162   private: // Data members
00163     friend void ANNOUNCE(const ErrorInfo& err);
00164     const ERR::code myCode;
00165     const std::string myMessage;
00166     const std::string myContext;
00167     const std::string myFile;
00168     const unsigned long myLine;
00169   };
00170 
00171   std::ostream& operator<<(std::ostream& out, const ErrorInfo& err);
00172   void ANNOUNCE(const ErrorInfo& err);
00173   void error(const ErrorInfo& err);
00174 
00175 
00176   namespace ErrorLanguage
00177   {
00178     void english(); // Set english as the language for error messages.
00179     void italian(); // Set italian as the language for error messages.
00180   }
00181 
00182 
00183 } // end of namespace CoCoA
00184 
00185 // Macro: using this allows the file and line number to be reported in the error message.
00186 #define CoCoA_ERROR(code, func) ::CoCoA::error(::CoCoA::ErrorInfo(code, func, __FILE__, __LINE__))
00187 
00188 
00189 
00190 // RCS header/log in the next few lines.
00191 // $Header: /Volumes/Home/cocoa/cvs-repository/CoCoALib-0.99/include/CoCoA/error.H,v 1.3 2007/05/21 12:57:28 abbott Exp $
00192 // $Log: error.H,v $
00193 // Revision 1.3  2007/05/21 12:57:28  abbott
00194 // New class for passing machine integers as args; includes some simple
00195 // operations on machine integers (cmp, gcd, IsNegative,...).  Operations
00196 // between ZZ and machine integers modified to use the new class.  Inexact
00197 // integer division (of a ZZ) by a negative value now triggers an error;
00198 // new error for reporting inexact integer division by a negative value.
00199 //
00200 // Revision 1.2  2007/03/28 10:06:13  abbott
00201 // Now gives error when you use RingZ() or RingQ() without creating GlobalManager.
00202 //
00203 // Revision 1.1.1.1  2007/03/09 15:16:11  abbott
00204 // Imported files
00205 //
00206 // Revision 1.13  2007/03/08 11:07:12  cocoa
00207 // Made pseudo ctors for polynomial rings more uniform.  This allowed me to
00208 // remove an include of CoCoA/symbol.H  from the RingDistrM*.H files, but then
00209 // I had to put the include in several .C files.
00210 //
00211 // Revision 1.12  2007/03/05 21:34:36  cocoa
00212 // Ooops, forgot to check these in a few mins ago.  Revised names for hom pseudo-ctors; new error
00213 // for CanonicalHom.
00214 //
00215 // Revision 1.11  2007/03/05 16:17:11  bigatti
00216 // -- clenup for numerical code (and 3 new error codes)
00217 //
00218 // Revision 1.10  2007/03/03 14:07:23  bigatti
00219 // -- "foundations" renamed into "GlobalManager"
00220 //
00221 // Revision 1.9  2007/03/02 10:47:53  cocoa
00222 // First stage of RingZ modifications -- tests do not compile currently, Anna will fix this.
00223 //
00224 // Revision 1.8  2007/02/12 17:40:19  bigatti
00225 // -- added MissNumLibs
00226 //
00227 // Revision 1.7  2007/01/13 14:14:34  cocoa
00228 // Overhaul of RingHom code: it nows uses SmartPtrIRC, and printing is more logical.
00229 // Have not yet updated the documentation.
00230 //
00231 // Revision 1.6  2006/12/21 13:46:54  cocoa
00232 // Improved layout; added one new error code.
00233 //
00234 // Revision 1.5  2006/12/06 17:17:44  cocoa
00235 // -- removed #include "config.H"
00236 //
00237 // Revision 1.4  2006/10/06 10:10:15  cocoa
00238 // Corrected a comment.  Corrected position of #ifndef etc.
00239 //
00240 // Revision 1.3  2006/08/07 21:23:25  cocoa
00241 // Removed almost all publicly visible references to SmallExponent_t;
00242 // changed to long in all PPMonoid functions and SparsePolyRing functions.
00243 // DivMask remains to sorted out.
00244 //
00245 // Revision 1.2  2006/07/17 19:16:53  cocoa
00246 // New, better errors :-)
00247 //
00248 // Revision 1.1.1.1  2006/05/30 11:39:36  cocoa
00249 // Imported files
00250 //
00251 // Revision 1.6  2006/04/14 13:51:40  cocoa
00252 // Added a class for generating random bits (RandomBitStream in the file random.H).
00253 //
00254 // Revision 1.5  2006/04/07 16:44:52  cocoa
00255 // Considerably updated MemPool design -- it works, and I'm about to test
00256 // its efficiency against the old one.
00257 //
00258 // Revision 1.4  2006/04/04 13:01:02  cocoa
00259 // -- added: NotNonNegativeGrading, NotPositiveGrading
00260 //
00261 // Revision 1.3  2006/03/27 12:21:26  cocoa
00262 // Minor silly changes to reduce number of complaints from some compiler or other.
00263 //
00264 // Revision 1.2  2005/11/24 16:09:38  cocoa
00265 // -- added operator[] for ModuleElem
00266 //
00267 // Revision 1.1.1.1  2005/10/17 10:46:54  cocoa
00268 // Imported files
00269 //
00270 // Revision 1.8  2005/09/28 11:50:35  cocoa
00271 // -- new code for graded modules
00272 //
00273 // Revision 1.7  2005/08/08 16:36:32  cocoa
00274 // Just checking in before going on holiday.
00275 // Don't really recall what changes have been made.
00276 // Added IsIndet function for RingElem, PPMonoidElem,
00277 // and a member function of OrdvArith.
00278 // Improved the way failed assertions are handled.
00279 //
00280 // Revision 1.6  2005/07/19 15:30:20  cocoa
00281 // A first attempt at iterators over sparse polynomials.
00282 // Main additions are to SparsePolyRing, DistrMPoly*.
00283 // Some consequential changes to PPMonoid*.
00284 //
00285 // Revision 1.5  2005/07/15 16:34:33  cocoa
00286 // Added iterators for sparse polynomials.
00287 // The code compiles (and the old tests still run).
00288 // It'd Friday evening -- I'm going home before
00289 // getting any ideas about making the iterator code run.
00290 //
00291 // Revision 1.4  2005/07/08 15:09:29  cocoa
00292 // Added new symbol class (to represent names of indets).
00293 // Integrated the new class into concrete polynomial rings
00294 // and PPMonoid -- many consequential changes.
00295 // Change ctors for the "inline" sparse poly rings: they no
00296 // longer expect a PPMonoid, but build their own instead
00297 // (has to be a PPMonoidOv).
00298 //
00299 // Revision 1.3  2005/07/01 16:08:16  cocoa
00300 // Friday check-in.  Major change to structure under PolyRing:
00301 // now SparsePolyRing and DUPolyRing are separated (in preparation
00302 // for implementing iterators).
00303 //
00304 // A number of other relatively minor changes had to be chased through
00305 // (e.g. IndetPower).
00306 //
00307 // Revision 1.2  2005/06/27 14:55:24  cocoa
00308 // Cleaned up some more PPMonoid code.
00309 //
00310 // Revision 1.1.1.1  2005/05/03 15:47:30  cocoa
00311 // Imported files
00312 //
00313 // Revision 1.8  2005/04/29 15:42:02  cocoa
00314 // Improved documentation for GMPAllocator.
00315 // Added example program for GMPAllocator.
00316 // Added example program for simple ops on polynomials.
00317 // Added two new ctors for (principal) ideals (from long, and from ZZ).
00318 // Added (crude) printing for PPMonoids.
00319 // Updated library.H (#included GMPAllocator.H).
00320 //
00321 // Revision 1.7  2005/04/27 16:14:56  cocoa
00322 // Cleaned up example programs -- added "free use" permit.
00323 // Changed a couple of ErrorInfo object names, and added
00324 // ERR::NotTrueGCDDomain.
00325 //
00326 // Revision 1.6  2005/04/20 15:40:48  cocoa
00327 // Major change: modified the standard way errors are to be signalled
00328 // (now via a macro which records filename and line number).  Updated
00329 // documentation in error.txt accordingly.
00330 //
00331 // Improved the documentation in matrix.txt (still more work to be done).
00332 //
00333 // Revision 1.5  2005/04/19 14:06:04  cocoa
00334 // Added GPL and GFDL licence stuff.
00335 //
00336 // Revision 1.4  2005/03/11 16:44:18  cocoa
00337 // New abstract class structure for matrices.
00338 // New types of special matrix.
00339 //
00340 // Revision 1.3  2005/03/02 18:46:41  cocoa
00341 // Added new types ConstRefMatrix, and RefMatrix following along
00342 // the lines of ConstRefRingElem and RefRingElem.  The semantics
00343 // should be a bit clearer now.
00344 //
00345 // Revision 1.2  2005/02/22 12:50:40  cocoa
00346 // -- added: NotFullRank, NotIntDom, NotTermOrdering
00347 //
00348 // Revision 1.1.1.1  2005/01/27 15:12:13  cocoa
00349 // Imported files
00350 //
00351 // Revision 1.19  2004/11/25 16:14:21  cocoa
00352 // (1) Fixed definition of specialization of std::swap template function
00353 //     so that it compiles with gcc 3.4.3
00354 // (2) Implemented monomial function for polynomial rings.
00355 // (3) Added one(PPM) and PPM->myOne() functions.
00356 //
00357 // Revision 1.18  2004/11/19 17:43:50  cocoa
00358 // -- added matrix related errors
00359 //
00360 // Revision 1.17  2004/11/19 16:15:51  cocoa
00361 // (a) Removed unused error message about degree of zero;
00362 //     replaced it by a more general message about needing a
00363 //     non-zero polynomial (for various ops such as LC, LPP).
00364 // (b) Added some missing arg checking in LC, LPP and deg
00365 //     (for elems of a PolyRing).
00366 // (c) Updated some commented out code in GPair and GPoly.
00367 //
00368 // Revision 1.16  2004/11/19 15:14:09  cocoa
00369 // (a) Added new check to MemPool so that it can signal an
00370 //     error if one tries to use a MemPool after it has been
00371 //     destroyed.
00372 // (b) Improved makefile in TEST/ so that it checks output,
00373 //     and prints useful messages if the test fails.
00374 // (c) Tidied ring.txt a bit (still more to do).
00375 //
00376 // Revision 1.15  2004/11/12 15:49:29  cocoa
00377 // Tidying prior to 0.90 release.
00378 // (a) documentation improved (or marked as poor)
00379 // (b) sundry minor improvements to the code
00380 //
00381 // Revision 1.14  2004/11/11 14:16:37  cocoa
00382 // -- added \include *.txt for doxygen
00383 //
00384 // Revision 1.13  2004/11/11 11:56:09  cocoa
00385 // (1) Tidied makefiles, and introduced common.mki
00386 // (2) Improved several tests, and cleaned them so that they
00387 //     handle sanely any otherwise unhandled exceptions.
00388 //
00389 // Revision 1.12  2004/11/09 15:53:56  cocoa
00390 // -- added BadQuotRing("Attempt to quotient by ideal(1)")
00391 //
00392 // Revision 1.11  2004/11/05 15:37:56  cocoa
00393 // Added a couple of new errors.
00394 //
00395 // Revision 1.10  2004/11/03 18:01:55  cocoa
00396 // -- clarified behaviour of error()
00397 // -- added ANNOUNCE function
00398 // -- minor tidying
00399 //
00400 // Revision 1.8  2004/07/27 16:03:38  cocoa
00401 // Added IsCommutative test and IamCommutative member function
00402 // to all rings.  Tidied geobuckets a little.
00403 //
00404 // Revision 1.7  2004/07/20 15:04:06  cocoa
00405 // The next step in the new "ring element" conversion process:
00406 // handling the case of creating a "const RefRingElem" object
00407 // (since C++ refuses to do this properly itself).
00408 //
00409 // Revision 1.6  2004/07/14 16:40:42  cocoa
00410 // Separated RingFpLog from its implementation which now resides in
00411 // a new class: SmallFpLogImpl.  This is analogous to the change made
00412 // to RingFp yesterday.
00413 //
00414 // Some tidying and other sundry minor changes.
00415 //
00416 // Revision 1.5  2004/07/13 16:32:26  cocoa
00417 // First stage of major revamp of ring elements.
00418 // Implementation of RingFp has been split into "ring interface"
00419 // and "algorithms plus data structures".
00420 //
00421 // Revision 1.4  2004/06/29 17:10:22  cocoa
00422 // Partially tidied use of "protected" and "private" in various
00423 // base classes.  Checking in at the end of the day -- it works,
00424 // and I wouldn't want it to be lost next time point's disk
00425 // misbehaves.
00426 //
00427 // Revision 1.3  2004/05/27 16:14:02  cocoa
00428 // Minor revision for new coding conventions.
00429 //
00430 // Revision 1.2  2004/05/24 15:52:13  cocoa
00431 // Major update:
00432 //   new error mechanism
00433 //   many fixes
00434 //   RingHoms almost work now
00435 //   RingFloat much improved
00436 //
00437 // Revision 1.1.1.1  2003/09/24 12:55:43  cocoa
00438 // Imported files
00439 //
00440 // Revision 1.5  2003/06/23 16:15:05  abbott
00441 // Minor cleaning prior to public release.
00442 //
00443 // Revision 1.4  2002/11/13 15:37:49  abbott
00444 // Added a second field to CoCoAError to allow the location of an
00445 // error to be indicated.  Also a new accessor function "where" to
00446 // read the new field, and a query function saying whether the new
00447 // field has a non-trivial value (HasLocation).  The old constructor
00448 // remains, and is joined by a new one allowing the location field
00449 // to be specified.
00450 //
00451 // Revision 1.3  2002/01/25 15:16:59  abbott
00452 // Added class CoCoAError as a temporary solution; the standard library
00453 // exception classes do not seem to offer what we need.
00454 //
00455 // Revision 1.2  2001/12/07 15:56:48  abbott
00456 // error function now takes an exception as an argument, instead of a string.
00457 //
00458 // Revision 1.1  2001/11/26 19:13:24  abbott
00459 // Initial revision
00460 //
00461 
00462 #endif

Generated on Wed May 23 13:45:22 2007 for CoCoALib by  doxygen 1.4.6