]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
Protections on Fields against null pointers
authorageay <ageay>
Thu, 4 Apr 2013 07:59:09 +0000 (07:59 +0000)
committerageay <ageay>
Thu, 4 Apr 2013 07:59:09 +0000 (07:59 +0000)
src/MEDCoupling/MEDCouplingNatureOfField.cxx
src/MEDCoupling/MEDCouplingNatureOfField.hxx

index da684878fac0d2998b76cbd4c322d439b4d7a69f..3c44332fb538f77db282173a4bf8d95a603a93a2 100644 (file)
@@ -21,6 +21,7 @@
 #include "MEDCouplingNatureOfField.hxx"
 
 #include <algorithm>
+#include <sstream>
 
 namespace ParaMEDMEM
 {
@@ -37,7 +38,11 @@ namespace ParaMEDMEM
   {
     const int *pos=std::find(POS_OF_NATUREOFFIELD,POS_OF_NATUREOFFIELD+NB_OF_POSSIBILITIES,(int)nat);
     if(pos==POS_OF_NATUREOFFIELD+NB_OF_POSSIBILITIES)
-      throw INTERP_KERNEL::Exception("MEDCouplingNatureOfField::getRepr : Unrecognized nature of field !");
+      {
+        std::ostringstream oss; oss << "MEDCouplingNatureOfField::getRepr : Unrecognized nature of field ! ";
+        oss << GetAllPossibilitiesStr() << " !";
+        throw INTERP_KERNEL::Exception(oss.str().c_str());
+      }
     std::size_t pos2=std::distance(POS_OF_NATUREOFFIELD,pos);
     return REPR_OF_NATUREOFFIELD[pos2];
   }
@@ -50,5 +55,16 @@ namespace ParaMEDMEM
     std::size_t pos2=std::distance(POS_OF_NATUREOFFIELD,pos);
     return std::string(REPR_OF_NATUREOFFIELD[pos2]);
   }
+
+  std::string MEDCouplingNatureOfField::GetAllPossibilitiesStr()
+  {
+    std::ostringstream oss; oss << "Possibilities are : ";
+    for(int i=0;i<NB_OF_POSSIBILITIES;i++)
+      {
+        oss << REPR_OF_NATUREOFFIELD[i] << "(value=" << POS_OF_NATUREOFFIELD[i] << ")";
+        if(i!=NB_OF_POSSIBILITIES-1)
+          oss << ", ";
+      }
+    return oss.str();
+  }
 }
index 0061b495226676b09b9572570b54166ec7c53c77..bc9e0caf4cb0aeb41ad3d7d4d80fcf6a0cc53e11 100644 (file)
@@ -40,6 +40,7 @@ namespace ParaMEDMEM
   public:
     MEDCOUPLING_EXPORT static const char *GetRepr(NatureOfField nat) throw(INTERP_KERNEL::Exception);
     MEDCOUPLING_EXPORT static std::string GetReprNoThrow(NatureOfField nat);
+    MEDCOUPLING_EXPORT static std::string GetAllPossibilitiesStr();
   private:
     static const int NB_OF_POSSIBILITIES=5;
     static const char *REPR_OF_NATUREOFFIELD[NB_OF_POSSIBILITIES];