Back to index

salome-med  6.5.0
MEDMEM_IndexCheckingPolicy.hxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 #ifndef MEDMEM_INDEX_CHECKING_POLICY_HXX
00024 #define MEDMEM_INDEX_CHECKING_POLICY_HXX 
00025 
00026 #include <MEDMEM.hxx>
00027 
00028 #include "MEDMEM_Exception.hxx"
00029 #include "MEDMEM_STRING.hxx"
00030 
00031 namespace MEDMEM {
00032 
00033 class MEDMEM_EXPORT IndexCheckPolicy {
00034 public :
00035   inline void checkMoreThanZero(const std::string & classname, int index) const {
00036     if (index <= 0)
00037       throw MEDEXCEPTION(LOCALIZED(STRING("In ") << classname << ", index : " << index << " is less or equal to zero"));
00038   }
00039   inline void checkLessOrEqualThan(const std::string & classname, int max, int index) const {
00040     if (index > max)
00041       throw MEDEXCEPTION(LOCALIZED(STRING("In ") << classname << ", index : " << index << " is more than " << max ));
00042   }
00043 
00044   inline void checkInInclusiveRange(const std::string & classname, int min, int max, int index) const {
00045     if (index < min || index > max )
00046       throw MEDEXCEPTION(LOCALIZED(STRING("In ") << classname << ", index : " << index 
00047                                            << " not in rang [" << min << "," << max <<"]"));
00048   }
00049 
00050   inline void checkEquality(const std::string & classname, int a, int b) const {
00051     if ( a == b )
00052       throw MEDEXCEPTION(LOCALIZED(STRING("In ") << classname << ", Value shouldn't be : " << a ));
00053   }
00054 
00055 };
00056 
00057 class MEDMEM_EXPORT NoIndexCheckPolicy {
00058 public :
00059   inline void checkMoreThanZero(const string &classname, int index) const {}
00060   inline void checkLessOrEqualThan(const std::string & classname, int max, int index) const {}
00061   inline void checkInInclusiveRange(const std::string & classname, int min, int max, int index) const {}
00062   inline void checkEquality(const std::string & classname, int a, int b) const {}
00063 };
00064 
00065 }// END NAMESPACE
00066 #endif