Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[modules/med.git] / src / MEDWrapper / Base / MED_SliceArray.hxx
index 5364d32e21e2e251ad3cc07f8db053b440230818..cce9c465caee4e93b4fab3c9789530eaf3284989 100644 (file)
 #ifndef MED_SliceArray_HeaderFile
 #define MED_SliceArray_HeaderFile
 
+#ifdef WNT // for correctly compiling "valarray" in modules, which are includes this file
+  #undef max
+  #undef min
+#endif
+
 #include <valarray>
 #include <stdexcept>
 
@@ -45,12 +50,13 @@ namespace MED
     This class deal with constant pointer to the sources data and provide const method to
     read the them (data).
    */
-  template<class TContainer
+  template<class TValueType
   class TCSlice
   {
-    typedef const TContainer* PCContainer;
-    PCContainer myCContainer; //!< Reference to source multy-dimension data
+    const TValueType* myCValuePtr; //!< Reference to source multy-dimension data
+    size_t mySourceSize; //!< Size of the source multy-dimension data
     std::slice mySlice; //!< Defines algorithm of index calculation
+
   protected:
     void
     check_id(size_t theId) const
@@ -58,7 +64,7 @@ namespace MED
       long int anId = -1;
       if(theId < mySlice.size()){
        anId = mySlice.start() + theId*mySlice.stride();
-       if(anId < myCContainer->size())
+       if(anId < mySourceSize)
          return;
       }
       throw std::out_of_range("TCSlice::check_id");
@@ -88,31 +94,41 @@ namespace MED
     }
 
   public:
-    typedef typename TContainer::value_type value_type;
+    typedef TValueType value_type;
 
-    //! Construct the class
-    TCSlice(const TContainer& theContainer,
+    //! Construct the class from bare pointer
+    TCSlice(const value_type* theValuePtr,
+           size_t theSourceSize,
+           const std::slice& theSlice): 
+      myCValuePtr(theValuePtr),
+      mySourceSize(theSourceSize),
+      mySlice(theSlice)
+    {}
+    
+    //! Construct the class from corresponding container
+    TCSlice(const TVector<value_type>& theContainer,
            const std::slice& theSlice): 
-      myCContainer(&theContainer),
+      myCValuePtr(&theContainer[0]),
+      mySourceSize(theContainer.size()),
       mySlice(theSlice)
     {}
     
     //! Default constructor (dangerous)
     TCSlice():
-      myCContainer(NULL)
+      myCValuePtr(NULL)
     {}
 
     //! Get element by its number (const version)
     const value_type& 
     operator[](size_t theId) const
     {
-      return (*myCContainer)[get_id(theId)];
+      return *(myCValuePtr + get_id(theId));
     }
     
     const value_type& 
     at(size_t theId) const
     {
-      return (*myCContainer)[get_id_at(theId)];
+      return *(myCValuePtr + get_id_at(theId));
     }
     
     //! Get range of the order numbers
@@ -126,40 +142,46 @@ namespace MED
 
   //---------------------------------------------------------------
   //! This class extend TCSlice functionality for non-constant case
-  template<class TContainer
-  class TSlice: public TCSlice<TContainer>
+  template<class TValueType
+  class TSlice: public TCSlice<TValueType>
   {
-    typedef TContainer* PContainer;
-    PContainer myContainer;
+    TValueType* myValuePtr;
     
   public:
-    typedef typename TContainer::value_type value_type;
-    typedef TCSlice<TContainer> TSupperClass;
+    typedef TValueType value_type;
+    typedef TCSlice<TValueType> TSupperClass;
 
-    //! Construct the class
-    TSlice(TContainer& theContainer,
+    //! Construct the class from bare pointer
+    TSlice(value_type* theValuePtr,
+          size_t theSourceSize,
           const std::slice& theSlice): 
-      TSupperClass(theContainer,theSlice),
-      myContainer(&theContainer)
-    {
-    }
+      TSupperClass(theValuePtr, theSourceSize, theSlice),
+      myValuePtr(theValuePtr)
+    {}
+    
+    //! Construct the class from corresponding container
+    TSlice(TVector<value_type>& theContainer,
+          const std::slice& theSlice): 
+      TSupperClass(theContainer, theSlice),
+      myValuePtr(&theContainer[0])
+    {}
     
     //! Default constructor (dangerous)
     TSlice():
-      myContainer(NULL)
+      myValuePtr(NULL)
     {}
 
     //! Get element by its number
     value_type& 
     operator[](size_t theId)
     {
-      return (*myContainer)[this->get_id(theId)];
+      return *(myValuePtr + this->get_id(theId));
     }
 
     value_type& 
     at(size_t theId)
     {
-      return (*myContainer)[this->get_id_at(theId)];
+      return *(myValuePtr + this->get_id_at(theId));
     }
   };