nnfw/include/nnfwexceptions.h

Go to the documentation of this file.
00001 /********************************************************************************
00002  *  Neural Network Framework.                                                   *
00003  *  Copyright (C) 2005-2011 Gianluca Massera <emmegian@yahoo.it>                *
00004  *                                                                              *
00005  *  This program is free software; you can redistribute it and/or modify        *
00006  *  it under the terms of the GNU General Public License as published by        *
00007  *  the Free Software Foundation; either version 2 of the License, or           *
00008  *  (at your option) any later version.                                         *
00009  *                                                                              *
00010  *  This program is distributed in the hope that it will be useful,             *
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of              *
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               *
00013  *  GNU General Public License for more details.                                *
00014  *                                                                              *
00015  *  You should have received a copy of the GNU General Public License           *
00016  *  along with this program; if not, write to the Free Software                 *
00017  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA  *
00018  ********************************************************************************/
00019 
00020 #ifndef NNFWEXCEPTIONS_H
00021 #define NNFWEXCEPTIONS_H
00022 
00028 #include <exception>
00029 #include <cstring>
00030 #include <cstdio>
00031 #include "baseexception.h"
00032 
00033 // All the suff below is to avoid warnings on Windows about the use of the
00034 // unsafe function sprintf and strcpy...
00035 #if defined(_MSC_VER)
00036     #pragma warning(push)
00037     #pragma warning(disable:4996)
00038 #endif
00039 
00040 namespace farsa {
00041 
00042 // NOTE: I don't use snprintf instead of sprintf because it seems not to be in
00043 // the current C++ standard (C++03, it is instead in the C99 standard). Note
00044 // however that no buffer overflow is possible (buffer lengths are carefully
00045 // checked)
00046 
00051 class FARSA_NNFW_TEMPLATE VectorAssignmentNotAllowed : public BaseException
00052 {
00053 public:
00057     VectorAssignmentNotAllowed() throw() :
00058         BaseException()
00059     {
00060     }
00061 
00067     VectorAssignmentNotAllowed(const VectorAssignmentNotAllowed& other) throw() :
00068         BaseException(other)
00069     {
00070     }
00071 
00077     VectorAssignmentNotAllowed& operator=(const VectorAssignmentNotAllowed& other) throw()
00078     {
00079         if (&other == this) {
00080             return *this;
00081         }
00082 
00083         BaseException::operator=(other);
00084 
00085         return *this;
00086     }
00087 
00091     virtual ~VectorAssignmentNotAllowed() throw()
00092     {
00093     }
00094 
00100     virtual const char *what() const throw()
00101     {
00102         return "It is not allowed to use the operator=() on DoubleVector used as internal data";
00103     }
00104 
00109     EXCEPTION_HELPER_FUNCTIONS(VectorAssignmentNotAllowed)
00110 };
00111 
00116 class FARSA_NNFW_TEMPLATE VectorResizeNotAllowed : public BaseException
00117 {
00118 public:
00122     VectorResizeNotAllowed() throw() :
00123         BaseException()
00124     {
00125     }
00126 
00132     VectorResizeNotAllowed(const VectorResizeNotAllowed& other) throw() :
00133         BaseException(other)
00134     {
00135     }
00136 
00142     VectorResizeNotAllowed& operator=(const VectorResizeNotAllowed& other) throw()
00143     {
00144         if (&other == this) {
00145             return *this;
00146         }
00147 
00148         BaseException::operator=(other);
00149 
00150         return *this;
00151     }
00152 
00156     virtual ~VectorResizeNotAllowed() throw()
00157     {
00158     }
00159 
00165     virtual const char *what() const throw()
00166     {
00167         return "It is not allowed to resize a DoubleVector used as internal data";
00168     }
00169 
00174     EXCEPTION_HELPER_FUNCTIONS(VectorResizeNotAllowed)
00175 };
00176 
00181 class FARSA_NNFW_TEMPLATE IncompatibleVectors : public BaseException
00182 {
00183 public:
00191     IncompatibleVectors(const char* description) throw() :
00192         BaseException()
00193     {
00194         strncpy(m_description, description, 256);
00195         m_description[255] = '\0';
00196     }
00197 
00203     IncompatibleVectors(const IncompatibleVectors& other) throw() :
00204         BaseException(other)
00205     {
00206         strncpy(m_description, other.m_description, 256);
00207         m_description[255] = '\0';
00208     }
00209 
00215     IncompatibleVectors& operator=(const IncompatibleVectors& other) throw()
00216     {
00217         if (&other == this) {
00218             return *this;
00219         }
00220 
00221         BaseException::operator=(other);
00222         strncpy(m_description, other.m_description, 256);
00223         m_description[255] = '\0';
00224 
00225         return *this;
00226     }
00227 
00231     virtual ~IncompatibleVectors() throw()
00232     {
00233     }
00234 
00240     virtual const char *what() const throw()
00241     {
00242         return m_description;
00243     }
00244 
00250     const char *description() const throw()
00251     {
00252         return m_description;
00253     }
00254 
00259     EXCEPTION_HELPER_FUNCTIONS(IncompatibleVectors)
00260 
00261 private:
00265     char m_description[256];
00266 };
00267 
00272 class FARSA_NNFW_TEMPLATE OutsideVectorBoundaries : public BaseException
00273 {
00274 public:
00282     OutsideVectorBoundaries(const char* description) throw() :
00283         BaseException()
00284     {
00285         strncpy(m_description, description, 256);
00286         m_description[255] = '\0';
00287     }
00288 
00294     OutsideVectorBoundaries(const OutsideVectorBoundaries& other) throw() :
00295         BaseException(other)
00296     {
00297         strncpy(m_description, other.m_description, 256);
00298         m_description[255] = '\0';
00299     }
00300 
00306     OutsideVectorBoundaries& operator=(const OutsideVectorBoundaries& other) throw()
00307     {
00308         if (&other == this) {
00309             return *this;
00310         }
00311 
00312         BaseException::operator=(other);
00313         strncpy(m_description, other.m_description, 256);
00314         m_description[255] = '\0';
00315 
00316         return *this;
00317     }
00318 
00322     virtual ~OutsideVectorBoundaries() throw()
00323     {
00324     }
00325 
00331     virtual const char *what() const throw()
00332     {
00333         return m_description;
00334     }
00335 
00341     const char *description() const throw()
00342     {
00343         return m_description;
00344     }
00345 
00350     EXCEPTION_HELPER_FUNCTIONS(OutsideVectorBoundaries)
00351 
00352 private:
00356     char m_description[256];
00357 };
00358 
00363 class FARSA_NNFW_TEMPLATE ClusterFromOrToMissing : public BaseException
00364 {
00365 public:
00369     ClusterFromOrToMissing() throw() :
00370         BaseException()
00371     {
00372     }
00373 
00379     ClusterFromOrToMissing(const ClusterFromOrToMissing& other) throw() :
00380         BaseException(other)
00381     {
00382     }
00383 
00389     ClusterFromOrToMissing& operator=(const ClusterFromOrToMissing& other) throw()
00390     {
00391         if (&other == this) {
00392             return *this;
00393         }
00394 
00395         BaseException::operator=(other);
00396 
00397         return *this;
00398     }
00399 
00403     virtual ~ClusterFromOrToMissing() throw()
00404     {
00405     }
00406 
00412     virtual const char *what() const throw()
00413     {
00414         return "The Cluster 'from' or 'to' is missing - Check your configuration file";
00415     }
00416 
00421     EXCEPTION_HELPER_FUNCTIONS(ClusterFromOrToMissing)
00422 };
00423 
00428 class FARSA_NNFW_TEMPLATE MatrixAssignmentNotAllowed : public BaseException
00429 {
00430 public:
00434     MatrixAssignmentNotAllowed() throw() :
00435         BaseException()
00436     {
00437     }
00438 
00444     MatrixAssignmentNotAllowed(const MatrixAssignmentNotAllowed& other) throw() :
00445         BaseException(other)
00446     {
00447     }
00448 
00454     MatrixAssignmentNotAllowed& operator=(const MatrixAssignmentNotAllowed& other) throw()
00455     {
00456         if (&other == this) {
00457             return *this;
00458         }
00459 
00460         BaseException::operator=(other);
00461 
00462         return *this;
00463     }
00464 
00468     virtual ~MatrixAssignmentNotAllowed() throw()
00469     {
00470     }
00471 
00477     virtual const char *what() const throw()
00478     {
00479         return "It is not allowed to use the operator=() on DoubleMatrix used as internal data";
00480     }
00481 
00486     EXCEPTION_HELPER_FUNCTIONS(MatrixAssignmentNotAllowed)
00487 };
00488 
00493 class FARSA_NNFW_TEMPLATE MatrixResizeNotAllowed : public BaseException
00494 {
00495 public:
00499     MatrixResizeNotAllowed() throw() :
00500         BaseException()
00501     {
00502     }
00503 
00509     MatrixResizeNotAllowed(const MatrixResizeNotAllowed& other) throw() :
00510         BaseException(other)
00511     {
00512     }
00513 
00519     MatrixResizeNotAllowed& operator=(const MatrixResizeNotAllowed& other) throw()
00520     {
00521         if (&other == this) {
00522             return *this;
00523         }
00524 
00525         BaseException::operator=(other);
00526 
00527         return *this;
00528     }
00529 
00533     virtual ~MatrixResizeNotAllowed() throw()
00534     {
00535     }
00536 
00542     virtual const char *what() const throw()
00543     {
00544         return "It is not allowed to resize a DoubleMatrix used as internal data";
00545     }
00546 
00551     EXCEPTION_HELPER_FUNCTIONS(MatrixResizeNotAllowed)
00552 };
00553 
00558 class FARSA_NNFW_TEMPLATE IncompatibleMatrices : public BaseException
00559 {
00560 public:
00568     IncompatibleMatrices(const char* description) throw() :
00569         BaseException()
00570     {
00571         strncpy(m_description, description, 256);
00572         m_description[255] = '\0';
00573     }
00574 
00580     IncompatibleMatrices(const IncompatibleMatrices& other) throw() :
00581         BaseException(other)
00582     {
00583         strncpy(m_description, other.m_description, 256);
00584         m_description[255] = '\0';
00585     }
00586 
00592     IncompatibleMatrices& operator=(const IncompatibleMatrices& other) throw()
00593     {
00594         if (&other == this) {
00595             return *this;
00596         }
00597 
00598         BaseException::operator=(other);
00599         strncpy(m_description, other.m_description, 256);
00600         m_description[255] = '\0';
00601 
00602         return *this;
00603     }
00604 
00608     virtual ~IncompatibleMatrices() throw()
00609     {
00610     }
00611 
00617     virtual const char *what() const throw()
00618     {
00619         return m_description;
00620     }
00621 
00627     const char *description() const throw()
00628     {
00629         return m_description;
00630     }
00631 
00636     EXCEPTION_HELPER_FUNCTIONS(IncompatibleMatrices)
00637 
00638 private:
00642     char m_description[256];
00643 };
00644 
00649 class FARSA_NNFW_TEMPLATE OutsideMatrixBoundaries : public BaseException
00650 {
00651 public:
00659     OutsideMatrixBoundaries(const char* description) throw() :
00660         BaseException()
00661     {
00662         strncpy(m_description, description, 256);
00663         m_description[255] = '\0';
00664     }
00665 
00671     OutsideMatrixBoundaries(const OutsideMatrixBoundaries& other) throw() :
00672         BaseException(other)
00673     {
00674         strncpy(m_description, other.m_description, 256);
00675         m_description[255] = '\0';
00676     }
00677 
00683     OutsideMatrixBoundaries& operator=(const OutsideMatrixBoundaries& other) throw()
00684     {
00685         if (&other == this) {
00686             return *this;
00687         }
00688 
00689         BaseException::operator=(other);
00690         strncpy(m_description, other.m_description, 256);
00691         m_description[255] = '\0';
00692 
00693         return *this;
00694     }
00695 
00699     virtual ~OutsideMatrixBoundaries() throw()
00700     {
00701     }
00702 
00708     virtual const char *what() const throw()
00709     {
00710         return m_description;
00711     }
00712 
00718     const char *description() const throw()
00719     {
00720         return m_description;
00721     }
00722 
00727     EXCEPTION_HELPER_FUNCTIONS(OutsideMatrixBoundaries)
00728 
00729 private:
00733     char m_description[256];
00734 };
00735 
00740 class FARSA_NNFW_TEMPLATE OutputFunctionSetClusterException : public BaseException
00741 {
00742 public:
00746     OutputFunctionSetClusterException() throw() :
00747         BaseException()
00748     {
00749     }
00750 
00756     OutputFunctionSetClusterException(const OutputFunctionSetClusterException& other) throw() :
00757         BaseException(other)
00758     {
00759     }
00760 
00766     OutputFunctionSetClusterException& operator=(const OutputFunctionSetClusterException& other) throw()
00767     {
00768         if (&other == this) {
00769             return *this;
00770         }
00771 
00772         BaseException::operator=(other);
00773 
00774         return *this;
00775     }
00776 
00780     virtual ~OutputFunctionSetClusterException() throw()
00781     {
00782     }
00783 
00789     virtual const char *what() const throw()
00790     {
00791         return "setCluster called on an OutputFunction already configured to be part of another Cluster!";
00792     }
00793 
00798     EXCEPTION_HELPER_FUNCTIONS(OutputFunctionSetClusterException)
00799 };
00800 
00805 class FARSA_NNFW_TEMPLATE ClusterStateVectorNotPresent : public BaseException
00806 {
00807 public:
00815     ClusterStateVectorNotPresent(const char* description) throw() :
00816         BaseException()
00817     {
00818         strncpy(m_description, description, 256);
00819         m_description[255] = '\0';
00820     }
00821 
00827     ClusterStateVectorNotPresent(const ClusterStateVectorNotPresent& other) throw() :
00828         BaseException(other)
00829     {
00830         strncpy(m_description, other.m_description, 256);
00831         m_description[255] = '\0';
00832     }
00833 
00839     ClusterStateVectorNotPresent& operator=(const ClusterStateVectorNotPresent& other) throw()
00840     {
00841         if (&other == this) {
00842             return *this;
00843         }
00844 
00845         BaseException::operator=(other);
00846         strncpy(m_description, other.m_description, 256);
00847         m_description[255] = '\0';
00848 
00849         return *this;
00850     }
00851 
00855     virtual ~ClusterStateVectorNotPresent() throw()
00856     {
00857     }
00858 
00864     virtual const char *what() const throw()
00865     {
00866         return m_description;
00867     }
00868 
00874     const char *description() const throw()
00875     {
00876         return m_description;
00877     }
00878 
00883     EXCEPTION_HELPER_FUNCTIONS(ClusterStateVectorNotPresent)
00884 
00885 private:
00889     char m_description[256];
00890 };
00891 
00892 }
00893 
00894 #endif