Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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 }
00066 #endif