nnfwexceptions.h
Go to the documentation of this file.
1 /********************************************************************************
2  * Neural Network Framework. *
3  * Copyright (C) 2005-2011 Gianluca Massera <emmegian@yahoo.it> *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the Free Software *
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
18  ********************************************************************************/
19 
20 #ifndef NNFWEXCEPTIONS_H
21 #define NNFWEXCEPTIONS_H
22 
28 #include <exception>
29 #include <cstring>
30 #include <cstdio>
31 #include "baseexception.h"
32 
33 // All the suff below is to avoid warnings on Windows about the use of the
34 // unsafe function sprintf and strcpy...
35 #if defined(_MSC_VER)
36  #pragma warning(push)
37  #pragma warning(disable:4996)
38 #endif
39 
40 namespace farsa {
41 
42 // NOTE: I don't use snprintf instead of sprintf because it seems not to be in
43 // the current C++ standard (C++03, it is instead in the C99 standard). Note
44 // however that no buffer overflow is possible (buffer lengths are carefully
45 // checked)
46 
51 class FARSA_NNFW_TEMPLATE VectorAssignmentNotAllowed : public BaseException
52 {
53 public:
58  BaseException()
59  {
60  }
61 
68  BaseException(other)
69  {
70  }
71 
77  VectorAssignmentNotAllowed& operator=(const VectorAssignmentNotAllowed& other) throw()
78  {
79  if (&other == this) {
80  return *this;
81  }
82 
83  BaseException::operator=(other);
84 
85  return *this;
86  }
87 
91  virtual ~VectorAssignmentNotAllowed() throw()
92  {
93  }
94 
100  virtual const char *what() const throw()
101  {
102  return "It is not allowed to use the operator=() on DoubleVector used as internal data";
103  }
104 
109  EXCEPTION_HELPER_FUNCTIONS(VectorAssignmentNotAllowed)
110 };
111 
116 class FARSA_NNFW_TEMPLATE VectorResizeNotAllowed : public BaseException
117 {
118 public:
123  BaseException()
124  {
125  }
126 
133  BaseException(other)
134  {
135  }
136 
142  VectorResizeNotAllowed& operator=(const VectorResizeNotAllowed& other) throw()
143  {
144  if (&other == this) {
145  return *this;
146  }
147 
148  BaseException::operator=(other);
149 
150  return *this;
151  }
152 
156  virtual ~VectorResizeNotAllowed() throw()
157  {
158  }
159 
165  virtual const char *what() const throw()
166  {
167  return "It is not allowed to resize a DoubleVector used as internal data";
168  }
169 
174  EXCEPTION_HELPER_FUNCTIONS(VectorResizeNotAllowed)
175 };
176 
181 class FARSA_NNFW_TEMPLATE IncompatibleVectors : public BaseException
182 {
183 public:
191  IncompatibleVectors(const char* description) throw() :
192  BaseException()
193  {
194  strncpy(m_description, description, 256);
195  m_description[255] = '\0';
196  }
197 
203  IncompatibleVectors(const IncompatibleVectors& other) throw() :
204  BaseException(other)
205  {
206  strncpy(m_description, other.m_description, 256);
207  m_description[255] = '\0';
208  }
209 
215  IncompatibleVectors& operator=(const IncompatibleVectors& other) throw()
216  {
217  if (&other == this) {
218  return *this;
219  }
220 
221  BaseException::operator=(other);
222  strncpy(m_description, other.m_description, 256);
223  m_description[255] = '\0';
224 
225  return *this;
226  }
227 
231  virtual ~IncompatibleVectors() throw()
232  {
233  }
234 
240  virtual const char *what() const throw()
241  {
242  return m_description;
243  }
244 
250  const char *description() const throw()
251  {
252  return m_description;
253  }
254 
259  EXCEPTION_HELPER_FUNCTIONS(IncompatibleVectors)
260 
261 private:
265  char m_description[256];
266 };
267 
272 class FARSA_NNFW_TEMPLATE OutsideVectorBoundaries : public BaseException
273 {
274 public:
282  OutsideVectorBoundaries(const char* description) throw() :
283  BaseException()
284  {
285  strncpy(m_description, description, 256);
286  m_description[255] = '\0';
287  }
288 
295  BaseException(other)
296  {
297  strncpy(m_description, other.m_description, 256);
298  m_description[255] = '\0';
299  }
300 
306  OutsideVectorBoundaries& operator=(const OutsideVectorBoundaries& other) throw()
307  {
308  if (&other == this) {
309  return *this;
310  }
311 
312  BaseException::operator=(other);
313  strncpy(m_description, other.m_description, 256);
314  m_description[255] = '\0';
315 
316  return *this;
317  }
318 
322  virtual ~OutsideVectorBoundaries() throw()
323  {
324  }
325 
331  virtual const char *what() const throw()
332  {
333  return m_description;
334  }
335 
341  const char *description() const throw()
342  {
343  return m_description;
344  }
345 
350  EXCEPTION_HELPER_FUNCTIONS(OutsideVectorBoundaries)
351 
352 private:
356  char m_description[256];
357 };
358 
363 class FARSA_NNFW_TEMPLATE ClusterFromOrToMissing : public BaseException
364 {
365 public:
370  BaseException()
371  {
372  }
373 
380  BaseException(other)
381  {
382  }
383 
389  ClusterFromOrToMissing& operator=(const ClusterFromOrToMissing& other) throw()
390  {
391  if (&other == this) {
392  return *this;
393  }
394 
395  BaseException::operator=(other);
396 
397  return *this;
398  }
399 
403  virtual ~ClusterFromOrToMissing() throw()
404  {
405  }
406 
412  virtual const char *what() const throw()
413  {
414  return "The Cluster 'from' or 'to' is missing - Check your configuration file";
415  }
416 
421  EXCEPTION_HELPER_FUNCTIONS(ClusterFromOrToMissing)
422 };
423 
428 class FARSA_NNFW_TEMPLATE MatrixAssignmentNotAllowed : public BaseException
429 {
430 public:
435  BaseException()
436  {
437  }
438 
445  BaseException(other)
446  {
447  }
448 
455  {
456  if (&other == this) {
457  return *this;
458  }
459 
460  BaseException::operator=(other);
461 
462  return *this;
463  }
464 
468  virtual ~MatrixAssignmentNotAllowed() throw()
469  {
470  }
471 
477  virtual const char *what() const throw()
478  {
479  return "It is not allowed to use the operator=() on DoubleMatrix used as internal data";
480  }
481 
486  EXCEPTION_HELPER_FUNCTIONS(MatrixAssignmentNotAllowed)
487 };
488 
493 class FARSA_NNFW_TEMPLATE MatrixResizeNotAllowed : public BaseException
494 {
495 public:
500  BaseException()
501  {
502  }
503 
510  BaseException(other)
511  {
512  }
513 
519  MatrixResizeNotAllowed& operator=(const MatrixResizeNotAllowed& other) throw()
520  {
521  if (&other == this) {
522  return *this;
523  }
524 
525  BaseException::operator=(other);
526 
527  return *this;
528  }
529 
533  virtual ~MatrixResizeNotAllowed() throw()
534  {
535  }
536 
542  virtual const char *what() const throw()
543  {
544  return "It is not allowed to resize a DoubleMatrix used as internal data";
545  }
546 
551  EXCEPTION_HELPER_FUNCTIONS(MatrixResizeNotAllowed)
552 };
553 
558 class FARSA_NNFW_TEMPLATE IncompatibleMatrices : public BaseException
559 {
560 public:
568  IncompatibleMatrices(const char* description) throw() :
569  BaseException()
570  {
571  strncpy(m_description, description, 256);
572  m_description[255] = '\0';
573  }
574 
581  BaseException(other)
582  {
583  strncpy(m_description, other.m_description, 256);
584  m_description[255] = '\0';
585  }
586 
592  IncompatibleMatrices& operator=(const IncompatibleMatrices& other) throw()
593  {
594  if (&other == this) {
595  return *this;
596  }
597 
598  BaseException::operator=(other);
599  strncpy(m_description, other.m_description, 256);
600  m_description[255] = '\0';
601 
602  return *this;
603  }
604 
608  virtual ~IncompatibleMatrices() throw()
609  {
610  }
611 
617  virtual const char *what() const throw()
618  {
619  return m_description;
620  }
621 
627  const char *description() const throw()
628  {
629  return m_description;
630  }
631 
636  EXCEPTION_HELPER_FUNCTIONS(IncompatibleMatrices)
637 
638 private:
642  char m_description[256];
643 };
644 
649 class FARSA_NNFW_TEMPLATE OutsideMatrixBoundaries : public BaseException
650 {
651 public:
659  OutsideMatrixBoundaries(const char* description) throw() :
660  BaseException()
661  {
662  strncpy(m_description, description, 256);
663  m_description[255] = '\0';
664  }
665 
672  BaseException(other)
673  {
674  strncpy(m_description, other.m_description, 256);
675  m_description[255] = '\0';
676  }
677 
683  OutsideMatrixBoundaries& operator=(const OutsideMatrixBoundaries& other) throw()
684  {
685  if (&other == this) {
686  return *this;
687  }
688 
689  BaseException::operator=(other);
690  strncpy(m_description, other.m_description, 256);
691  m_description[255] = '\0';
692 
693  return *this;
694  }
695 
699  virtual ~OutsideMatrixBoundaries() throw()
700  {
701  }
702 
708  virtual const char *what() const throw()
709  {
710  return m_description;
711  }
712 
718  const char *description() const throw()
719  {
720  return m_description;
721  }
722 
727  EXCEPTION_HELPER_FUNCTIONS(OutsideMatrixBoundaries)
728 
729 private:
733  char m_description[256];
734 };
735 
740 class FARSA_NNFW_TEMPLATE OutputFunctionSetClusterException : public BaseException
741 {
742 public:
747  BaseException()
748  {
749  }
750 
757  BaseException(other)
758  {
759  }
760 
767  {
768  if (&other == this) {
769  return *this;
770  }
771 
772  BaseException::operator=(other);
773 
774  return *this;
775  }
776 
781  {
782  }
783 
789  virtual const char *what() const throw()
790  {
791  return "setCluster called on an OutputFunction already configured to be part of another Cluster!";
792  }
793 
798  EXCEPTION_HELPER_FUNCTIONS(OutputFunctionSetClusterException)
799 };
800 
805 class FARSA_NNFW_TEMPLATE ClusterStateVectorNotPresent : public BaseException
806 {
807 public:
815  ClusterStateVectorNotPresent(const char* description) throw() :
816  BaseException()
817  {
818  strncpy(m_description, description, 256);
819  m_description[255] = '\0';
820  }
821 
828  BaseException(other)
829  {
830  strncpy(m_description, other.m_description, 256);
831  m_description[255] = '\0';
832  }
833 
840  {
841  if (&other == this) {
842  return *this;
843  }
844 
845  BaseException::operator=(other);
846  strncpy(m_description, other.m_description, 256);
847  m_description[255] = '\0';
848 
849  return *this;
850  }
851 
855  virtual ~ClusterStateVectorNotPresent() throw()
856  {
857  }
858 
864  virtual const char *what() const throw()
865  {
866  return m_description;
867  }
868 
874  const char *description() const throw()
875  {
876  return m_description;
877  }
878 
883  EXCEPTION_HELPER_FUNCTIONS(ClusterStateVectorNotPresent)
884 
885 private:
889  char m_description[256];
890 };
891 
892 }
893 
894 #endif