Changeset 2915 in Sophya for trunk/SophyaLib/TArray/utilarr.cc
- Timestamp:
- Feb 22, 2006, 7:17:30 PM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaLib/TArray/utilarr.cc
r2795 r2915 313 313 \class SOPHYA::Range 314 314 \ingroup TArray 315 Class to define a range of indexes 316 */ 317 318 //! Constructor 319 /*! 320 Define a range of indexes 315 Class to define a range of indices, to be used with TArra<T> TMatrix<T> TVector<T> ... 316 */ 317 318 /*! 319 Constructor defining defining the range of indices, starting from \b start to the last. 320 \param start : start index (inclusive) 321 */ 322 Range::Range(sa_size_t start) 323 { 324 start_ = start; 325 end_ = Range::lastIndex(); 326 size_ = 0; 327 step_ = 1; 328 } 329 330 /*! 331 Constructor defining defining the range of indices, from \b start to \b end 321 332 \param start : start index (inclusive) 322 333 \param end : end index (inclusive) 323 \param size : size (number of elements, used if end \<= start) 324 \param step : step (or stride) 325 326 \warning If \b end \> \b start, \b size is computed automatically 327 \warning If not \b size is fixed and \b end recomputed 334 */ 335 Range::Range(sa_size_t start, sa_size_t end) 336 { 337 start_ = start; 338 end_ = end; 339 if (end >= start) size_ = end-start+1; 340 else size_ = 0; 341 step_ = 1; 342 } 343 344 /*! 345 Constructor defining defining the range of indices, from \b start to \b end 346 \param start : start index (inclusive) 347 \param end : end index (inclusive) 348 \param step : step (or stride) = index increment 349 */ 350 Range::Range(sa_size_t start, sa_size_t end, sa_size_t step) 351 { 352 start_ = start; 353 end_ = end; 354 step_ = (step > 0) ? step : 1; 355 if (step < 1) step = 1; 356 if (end >= start) 357 size_ = (end-start)/step_+1; 358 else size_ = 0; 359 } 360 361 /*! 362 Define a range of indices 363 \param start : start index (inclusive) 364 \param end : end index (inclusive, used if size \<= 0 and end \>= start) 365 \param size : size (number of elements, used if \>= 1 ) 366 \param step : step (or stride) = index increment 367 368 \warning If \b size \>= 1 , \b end index computed automatically. 369 If \b size \< 1 and \b end < \b start , equivalent to \b end = Range()::lastIndex() 328 370 */ 329 371 Range::Range(sa_size_t start, sa_size_t end, sa_size_t size, sa_size_t step) … … 331 373 start_ = start; 332 374 step_ = (step > 0) ? step : 1; 333 if (end > start) { // Taille calcule automatiquement 334 end_ = end; 335 if (step_ > ((end_-start_)+1)) size_ = 1; 336 else size_ = ((end-start)+1)/step_; 337 } 338 else { // Taille fixee 375 if (size > 0) { // Nb d'elements fixe 339 376 size_ = size; 340 end_ = start_+size_*step_; 341 } 377 if (end == Range::lastIndex()) start_ = end_ = end; 378 else end_ = start_+size_*step_; 379 } 380 else { 381 if (end >= start) { // Indice de fin fixe 382 end_ = end; 383 size_ = (end-start)/step_+1; 384 } 385 else { // rien fixe 386 size_ = 0; 387 end_ = Range::lastIndex(); 388 } 389 } 390 } 391 392 /* 393 Range::Range(Range const& a) 394 { 395 start_ = a.start_; 396 end_ = a.end_; 397 size_ = a.size_; 398 step_ = a.step_; 399 } 400 */ 401 402 /*! 403 This method is called to recompute index ranges, specifying the original array size 404 by the TArray<T> (or derived classes) sub array extraction methods 405 */ 406 void Range::Update(sa_size_t osz) 407 { 408 if (end_ >= 0) return; 409 if (osz == 0) { 410 start_ = end_ = 0; 411 size_ = step_ = 1; 412 return; 413 } 414 if (end_ == start_) { 415 end_ = osz-1; 416 if ((size_ > 0) && (size_ <= osz/step_)) 417 start_ = end_ - size_*step_; 418 else { 419 start_ = end_; 420 size_ = 1; 421 } 422 } 423 else { 424 end_ = osz-1; 425 size_ = (end_-start_)/step_+1; 426 } 427 return; 342 428 } 343 429
Note:
See TracChangeset
for help on using the changeset viewer.