Salome HOME
Ensure sequential run of MEDLoader 1,2,3 tests.
[tools/medcoupling.git] / src / MEDCoupling / MEDCouplingMemArray.txx
index bff8f089b993d10a161006dbc4b211f79211000d..fa5fac7a0c7578b0368277b63816ad7a5c0ea7fb 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2014  CEA/DEN, EDF R&D
+// Copyright (C) 2007-2015  CEA/DEN, EDF R&D
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
@@ -30,7 +30,7 @@
 #include <cstdlib>
 #include <algorithm>
 
-namespace ParaMEDMEM
+namespace MEDCoupling
 {
   template<class T>
   void MEDCouplingPointer<T>::setInternal(T *pointer)
@@ -82,7 +82,7 @@ namespace ParaMEDMEM
     _ownership=false;
     _dealloc=CPPDeallocator;
   }
-  
+
   template<class T>
   void MemArray<T>::writeOnPlace(std::size_t id, T element0, const T *others, std::size_t sizeOfOthers)
   {
@@ -93,7 +93,7 @@ namespace ParaMEDMEM
     std::copy(others,others+sizeOfOthers,pointer+id+1);
     _nb_of_elem=std::max<std::size_t>(_nb_of_elem,id+sizeOfOthers+1);
   }
-  
+
   template<class T>
   template<class InputIterator>
   void MemArray<T>::insertAtTheEnd(InputIterator first, InputIterator last)
@@ -109,7 +109,7 @@ namespace ParaMEDMEM
         pointer[_nb_of_elem++]=*first++;
       }
   }
-  
+
   template<class T>
   void MemArray<T>::pushBack(T elem)
   {
@@ -118,7 +118,7 @@ namespace ParaMEDMEM
     T *pt=getPointer();
     pt[_nb_of_elem++]=elem;
   }
-  
+
   template<class T>
   T MemArray<T>::popBack()
   {
@@ -129,7 +129,7 @@ namespace ParaMEDMEM
       }
     throw INTERP_KERNEL::Exception("MemArray::popBack : nothing to pop in array !");
   }
-  
+
   template<class T>
   void MemArray<T>::pack() const
   {
@@ -180,7 +180,7 @@ namespace ParaMEDMEM
       {
         if(sl!=0)
           stream << _nb_of_elem/sl << std::endl << "Internal memory facts : " << _nb_of_elem << "/" << _nb_of_elem_alloc;
-       else
+        else
           stream << "Empty Data";
       }
     else
@@ -192,7 +192,7 @@ namespace ParaMEDMEM
       stream << "No data !\n";
     return ret;
   }
-  
+
   /*!
    * \param [in] sl is typically the number of components
    */
@@ -217,7 +217,7 @@ namespace ParaMEDMEM
           stream << "Empty Data\n";
       }
   }
-  
+
   /*!
    * \param [in] sl is typically the number of components
    */
@@ -257,14 +257,58 @@ namespace ParaMEDMEM
     else
       stream << "No data !\n";
   }
-  
+
+  /*!
+   * \param [in] sl is typically the number of components
+   */
+  template<class T>
+  void MemArray<T>::reprNotTooLong(int sl, std::ostream& stream) const
+  {
+    if(reprHeader(sl,stream))
+      {
+        const T *data=getConstPointer();
+        if(_nb_of_elem!=0 && sl!=0)
+          {
+            std::size_t nbOfTuples=_nb_of_elem/std::abs(sl);
+            if(nbOfTuples<=1000)
+              {
+                for(std::size_t i=0;i<nbOfTuples;i++)
+                  {
+                    stream << "Tuple #" << i << " : ";
+                    std::copy(data,data+sl,std::ostream_iterator<T>(stream," "));
+                    stream << "\n";
+                    data+=sl;
+                  }
+              }
+            else
+              {// too much tuples -> print the 3 first tuples and 3 last.
+                stream << "Tuple #0 : ";
+                std::copy(data,data+sl,std::ostream_iterator<T>(stream," ")); stream << "\n";
+                stream << "Tuple #1 : ";
+                std::copy(data+sl,data+2*sl,std::ostream_iterator<T>(stream," ")); stream << "\n";
+                stream << "Tuple #2 : ";
+                std::copy(data+2*sl,data+3*sl,std::ostream_iterator<T>(stream," ")); stream << "\n";
+                stream << "...\n";
+                stream << "Tuple #" << nbOfTuples-3 << " : ";
+                std::copy(data+(nbOfTuples-3)*sl,data+(nbOfTuples-2)*sl,std::ostream_iterator<T>(stream," ")); stream << "\n";
+                stream << "Tuple #" << nbOfTuples-2 << " : ";
+                std::copy(data+(nbOfTuples-2)*sl,data+(nbOfTuples-1)*sl,std::ostream_iterator<T>(stream," ")); stream << "\n";
+                stream << "Tuple #" << nbOfTuples-1 << " : ";
+                std::copy(data+(nbOfTuples-1)*sl,data+nbOfTuples*sl,std::ostream_iterator<T>(stream," ")); stream << "\n";
+              }
+          }
+        else
+          stream << "Empty Data\n";
+      }
+  }
+
   template<class T>
   void MemArray<T>::fillWithValue(const T& val)
   {
     T *pt=_pointer.getPointer();
     std::fill(pt,pt+_nb_of_elem,val);
   }
-  
+
   template<class T>
   T *MemArray<T>::fromNoInterlace(int nbOfComp) const
   {
@@ -279,7 +323,7 @@ namespace ParaMEDMEM
         *w=pt[j*nbOfTuples+i];
     return ret;
   }
-  
+
   template<class T>
   T *MemArray<T>::toNoInterlace(int nbOfComp) const
   {
@@ -409,14 +453,14 @@ namespace ParaMEDMEM
   typename MemArray<T>::Deallocator MemArray<T>::BuildFromType(DeallocType type)
   {
     switch(type)
-      {
+    {
       case CPP_DEALLOC:
         return CPPDeallocator;
       case C_DEALLOC:
         return CDeallocator;
       default:
         throw INTERP_KERNEL::Exception("Invalid deallocation requested ! Unrecognized enum DeallocType !");
-      }
+    }
   }
 
   template<class T>
@@ -438,7 +482,7 @@ namespace ParaMEDMEM
     _nb_of_elem=0;
     _nb_of_elem_alloc=0;
   }
-  
+
   template<class T>
   MemArray<T> &MemArray<T>::operator=(const MemArray<T>& other)
   {