From: apo Date: Tue, 25 Jan 2005 14:26:53 +0000 (+0000) Subject: CEA DEN - PAL/SALOME 2005 - L1.4.1 - Polyhedral elements - access to connectivities... X-Git-Tag: V2_2_0b1~12 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=baa79fa81a63eb159a39b3784be811a6057bef9c;p=modules%2Fkernel.git CEA DEN - PAL/SALOME 2005 - L1.4.1 - Polyhedral elements - access to connectivities through slice_array --- diff --git a/src/MEDWrapper/Base/MED_Common.hxx b/src/MEDWrapper/Base/MED_Common.hxx index 5cac8fbd1..02f992ea1 100644 --- a/src/MEDWrapper/Base/MED_Common.hxx +++ b/src/MEDWrapper/Base/MED_Common.hxx @@ -29,8 +29,10 @@ #ifndef MED_Common_HeaderFile #define MED_Common_HeaderFile -#include +#include +#include #include +#include #include #include @@ -42,16 +44,19 @@ extern "C"{ namespace MED{ - template class shared_ptr: public boost::shared_ptr + enum EVersion {eVUnknown = -1, eV2_1, eV2_2}; + + + template class SharedPtr: public boost::shared_ptr { public: - shared_ptr() {} + SharedPtr() {} template - explicit shared_ptr(Y * p): boost::shared_ptr(p) {} + explicit SharedPtr(Y * p): boost::shared_ptr(p) {} template - shared_ptr(shared_ptr const & r): boost::shared_ptr(r) {} + SharedPtr(SharedPtr const & r): boost::shared_ptr(r) {} operator const T& () const { return *get();} @@ -59,6 +64,66 @@ namespace MED{ }; + template + class ConstSliceArray + { + const TContainer& myConstContainer; + std::slice mySlice; + protected: + size_t GetID(size_t theId) const + { + if(theId < mySlice.size()){ + size_t anId = mySlice.start() + theId*mySlice.stride(); + if(anId < myConstContainer.size()) + return anId; + } + throw std::out_of_range(); + return -1; + } + + public: + typedef typename TContainer::value_type TValue; + + ConstSliceArray(const TContainer& theContainer, + const std::slice& theSlice): + myConstContainer(theContainer), + mySlice(theSlice) + { + } + + const TValue& operator[](size_t theId) const + { + return myConstContainer[GetID(theId)]; + } + + size_t size() const + { + return mySlice.size(); + } + }; + + + template + class SliceArray: public ConstSliceArray + { + TContainer& myContainer; + + public: + typedef ConstSliceArray TSupperClass; + SliceArray(TContainer& theContainer, + const std::slice& theSlice): + TSupperClass(theContainer,theSlice), + myContainer(theContainer) + { + } + + typename TSupperClass::TValue& operator[](size_t theId) + { + return myContainer[GetID(theId)]; + } + }; + + typedef enum {eFAUX, eVRAI} EBooleen ; typedef double TFloat; typedef int TInt; @@ -97,10 +162,6 @@ namespace MED{ const TEntity2GeomSet& GetEntity2GeomSet(); - enum EVersion {eVUnknown = -1, eV2_1, eV2_2}; - - TInt GetNbConnectivities(EGeometrieElement typmai); - template TInt GetNbConn(EGeometrieElement typmai, TInt mdim); @@ -113,41 +174,43 @@ namespace MED{ TInt GetNbConn(EGeometrieElement typmai, TInt mdim); + TInt GetNbConnectivities(EGeometrieElement typmai); + struct TNameInfo; - typedef MED::shared_ptr PNameInfo; + typedef SharedPtr PNameInfo; struct TMeshInfo; - typedef MED::shared_ptr PMeshInfo; + typedef SharedPtr PMeshInfo; struct TFamilyInfo; - typedef MED::shared_ptr PFamilyInfo; + typedef SharedPtr PFamilyInfo; struct TElemInfo; - typedef MED::shared_ptr PElemInfo; + typedef SharedPtr PElemInfo; struct TNodeInfo; - typedef MED::shared_ptr PNodeInfo; + typedef SharedPtr PNodeInfo; struct TPolygoneInfo; - typedef MED::shared_ptr PPolygoneInfo; + typedef SharedPtr PPolygoneInfo; struct TPolyedreInfo; - typedef MED::shared_ptr PPolyedreInfo; + typedef SharedPtr PPolyedreInfo; struct TCellInfo; - typedef MED::shared_ptr PCellInfo; + typedef SharedPtr PCellInfo; struct TFieldInfo; - typedef MED::shared_ptr PFieldInfo; + typedef SharedPtr PFieldInfo; struct TTimeStampInfo; - typedef MED::shared_ptr PTimeStampInfo; + typedef SharedPtr PTimeStampInfo; struct TTimeStampVal; - typedef MED::shared_ptr PTimeStampVal; + typedef SharedPtr PTimeStampVal; class TWrapper; - typedef MED::shared_ptr PWrapper; + typedef SharedPtr PWrapper; }; diff --git a/src/MEDWrapper/Base/MED_Structures.cxx b/src/MEDWrapper/Base/MED_Structures.cxx index 3ec5eece4..24185816f 100644 --- a/src/MEDWrapper/Base/MED_Structures.cxx +++ b/src/MEDWrapper/Base/MED_Structures.cxx @@ -123,6 +123,19 @@ TInt TCellInfo::GetConn(TInt theElemId, TInt theConnId) const { void TCellInfo::SetConn(TInt theElemId, TInt theConnId, TInt theVal){ GETINDEX(myConn,GetConnDim()*theElemId + theConnId) = theVal; } + +TConstConnSlice +TCellInfo::GetConnSlice(TInt theElemId) const +{ + return TConstConnSlice(myConn,std::slice(GetConnDim()*theElemId,GetNbConnectivities(myTGeom),1)); +} + +TConnSlice +TCellInfo::GetConnSlice(TInt theElemId) +{ + return TConnSlice(myConn,std::slice(GetConnDim()*theElemId,GetNbConnectivities(myTGeom),1)); +} + //--------------------------------------------------------------- TInt TPolygoneInfo::GetNbConn(TInt theElemId) const { TInt i1 = GETINDEX(myIndex,theElemId); diff --git a/src/MEDWrapper/Base/MED_Structures.hxx b/src/MEDWrapper/Base/MED_Structures.hxx index 888c3aeb1..12e131bdd 100644 --- a/src/MEDWrapper/Base/MED_Structures.hxx +++ b/src/MEDWrapper/Base/MED_Structures.hxx @@ -165,6 +165,9 @@ namespace MED{ //--------------------------------------------------------------- + typedef SliceArray TConnSlice; + typedef ConstSliceArray TConstConnSlice; + struct TCellInfo: virtual TElemInfo { EEntiteMaillage myTEntity; @@ -179,6 +182,9 @@ namespace MED{ virtual TInt GetConnDim() const = 0; TElemNum myConn; + TConstConnSlice GetConnSlice(TInt theElemId) const; + TConnSlice GetConnSlice(TInt theElemId); + TInt GetConn(TInt theElemId, TInt theConnId) const; void SetConn(TInt theElemId, TInt theConnId, TInt theVal); };