Changeset 285 in Sophya for trunk/SophyaLib/BaseTools
- Timestamp:
- Apr 30, 1999, 1:02:25 PM (26 years ago)
- Location:
- trunk/SophyaLib/BaseTools
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaLib/BaseTools/ndatablock.cc
r277 r285 82 82 NDataBlock<T>::NDataBlock(const NDataBlock<T>& a,bool share) 83 83 // Createur avec choix de partager ou non 84 // Si "a" temporaire alors partage meme si share=false 84 85 : mSz(0), mSRef(NULL), mIsTemp(false) 85 86 { … … 119 120 template <class T> 120 121 void 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 122 123 // Si data==NULL : allocation de l'espace memoire (vide) 123 124 // data!=NULL : partage des donnees avec l'adresse data … … 153 154 mSRef = new NDREF; 154 155 mSRef->nref = 1; 155 if(data) mSRef->data = data; else mSRef->data = new T[n]; 156 if(data) mSRef->data = data; 157 else {mSRef->data = new T[n]; memset(mSRef->data,0,n*sizeof(T));} 156 158 mSRef->bridge = br; 157 159 … … 180 182 #endif 181 183 182 if( !a.mSRef) {mSz=0; mSRef=NULL;} // cas ou "a" est cree par defaut184 if(a.mSz==0) throw(SzMismatchError("NDataBlock::Clone a.mSz==0\n")); 183 185 else if(a.IsTemp()) Share(a); 184 186 else {Alloc(a.mSz); memcpy(Data(),a.Data(),mSz*sizeof(T));} … … 231 233 #endif 232 234 235 mSz = 0; mSRef=NULL; 233 236 return; 234 237 } … … 241 244 242 245 // 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 247 if(mSRef->bridge) delete mSRef->bridge; else delete [] mSRef->data; 246 248 mSRef->bridge=NULL; mSRef->data=NULL; 247 delete mSRef; mSRef=NULL; 249 delete mSRef; mSRef=NULL; mSz = 0; 248 250 } 249 251 … … 253 255 void NDataBlock<T>::Reset(T v) 254 256 { 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; 257 if(mSRef==NULL || mSRef->data==NULL || mSz==0) return; 258 T *p=Begin(), *pe=End(); while(p<pe) *p++ = v; 260 259 } 261 260 … … 278 277 if(n==0) throw(ParmError("NDataBlock::FillFrom n<=0\n")); 279 278 if(mSRef==NULL) Alloc(n); // cas du createur par default 280 if(mSz<n) n = mSz;279 if(mSz<n) n = mSz; 281 280 memcpy(Data(),data,n*sizeof(T)); 282 281 } … … 459 458 } 460 459 461 462 460 //////////////////////////////////////////////////////////////// 463 461 //**** Surcharge de +,-,*,/ : NDataBlock = NDataBlock+<T>b; … … 528 526 // Pour A+B 529 527 { 530 if( this->mSz!=b.mSz)528 if(mSz!=b.mSz) 531 529 throw(SzMismatchError("NDataBlock operator C=A+B size mismatch/null\n")); 532 530 NDataBlock<T> result; result.SetTemp(true); … … 545 543 // Pour A*B 546 544 { 547 if( this->mSz!=b.mSz)545 if(mSz!=b.mSz) 548 546 throw(SzMismatchError("NDataBlock operator C=A*B size mismatch/null\n")); 549 547 NDataBlock<T> result; result.SetTemp(true); … … 562 560 // Pour A-B 563 561 { 564 if( this->mSz!=b.mSz)562 if(mSz!=b.mSz) 565 563 throw(SzMismatchError("NDataBlock operator C=A-B size mismatch/null\n")); 566 564 NDataBlock<T> result; result.SetTemp(true); … … 568 566 result.Share(b); 569 567 T *p=result.Begin(), *pe=result.End(); 570 T const *pa= this->Begin();568 T const *pa=Begin(); 571 569 while(p<pe) {*p = *pa++ - *p; p++;} 572 570 } else { … … 581 579 // Pour A/B 582 580 { 583 if( this->mSz!=b.mSz)581 if(mSz!=b.mSz) 584 582 throw(SzMismatchError("NDataBlock operator C=A/B size mismatch/null\n")); 585 583 NDataBlock<T> result; result.SetTemp(true); … … 587 585 result.Share(b); 588 586 T *p=result.Begin(), *pe=result.End(); 589 T const *pa= this->Begin();587 T const *pa=Begin(); 590 588 while(p<pe) {*p = *pa++ / *p; p++;} 591 589 } else { -
trunk/SophyaLib/BaseTools/ndatablock.h
r277 r285 42 42 void Clone(const NDataBlock<T>& a); 43 43 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); 45 45 void FillFrom(size_t n,T* data); 46 46 … … 96 96 97 97 protected: 98 99 98 typedef struct {size_t nref; T* data; Bridge* bridge; } NDREF; 100 99 … … 103 102 void Delete(void); 104 103 105 size_t mSz;106 NDREF* mSRef;107 mutable bool 104 size_t mSz; 105 NDREF* mSRef; 106 mutable bool mIsTemp; 108 107 }; 109 108 -
trunk/SophyaLib/BaseTools/peidainit.cc
r284 r285 2 2 #include <stdlib.h> 3 3 #include <stdio.h> 4 #include <complex> 4 5 #include "pexceptions.h" 5 6 #include "ppersist.h" 6 7 #include "peidainit.h" 7 8 #include "ndatablock.h" 8 #include "complex"9 9 10 10 // --- Classe d'initialisation de PEIDA++, (PPersistMgr en particulier)
Note:
See TracChangeset
for help on using the changeset viewer.