casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
ArrayError.h
Go to the documentation of this file.
00001 //# ArrayError.h: Exception classes thrown by Array and related classes/functions
00002 //# Copyright (C) 1993,1994,1995,1999,2000
00003 //# Associated Universities, Inc. Washington DC, USA.
00004 //# 
00005 //# This library is free software; you can redistribute it and/or modify it
00006 //# under the terms of the GNU Library General Public License as published by
00007 //# the Free Software Foundation; either version 2 of the License, or (at your
00008 //# option) any later version.
00009 //# 
00010 //# This library is distributed in the hope that it will be useful, but WITHOUT
00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00013 //# License for more details.
00014 //# 
00015 //# You should have received a copy of the GNU Library General Public License
00016 //# along with this library; if not, write to the Free Software Foundation,
00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00018 //# 
00019 //# Correspondence concerning AIPS++ should be addressed as follows:
00020 //#        Internet email: aips2-request@nrao.edu.
00021 //#        Postal address: AIPS++ Project Office
00022 //#                        National Radio Astronomy Observatory
00023 //#                        520 Edgemont Road
00024 //#                        Charlottesville, VA 22903-2475 USA
00025 //#
00026 //# $Id: ArrayError.h 21130 2011-10-18 07:39:05Z gervandiepen $
00027 
00028 #ifndef CASA_ARRAYERROR_H
00029 #define CASA_ARRAYERROR_H
00030 
00031 //# Includes
00032 #include <casa/aips.h>
00033 #include <casa/Exceptions/Error.h>
00034 #include <casa/Arrays/IPosition.h>
00035 
00036 
00037 namespace casa { //# NAMESPACE CASA - BEGIN
00038 
00039 // <summary> The base class for all Array exception classes. </summary>
00040 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
00041 // </reviewed>
00042 //
00043 // ArrayError is the base class for all the Array-specific exception classes,
00044 // i.e. if it is caught you will catch (through inheritance) all Array-specific
00045 // exceptions. Note that (presently, anyway) the Array classes will throw
00046 // a few non-Array exceptions.
00047 // <srcblock>
00048 // try {
00049 //    // Some lines, functions, ...
00050 // } catch (ArrayError x) {
00051 //    // Array specific errors
00052 // } catch (AipsError x) {
00053 //    // All other errors caught here.
00054 // }
00055 // </srcblock>
00056 //
00057 //# There are too many Array related error classes. Some should be deleted.
00058 
00059 class ArrayError : public AipsError
00060 {
00061 public:
00062     // Initialize with the message "ArrayError."
00063     ArrayError(Category c=GENERAL);
00064     // Initialize with the supplied message.
00065     ArrayError(const Char *m,Category c=GENERAL);
00066     // Initialize with the supplied message.
00067     ArrayError(const String &m,Category c=GENERAL);
00068     ~ArrayError() throw();
00069 };
00070 
00071 
00072 // <summary> An error thrown when an index is out of range </summary>
00073 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
00074 // </reviewed>
00075 //
00076 // The ArrayIndexError class, which is derived from ArrayError, is intended
00077 // to be thrown when an index is out-of-bounds. It contains within it
00078 // the offending index, as well as the shape of the array which
00079 // is being indexed. This should be multiply-derived from
00080 // indexError<T> defined in Error.h.
00081 class ArrayIndexError : public ArrayError
00082 {
00083 public:
00084     // Initialize with the message "ArrayIndexError".
00085     ArrayIndexError(Category c=BOUNDARY);
00086     // Initialize with the supplied message, the index and shape are null.
00087     ArrayIndexError(const Char *m,Category c=BOUNDARY);
00088     // Initialize with the supplied message, the index and shape are null.
00089     ArrayIndexError(const String &m,Category c=BOUNDARY);
00090     // Initialize with a given out-of-bounds index, as well as the shape
00091     // of the array and a supplied message.
00092     ArrayIndexError(const IPosition &index, const IPosition &shape, 
00093                     const Char *m="ArrayIndexError",Category c=BOUNDARY);
00094     ~ArrayIndexError() throw();
00095     // The out-of-bounds index.
00096     IPosition index() const;
00097     // The shape of the violated array.
00098     IPosition shape() const;
00099 private:
00100     //# index, offset, length
00101     IPosition i,l;
00102 };
00103 
00104 
00105 // <summary> An error thrown when two arrays do not conform </summary>
00106 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
00107 // </reviewed>
00108 //
00109 // The ArrayConformanceError class is the base class for all errors thrown
00110 // because two arrays are not conformant. See also the ArrayShapeError and
00111 // ArrayNDimError classes which are derived from it. This error, or one derived
00112 // from it, os normally thrown from a binary operation (arithmetic, logical,
00113 // assignment, etc).
00114 class ArrayConformanceError : public ArrayError
00115 {
00116 public:
00117     // Initialize the message with "ArrayConformanceError".
00118     ArrayConformanceError(Category c=CONFORMANCE);
00119     // Initialize with a supplied message.
00120     ArrayConformanceError(const Char *m,Category c=CONFORMANCE);
00121     // Initialize with a supplied message.
00122     ArrayConformanceError(const String &m,Category c=CONFORMANCE);
00123     ~ArrayConformanceError() throw();
00124 };
00125 
00126 
00127 // <summary> Thrown when two arrays have different dimensionality </summary>
00128 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
00129 // </reviewed>
00130 //
00131 // An ArrayNDimError is derived from ArrayConformanceError. It is thrown when
00132 // two arrays are non-conformant by virtue of having different dimensionality.
00133 // It holds within it the two dimensions.
00134 class ArrayNDimError : public ArrayConformanceError
00135 {
00136 public:
00137     // Define the two (presumably different) messages and optionally
00138     // supply a message.
00139     ArrayNDimError(Int dim1, Int dim2, const Char *m="ArrayNDimError",Category c=CONFORMANCE);
00140     ~ArrayNDimError() throw();
00141     // Return the stored dimensions. NB modifies arguments.
00142     void ndims(Int &dim1, Int &dim2) const; // modifies arguments
00143 private:
00144     Int r1, r2;
00145 };
00146 
00147 
00148 // <summary> An error thrown when two arrays have different shapes </summary>
00149 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
00150 // </reviewed>
00151 //
00152 // An ArrayShapeError is derived from ArrayConformanceError. It is thrown when
00153 // two arrays are non-conformant by virtue of having different shapes.
00154 // It holds within it the two different two shapes.
00155 class ArrayShapeError : public ArrayConformanceError
00156 {
00157 public:
00158     // Define an ArrayShapeError with the two (presumably different) shapes
00159     // and an optional supplied message.
00160     ArrayShapeError(const IPosition &shape1, const IPosition &shape2,
00161                      const Char *m="ArrayShapeError",Category c=CONFORMANCE);
00162     ~ArrayShapeError() throw();
00163     // Get back the stored shapes. NB modifies arguments.
00164     void shapes(IPosition &, IPosition &) const;  // modifies arguments
00165 private:
00166     IPosition sh1, sh2;
00167 };
00168 
00169 
00170 // <summary> An error thrown by an ArrayIterator </summary>
00171 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
00172 // </reviewed>
00173 //
00174 // An ArrayIteratorError is thrown by an array iterator or related class
00175 // (e.g. VectorIterator).
00176 class ArrayIteratorError : public ArrayError
00177 {
00178 public:    
00179     // Initialize with the message "ArrayIteratorError.
00180     ArrayIteratorError(Category c=BOUNDARY);
00181     // Initialize with the supplied message
00182     ArrayIteratorError(const Char *m,Category c=BOUNDARY);
00183     // Initialize with the supplied message
00184     ArrayIteratorError(const String &m,Category c=BOUNDARY);
00185     ~ArrayIteratorError() throw();
00186 };
00187 
00188 
00189 // <summary> An error thrown by an Slicer member function </summary>
00190 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
00191 // </reviewed>
00192 //
00193 // An ArraySlicerError is thrown by an  Slicer member function.
00194 class ArraySlicerError : public ArrayError
00195 {
00196 public:    
00197     // Initialize with the message "Slicer error."
00198     ArraySlicerError(Category c=GENERAL);
00199     // Initialize with ArraySlicerError plus the supplied message
00200     ArraySlicerError(const String &m,Category c=GENERAL);
00201     ~ArraySlicerError() throw();
00202 };
00203 
00204 
00205 } //# NAMESPACE CASA - END
00206 
00207 #endif