Changeset 285 in Sophya for trunk/SophyaLib/BaseTools/ndatablock.cc
- Timestamp:
- Apr 30, 1999, 1:02:25 PM (26 years ago)
- File:
-
- 1 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 {
Note:
See TracChangeset
for help on using the changeset viewer.