Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:04:59

0001 // Copyright (c) 2015 OPEN CASCADE SAS
0002 //
0003 // This file is part of Open CASCADE Technology software library.
0004 //
0005 // This library is free software; you can redistribute it and/or modify it under
0006 // the terms of the GNU Lesser General Public License version 2.1 as published
0007 // by the Free Software Foundation, with special exception defined in the file
0008 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0009 // distribution for complete text of the license and disclaimer of any warranty.
0010 //
0011 // Alternatively, this file may be used under the terms of Open CASCADE
0012 // commercial license or contractual agreement.
0013 
0014 
0015 #ifndef _StdLPersistent_HArray2_HeaderFile
0016 #define _StdLPersistent_HArray2_HeaderFile
0017 
0018 #include <Standard_NotImplemented.hxx>
0019 #include <Standard_NullValue.hxx>
0020 
0021 #include <StdObjMgt_Persistent.hxx>
0022 #include <StdObjMgt_ReadData.hxx>
0023 #include <StdObjMgt_WriteData.hxx>
0024 
0025 #include <TColStd_HArray2OfInteger.hxx>
0026 #include <TColStd_HArray2OfReal.hxx>
0027 
0028 
0029 DEFINE_HARRAY2 (StdLPersistent_HArray2OfPersistent,
0030                 NCollection_Array2<Handle(StdObjMgt_Persistent)>)
0031 
0032 
0033 class StdLPersistent_HArray2
0034 {
0035   class base : public StdObjMgt_Persistent
0036   {
0037   public:
0038     //! Read persistent data from a file.
0039     Standard_EXPORT virtual void Read (StdObjMgt_ReadData& theReadData);
0040 
0041     //! Read persistent data from a file.
0042     Standard_EXPORT virtual void Write (StdObjMgt_WriteData& theWriteData) const;
0043 
0044   protected:
0045     virtual void lowerBound(Standard_Integer& theRow, 
0046                             Standard_Integer& theCol) const = 0;
0047     virtual void upperBound(Standard_Integer& theRow, 
0048                             Standard_Integer& theCol) const = 0;
0049     virtual void createArray(
0050       const Standard_Integer theLowerRow, const Standard_Integer theLowerCol,
0051       const Standard_Integer theUpperRow, const Standard_Integer theUpperCol)
0052         = 0;
0053 
0054     virtual void readValue (StdObjMgt_ReadData&    theReadData,
0055                             const Standard_Integer theRow,
0056                             const Standard_Integer theCol) = 0;
0057     virtual void writeValue(StdObjMgt_WriteData&   theWriteData,
0058                             const Standard_Integer theRow,
0059                             const Standard_Integer theCol) const = 0;
0060   };
0061 
0062 protected:
0063   template <class ArrayClass>
0064   class instance : public base
0065   {
0066     friend class StdLPersistent_HArray2;
0067 
0068   public:
0069     typedef Handle(ArrayClass) ArrayHandle;
0070 
0071   public:
0072     //! Get the array.
0073     const Handle(ArrayClass)& Array() const  { return myArray; }
0074 
0075   protected:
0076     virtual void lowerBound(Standard_Integer& theRow,
0077       Standard_Integer& theCol) const
0078     {
0079       theRow = myArray->LowerRow(); 
0080       theCol = myArray->LowerCol();
0081     }
0082     virtual void upperBound(Standard_Integer& theRow,
0083       Standard_Integer& theCol) const
0084     { 
0085       theRow = myArray->UpperRow(); 
0086       theCol = myArray->UpperCol(); 
0087     }
0088     virtual void createArray(
0089       const Standard_Integer theLowerRow, const Standard_Integer theLowerCol,
0090       const Standard_Integer theUpperRow, const Standard_Integer theUpperCol)
0091     {
0092       myArray = new ArrayClass (theLowerRow, theUpperRow,
0093                                 theLowerCol, theUpperCol);
0094     }
0095     virtual void readValue (StdObjMgt_ReadData&    theReadData,
0096                             const Standard_Integer theRow,
0097                             const Standard_Integer theCol)
0098       { theReadData >> myArray->ChangeValue (theRow, theCol); }
0099     virtual void writeValue(StdObjMgt_WriteData&   theWriteData,
0100                             const Standard_Integer theRow,
0101                             const Standard_Integer theCol) const
0102     {
0103       theWriteData << myArray->Value(theRow, theCol);
0104     }
0105     virtual void PChildren(StdObjMgt_Persistent::SequenceOfPersistent& theChildren) const
0106       { return PChildrenT(theChildren); }
0107     virtual Standard_CString PName() const
0108       { return PNameT(); }
0109     Standard_CString PNameT() const
0110     {
0111       Standard_NotImplemented::Raise("StdLPersistent_HArray2::instance::PName - not implemented");
0112       return "";
0113     }
0114     void PChildrenT(StdObjMgt_Persistent::SequenceOfPersistent&) const {}
0115 
0116   protected:
0117     Handle(ArrayClass) myArray;
0118   };
0119 
0120   template <class ArrayClass>
0121   class named_instance : public instance<ArrayClass>
0122   {
0123     friend class StdLPersistent_HArray2;
0124 
0125   public:
0126     virtual Standard_CString PName() const
0127     {
0128       Standard_NullValue_Raise_if(!myPName,
0129         "StdLPersistent_HArray2::named_instance::PName - name not set");
0130       return myPName;
0131     }
0132 
0133   protected:
0134     named_instance(Standard_CString thePName) : myPName(thePName) {}
0135 
0136     Standard_CString myPName;
0137   };
0138 
0139 public:
0140   typedef instance<TColStd_HArray2OfInteger>           Integer;
0141   typedef instance<TColStd_HArray2OfReal>              Real;
0142   typedef instance<StdLPersistent_HArray2OfPersistent> Persistent;
0143 
0144 public:
0145   template <class ArrayClass>
0146   static Handle(instance<ArrayClass>) Translate(const ArrayClass& theArray)
0147   {
0148     Handle(instance<ArrayClass>) aPArray = new instance<ArrayClass>;
0149     aPArray->myArray = new ArrayClass(theArray.LowerRow(), theArray.UpperRow(),
0150       theArray.LowerCol(), theArray.UpperCol());
0151     for (Standard_Integer i = theArray.LowerRow(); i <= theArray.UpperRow(); ++i)
0152       for (Standard_Integer j = theArray.LowerCol(); j <= theArray.UpperCol(); ++j)
0153         aPArray->myArray->ChangeValue(i, j) = theArray.Value(i, j);
0154     return aPArray;
0155   }
0156   template <class ArrayClass>
0157   static Handle(instance<ArrayClass>) Translate(Standard_CString thePName, const ArrayClass& theArray)
0158   {
0159     Handle(named_instance<ArrayClass>) aPArray = new named_instance<ArrayClass>(thePName);
0160     aPArray->myArray = new ArrayClass(theArray.LowerRow(), theArray.UpperRow(),
0161       theArray.LowerCol(), theArray.UpperCol());
0162     for (Standard_Integer i = theArray.LowerRow(); i <= theArray.UpperRow(); ++i)
0163       for (Standard_Integer j = theArray.LowerCol(); j <= theArray.UpperCol(); ++j)
0164         aPArray->myArray->ChangeValue(i, j) = theArray.Value(i, j);
0165     return aPArray;
0166   }
0167 };
0168 
0169 template<>
0170 inline Standard_CString StdLPersistent_HArray2::instance<TColStd_HArray2OfInteger>::PNameT() const
0171   { return "PColStd_HArray2OfInteger"; }
0172 
0173 template<>
0174 inline Standard_CString StdLPersistent_HArray2::instance<TColStd_HArray2OfReal>::PNameT() const
0175   { return "PColStd_HArray2OfReal"; }
0176 
0177 template<>
0178 inline void StdLPersistent_HArray2::instance<StdLPersistent_HArray2OfPersistent>::PChildrenT
0179   (StdObjMgt_Persistent::SequenceOfPersistent& theChildren) const
0180   { 
0181     for (Standard_Integer i = myArray->LowerRow(); i <= myArray->UpperRow(); ++i)
0182       for (Standard_Integer j = myArray->LowerCol(); j <= myArray->UpperCol(); ++j)
0183         theChildren.Append(myArray->Value(i, j));
0184   }
0185 
0186 #endif