Changeset 4035 in Sophya


Ignore:
Timestamp:
Nov 14, 2011, 5:28:25 PM (13 years ago)
Author:
ansari
Message:

1/ modif mineure ds TArray<T>::::ReadASCII() au print level global de BaseArray
2/ Correction bug gestion memoire au niveau des constructeurs de copie TArray/TMatrix/TVector
avec un BaseArray en argument. Ajout argument optionnel bool pack a ces constructeurs
3/ On autorise desormais la creation des objets TArray/TMatrix/TVector par constructeur de
copie sur des objets non alloues

Reza, 14/11/2011

Location:
trunk/SophyaLib/TArray
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaLib/TArray/basarr.cc

    r3669 r4035  
    118118     mm == FortranMemoryMapping : Fortran like memory mapping
    119119  \endverbatim
     120  \return default memory mapping value
    120121  \verbatim
    121122  # ===== For Matrices
     
    138139     ex: Mc[2][0] = Mmath(3,1) = 31
    139140         Mc[0][2] = Mmath(1,3) = 13
    140   *** RESUME diff Idl/Fortan/C/Math:
     141  *** SUMMARY difference Idl/Fortan/C/Math:
    141142    Midl(col-1,row-1) = Mfor(col,row) = Mc[row-1][col-1] = Mmath(row,col)
    142143    TRANSPOSE(column-major array) --> row-major array
    143144  \endverbatim
    144   \return default memory mapping value
    145145 */
    146146short BaseArray::SetDefaultMemoryMapping(short mm)
     
    565565}
    566566
    567 //! Return attached DVList
     567//! Return the attached DVList info object
    568568DVList& BaseArray::Info()
    569569{
     
    571571return(*mInfo);
    572572}
     573
     574
    573575
    574576//! Update sizes and information for array
  • trunk/SophyaLib/TArray/basarr.h

    r3572 r4035  
    160160  virtual void   WriteASCII(ostream& os) const = 0;
    161161
    162   // DVList info Object
     162  // Access to the DVList info Object
    163163  DVList& Info();
     164  //! return true if the  DVList info Object has been created (not empty)
     165  inline bool HasInfoObject() const { return ((mInfo!=NULL)?true:false); } 
     166
     167//! Return the attached DVList object pointer (for special uses only TArray ... )
     168  inline DVList* getInfoPointer() const { return mInfo; }
    164169
    165170protected:
  • trunk/SophyaLib/TArray/tarray.cc

    r3850 r4035  
    197197  : BaseArray() , mNDBlock(a.mNDBlock)
    198198{
     199  if (a.NbDimensions() == 0)  return;    // Reza-Nov 2011: we allow copy contrsuctor on non allocated arrays 
    199200  string exmsg = "TArray<T>::TArray(const TArray<T>&)";
    200201  if (!UpdateSizes(a, exmsg))  throw( ParmError(exmsg) );
     
    210211  : BaseArray() , mNDBlock(a.mNDBlock, share)
    211212{
    212   if (a.NbDimensions() == 0)  return; 
     213  if (a.NbDimensions() == 0)  return;  // Reza-Nov 2011: we allow copy contrsuctor on non allocated arrays 
    213214  string exmsg = "TArray<T>::TArray(const TArray<T>&, bool)";
    214215  if (!UpdateSizes(a, exmsg))  throw( ParmError(exmsg) );
     
    216217}
    217218
    218 //! Constructor with size and contents copied (after conversion) from a different type TArray
    219 template <class T>
    220 TArray<T>::TArray(const BaseArray& a)
     219//! Constructor with size and contents copied (after conversion) from an array with different data type.
     220/*!
     221  The array size and memory layout are copied from the array \b a, or a packed array is created if \b pack==true.
     222  \param a : original array, to copy sizes and data from
     223  \param pack : if \b true , create a packed array, else same memory layout as \b a.
     224*/
     225template <class T>
     226TArray<T>::TArray(const BaseArray& a, bool pack)
    221227  : BaseArray() , mNDBlock()
    222228{
    223229  if (a.NbDimensions() == 0)  return; 
    224   string exmsg = "TArray<T>::TArray(const BaseArray&)";
    225   if (!UpdateSizes(a, exmsg))  throw( ParmError(exmsg) );
    226   mNDBlock.ReSize(totsize_);   
    227   //  if (a.mInfo) mInfo = new DVList(*(a.mInfo));  - pb protected !
     230  string exmsg = "TArray<T>::TArray(const BaseArray&,bool)";
     231  ReSize(a,pack,false);
    228232  ConvertAndCopyElt(a);
     233  if (a.HasInfoObject()) mInfo = new DVList(*(a.getInfoPointer()));     
    229234}
    230235
     
    16261631  }
    16271632  SetSeq(es);
    1628   cout << "TArray<T>::ReadASCII()/Info: " << n << " elements read from stream "
    1629        << " (Row,Col= " << nr << "," << nc << ")" << endl;
     1633  if (BaseArray::GetPrintLevel()>0)
     1634    cout << "TArray<T>::ReadASCII()/Info: " << n << " elements read from stream "
     1635         << " (Row,Col= " << nr << "," << nc << ")" << endl;
    16301636  return(n);
    16311637}
  • trunk/SophyaLib/TArray/tarray.h

    r3831 r4035  
    3535  TArray(const TArray<T>& a);
    3636  TArray(const TArray<T>& a, bool share);
    37   TArray(const BaseArray& a);
     37  TArray(const BaseArray& a, bool pack=true);
    3838
    3939  virtual ~TArray();
  • trunk/SophyaLib/TArray/tmatrix.cc

    r3831 r4035  
    1 // $Id: tmatrix.cc,v 1.40 2010-08-05 12:16:19 ansari Exp $
     1// $Id: tmatrix.cc,v 1.41 2011-11-14 16:28:25 ansari Exp $
    22//                         C.Magneville          04/99
    33#include "sopnamsp.h"
     
    127127: TArray<T>(a, share)
    128128{
     129  arrtype_ = 1;   // Type = Matrix
     130  if (a.NbDimensions() == 0)  {   // Reza-Nov 2011: we allow copy contrsuctor on non allocated arrays 
     131    UpdateMemoryMapping(a, SameMemoryMapping);
     132    return;
     133  }
    129134  if (a.NbDimensions() > 2)
    130135    throw SzMismatchError("TMatrix<T>::TMatrix(const TArray<T>& a, ...) a.NbDimensions()>2");
     
    134139    ndim_ = 2;
    135140  }
     141  UpdateMemoryMapping(a, SameMemoryMapping);
     142}
     143
     144//! Constructor of a matrix from a TArray \b a , with different data type
     145/*!
     146  Matrix size and memory layout are copied from the array \b a, or a packed matrix is created if \b pack==true.
     147  \param a : original array, to copy sizes and data from
     148  \param pack : if \b true , create a packed matrix, else same memory layout as \b a.
     149*/
     150template <class T>
     151TMatrix<T>::TMatrix(const BaseArray& a, bool pack)
     152  : TArray<T>()
     153{
     154  // On ne peut pas passer par TArray<T>(const BaseArray&), car il faut initialiser  arrtype_ d'abord !
    136155  arrtype_ = 1;   // Type = Matrix
     156  if (a.NbDimensions() == 0)  {   // Reza-Nov 2011: we allow copy contrsuctor on non allocated arrays 
     157    UpdateMemoryMapping(a, SameMemoryMapping);
     158    return;
     159  }
     160  if (a.NbDimensions() > 2)
     161    throw SzMismatchError("TMatrix<T>::TMatrix((const BaseArray& a, bool) a.NbDimensions()>2");
     162  string exmsg = "TMatrix<T>::TMatrix(const BaseArray&,bool)";
     163  TArray<T>::ReSize(a,pack,false);
    137164  UpdateMemoryMapping(a, SameMemoryMapping);
    138 }
    139 
    140 //! Constructor of a matrix from a TArray \b a , with a different data type
    141 template <class T>
    142 TMatrix<T>::TMatrix(const BaseArray& a)
    143 : TArray<T>()
    144 {
    145   arrtype_ = 1;   // Type = Matrix
    146   UpdateMemoryMapping(a, SameMemoryMapping);
    147   SetBA(a);
     165  TArray<T>::ConvertAndCopyElt(a);
    148166}
    149167
  • trunk/SophyaLib/TArray/tmatrix.h

    r3831 r4035  
    2121  TMatrix(const TMatrix<T>& a);
    2222  TMatrix(const TMatrix<T>& a, bool share);
    23   TMatrix(const TArray<T>& a,  bool share=true);
    24   TMatrix(const BaseArray& a);
     23  TMatrix(const TArray<T>& a, bool share=true);
     24  TMatrix(const BaseArray& a, bool pack=true);
    2525
    2626  virtual ~TMatrix();
  • trunk/SophyaLib/TArray/tvector.cc

    r3869 r4035  
    1 // $Id: tvector.cc,v 1.28 2010-08-12 15:01:47 ansari Exp $
     1// $Id: tvector.cc,v 1.29 2011-11-14 16:28:25 ansari Exp $
    22//                         C.Magneville          04/99
    33#include "sopnamsp.h"
     
    5656/*!
    5757  \param n : number of elements
    58   \param lcv : line or column vector ?
     58  \param lcv : line or column vector (BaseArray::AutoVectorType / SameVectorType / ColumnVector / RowVector)
    5959  \param mm : memory mapping type
    6060  \param fzero : if \b true , set vector elements to zero
     
    108108: TMatrix<T>(a, share)
    109109{
     110  arrtype_ = 2;   // Type = Vector
     111  if (a.NbDimensions() == 0)  return;    // Reza-Nov 2011: we allow copy contrsuctor on non allocated arrays 
    110112  if ( (size_[0] != 1) && (size_[1] != 1) )
    111113    throw SzMismatchError("TVector<T>::TVector(const TArray<T>& a) NRows()!=1 && NCols()!=1 ");
    112   arrtype_ = 2;   // Type = Vector
    113114  if ( (size_[0] == 1) && (size_[1] == 1) ) {
    114115    if (lcv == SameVectorType) lcv = a.GetVectorType();
     
    119120
    120121//! Constructor of a vector from a TArray \b a , with a different data type
    121 template <class T>
    122 TVector<T>::TVector(const BaseArray& a)
    123 : TMatrix<T>(a)
    124 {
     122/*!
     123  vector size and memory layout are copied from the array \b a, or a packed vector is created if \b pack==true.
     124  \param a : original array, to copy sizes and data from
     125  \param pack : if \b true , create a packed vector, else same memory layout as \b a.
     126*/
     127template <class T>
     128TVector<T>::TVector(const BaseArray& a, bool pack)
     129  : TMatrix<T>(a,pack)
     130{
     131  arrtype_ = 2;   // Type = Vector
     132  if (a.NbDimensions() == 0)  return;    // Reza-Nov 2011: we allow copy contrsuctor on non allocated arrays 
    125133  if ( (size_[0] != 1) && (size_[1] != 1) )
    126     throw SzMismatchError("TVector<T>::TVector(const BaseArray& a) NRows()!=1 && NCols()!=1 ");
    127   arrtype_ = 2;   // Type = Vector
     134    throw SzMismatchError("TVector<T>::TVector(const BaseArray& a,bool) NRows()!=1 && NCols()!=1 ");
    128135}
    129136
  • trunk/SophyaLib/TArray/tvector.h

    r3857 r4035  
    2020  TVector(const TVector<T>& v);
    2121  TVector(const TVector<T>& v, bool share);
    22   TVector(const TArray<T>& a,  bool share=true, short lcv=BaseArray::AutoVectorType);
    23   TVector(const BaseArray& a);
     22  TVector(const TArray<T>& a, bool share=true, short lcv=BaseArray::AutoVectorType);
     23  TVector(const BaseArray& a, bool pack=true);
    2424  TVector(const vector<T>& v, short lcv=BaseArray::AutoVectorType);
    2525
Note: See TracChangeset for help on using the changeset viewer.