Changeset 285 in Sophya for trunk/SophyaLib/BaseTools


Ignore:
Timestamp:
Apr 30, 1999, 1:02:25 PM (26 years ago)
Author:
ansari
Message:

complex est un include system -> <...> et pas "..." sinon pb mkmf
ndatablock ameliore cmv 30/4/99

Location:
trunk/SophyaLib/BaseTools
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaLib/BaseTools/ndatablock.cc

    r277 r285  
    8282NDataBlock<T>::NDataBlock(const NDataBlock<T>& a,bool share)
    8383// Createur avec choix de partager ou non
     84// Si "a" temporaire alors partage meme si share=false
    8485: mSz(0), mSRef(NULL), mIsTemp(false)
    8586{
     
    119120template <class T>
    120121void NDataBlock<T>::Alloc(size_t n,T* data,Bridge* br)
    121 // Allocation d'un NOUVEL espace de stoquage
     122// Allocation d'un NOUVEL espace de stoquage de "n" donnees
    122123// Si data==NULL : allocation de l'espace memoire (vide)
    123124//    data!=NULL : partage des donnees avec l'adresse data
     
    153154mSRef = new NDREF;
    154155mSRef->nref = 1;
    155 if(data) mSRef->data = data; else mSRef->data = new T[n];
     156if(data) mSRef->data = data;
     157else {mSRef->data = new T[n]; memset(mSRef->data,0,n*sizeof(T));}
    156158mSRef->bridge = br;
    157159
     
    180182#endif
    181183
    182 if(!a.mSRef) {mSz=0; mSRef=NULL;} // cas ou "a" est cree par defaut
     184if(a.mSz==0) throw(SzMismatchError("NDataBlock::Clone a.mSz==0\n"));
    183185else if(a.IsTemp()) Share(a);
    184186else {Alloc(a.mSz); memcpy(Data(),a.Data(),mSz*sizeof(T));}
     
    231233#endif
    232234
     235  mSz = 0; mSRef=NULL;
    233236  return;
    234237}
     
    241244
    242245// Si il y a un Bridge les donnees ne n'appartiennent pas, on detruit le Bridge
    243 if(mSRef->bridge) delete mSRef->bridge;
    244 // sinon, les donnees ont ete allouees par nos soins, on libere l'espace memoire
    245 else delete [] mSRef->data;
     246// sinon, les donnees ont ete allouees par nos soins, on libere l'espace
     247if(mSRef->bridge) delete mSRef->bridge; else delete [] mSRef->data;
    246248mSRef->bridge=NULL; mSRef->data=NULL;
    247 delete mSRef; mSRef=NULL;
     249delete mSRef; mSRef=NULL; mSz = 0;
    248250}
    249251
     
    253255void NDataBlock<T>::Reset(T v)
    254256{
    255 if(mSRef==NULL) return;
    256 if(mSRef->data==NULL) return;
    257 if(mSz==0) return;
    258 T *p=Begin(), *pe=End();
    259 while(p<pe) *p++ = v;
     257if(mSRef==NULL || mSRef->data==NULL || mSz==0) return;
     258T *p=Begin(), *pe=End(); while(p<pe) *p++ = v;
    260259}
    261260
     
    278277if(n==0) throw(ParmError("NDataBlock::FillFrom  n<=0\n"));
    279278if(mSRef==NULL) Alloc(n); // cas du createur par default
    280 if(mSz<n) n= mSz;
     279if(mSz<n) n = mSz;
    281280memcpy(Data(),data,n*sizeof(T));
    282281}
     
    459458}
    460459
    461 
    462460////////////////////////////////////////////////////////////////
    463461//**** Surcharge de +,-,*,/ : NDataBlock = NDataBlock+<T>b;
     
    528526// Pour A+B
    529527{
    530 if(this->mSz!=b.mSz)
     528if(mSz!=b.mSz)
    531529  throw(SzMismatchError("NDataBlock operator C=A+B size mismatch/null\n"));
    532530NDataBlock<T> result; result.SetTemp(true);
     
    545543// Pour A*B
    546544{
    547 if(this->mSz!=b.mSz)
     545if(mSz!=b.mSz)
    548546  throw(SzMismatchError("NDataBlock operator C=A*B size mismatch/null\n"));
    549547NDataBlock<T> result; result.SetTemp(true);
     
    562560// Pour A-B
    563561{
    564 if(this->mSz!=b.mSz)
     562if(mSz!=b.mSz)
    565563  throw(SzMismatchError("NDataBlock operator C=A-B size mismatch/null\n"));
    566564NDataBlock<T> result; result.SetTemp(true);
     
    568566  result.Share(b);
    569567  T *p=result.Begin(), *pe=result.End();
    570   T const *pa=this->Begin();
     568  T const *pa=Begin();
    571569  while(p<pe) {*p = *pa++  - *p; p++;}
    572570} else {
     
    581579// Pour A/B
    582580{
    583 if(this->mSz!=b.mSz)
     581if(mSz!=b.mSz)
    584582  throw(SzMismatchError("NDataBlock operator C=A/B size mismatch/null\n"));
    585583NDataBlock<T> result; result.SetTemp(true);
     
    587585  result.Share(b);
    588586  T *p=result.Begin(), *pe=result.End();
    589   T const *pa=this->Begin();
     587  T const *pa=Begin();
    590588  while(p<pe) {*p = *pa++  / *p; p++;}
    591589} else {
  • trunk/SophyaLib/BaseTools/ndatablock.h

    r277 r285  
    4242  void Clone(const NDataBlock<T>& a);
    4343  void Reset(T v=0);
    44   void ReSize(size_t n,bool force_alloc=false);
     44  void ReSize(size_t n,bool force_alloc=true);
    4545  void FillFrom(size_t n,T* data);
    4646 
     
    9696
    9797protected:
    98 
    9998  typedef struct {size_t nref; T* data; Bridge* bridge; } NDREF;
    10099
     
    103102  void Delete(void);
    104103
    105   size_t   mSz;
    106   NDREF*   mSRef;
    107   mutable bool     mIsTemp;
     104  size_t       mSz;
     105  NDREF*       mSRef;
     106  mutable bool mIsTemp;
    108107};
    109108
  • trunk/SophyaLib/BaseTools/peidainit.cc

    r284 r285  
    22#include <stdlib.h>
    33#include <stdio.h>
     4#include <complex>
    45#include "pexceptions.h"
    56#include "ppersist.h"
    67#include "peidainit.h"
    78#include "ndatablock.h"
    8 #include "complex"
    99
    1010// ---  Classe d'initialisation de PEIDA++, (PPersistMgr en particulier)
Note: See TracChangeset for help on using the changeset viewer.