bpp-core  2.1.0
VectorExceptions.h
Go to the documentation of this file.
00001 //
00002 // File: VectorExceptions.h
00003 // Created by: Julien Dutheil
00004 // Created on: 2003
00005 //
00006 
00007 /*
00008 Copyright or © or Copr. Bio++ Development Team, (November 17, 2004)
00009 
00010 This software is a computer program whose purpose is to provide classes
00011 for numerical calculus.
00012 
00013 This software is governed by the CeCILL  license under French law and
00014 abiding by the rules of distribution of free software.  You can  use, 
00015 modify and/ or redistribute the software under the terms of the CeCILL
00016 license as circulated by CEA, CNRS and INRIA at the following URL
00017 "http://www.cecill.info". 
00018 
00019 As a counterpart to the access to the source code and  rights to copy,
00020 modify and redistribute granted by the license, users are provided only
00021 with a limited warranty  and the software's author,  the holder of the
00022 economic rights,  and the successive licensors  have only  limited
00023 liability. 
00024 
00025 In this respect, the user's attention is drawn to the risks associated
00026 with loading,  using,  modifying and/or developing or reproducing the
00027 software by the user in light of its specific status of free software,
00028 that may mean  that it is complicated to manipulate,  and  that  also
00029 therefore means  that it is reserved for developers  and  experienced
00030 professionals having in-depth computer knowledge. Users are therefore
00031 encouraged to load and test the software's suitability as regards their
00032 requirements in conditions enabling the security of their systems and/or 
00033 data to be ensured and,  more generally, to use and operate it in the 
00034 same conditions as regards security. 
00035 
00036 The fact that you are presently reading this means that you have had
00037 knowledge of the CeCILL license and that you accept its terms.
00038 */
00039 
00040 #ifndef _VECTOREXCEPTIONS_H_
00041 #define _VECTOREXCEPTIONS_H_
00042 
00043 #include "../Exceptions.h"
00044 #include "../Text/TextTools.h"
00045 
00046 //From the STL/
00047 #include <string>
00048 #include <vector>
00049 
00050 namespace bpp
00051 {
00052 
00056 template<class T>
00057 class VectorException :
00058   public Exception
00059 {
00060 
00061   protected:
00062     const std::vector<T> * vect_;
00063       
00064   public:
00065     VectorException(const std::string& text, const std::vector<T>* vect = 0) :
00066       Exception("VectorException: " + text),
00067       vect_(vect) {};
00068 
00069     VectorException(const VectorException& ve): Exception(ve), vect_(ve.vect_) {}
00070     VectorException& operator=(const VectorException& ve)
00071     {
00072       Exception::operator=(ve);
00073       vect_ = ve.vect_;
00074       return *this;
00075     }
00076   
00077     virtual ~VectorException() throw () {};
00078     
00079   public:
00080     virtual const std::vector<T>* getVector() const { return vect_; }
00081 };
00082 
00086 template<class T>
00087 class EmptyVectorException :
00088   public VectorException<T>
00089 {
00090 
00091   public:
00092     EmptyVectorException(const std::string& text, const std::vector<T>* vect = 0) :
00093       VectorException<T>("EmptyVectorException: " + text, vect) {};
00094   
00095     virtual ~EmptyVectorException() throw () {}
00096 };
00097 
00101 class DimensionException :
00102   public Exception
00103 {
00104   private:
00105     size_t dimension_;
00106     size_t correctDimension_; 
00107       
00108   public:
00109     DimensionException(const std::string& text, size_t dimension, size_t correctDimension) :
00110         Exception("DimensionException (found " + TextTools::toString(dimension) + ", should be " + TextTools::toString(correctDimension) + ") " + text),
00111         dimension_(dimension),
00112         correctDimension_(correctDimension) {};
00113   
00114     virtual ~DimensionException() throw () {}
00115 
00116   public:
00117     virtual size_t getDimension() const { return dimension_; }
00118     virtual size_t getCorrectDimension() const { return correctDimension_; }
00119 };
00120 
00124 template<class T> class ElementNotFoundException :
00125   public VectorException<T>
00126 {
00127 
00128   private:
00129     const T* element_;
00130       
00131   public:
00132     ElementNotFoundException(const std::string& text, const std::vector<T>* vect = 0, const T* element = 0) :
00133       VectorException<T>("ElementNotFoundException: " + text, vect),
00134       element_(element) {};
00135 
00136     ElementNotFoundException(const ElementNotFoundException& enfe):
00137       VectorException<T>(enfe), element_(enfe.element_) {}
00138     
00139     ElementNotFoundException& operator=(const ElementNotFoundException& enfe)
00140     {
00141       VectorException<T>::operator=(enfe);
00142       element_ = enfe.element_;
00143       return *this;
00144     }
00145 
00146     virtual ~ElementNotFoundException() throw () {};
00147     
00148   public:
00149     virtual const T* getElement() const { return element_; }
00150 };
00151 
00152 } //end of namespace bpp.
00153 
00154 #endif //_VECTOREXCEPTIONS_H_
00155 
 All Classes Namespaces Files Functions Variables Typedefs Friends