Changeset 3039 for box


Ignore:
Timestamp:
01/11/2011 23:37:58 (7 months ago)
Author:
chris
Message:

Use a macro to verify block count adjustments to reduce duplicate code.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • box/trunk/lib/backupstore/BackupStoreInfo.cpp

    r2975 r3039  
    454454} 
    455455 
     456#define APPLY_DELTA(field, delta) \ 
     457        if(mReadOnly) \ 
     458        { \ 
     459                THROW_EXCEPTION(BackupStoreException, StoreInfoIsReadOnly) \ 
     460        } \ 
     461        \ 
     462        if((field + delta) < 0) \ 
     463        { \ 
     464                THROW_EXCEPTION_MESSAGE(BackupStoreException, \ 
     465                        StoreInfoBlockDeltaMakesValueNegative, \ 
     466                        "Failed to reduce " << #field << " from " << \ 
     467                        field << " by " << delta); \ 
     468        } \ 
     469        \ 
     470        field += delta; \ 
     471        mIsModified = true; 
     472 
    456473// -------------------------------------------------------------------------- 
    457474// 
     
    464481void BackupStoreInfo::ChangeBlocksUsed(int64_t Delta) 
    465482{ 
    466         if(mReadOnly) 
    467         { 
    468                 THROW_EXCEPTION(BackupStoreException, StoreInfoIsReadOnly) 
    469         } 
    470         if((mBlocksUsed + Delta) < 0) 
    471         { 
    472                 THROW_EXCEPTION(BackupStoreException, StoreInfoBlockDeltaMakesValueNegative) 
    473         } 
    474          
    475         mBlocksUsed += Delta; 
    476          
    477         mIsModified = true; 
     483        APPLY_DELTA(mBlocksUsed, Delta); 
    478484} 
    479485 
     
    489495void BackupStoreInfo::ChangeBlocksInCurrentFiles(int64_t Delta) 
    490496{ 
    491         if(mReadOnly) 
    492         { 
    493                 THROW_EXCEPTION(BackupStoreException, StoreInfoIsReadOnly) 
    494         } 
    495  
    496         if((mBlocksInCurrentFiles + Delta) < 0) 
    497         { 
    498                 THROW_EXCEPTION(BackupStoreException, 
    499                         StoreInfoBlockDeltaMakesValueNegative) 
    500         } 
    501          
    502         mBlocksInCurrentFiles += Delta; 
    503         mIsModified = true; 
     497        APPLY_DELTA(mBlocksInCurrentFiles, Delta); 
    504498} 
    505499 
     
    514508void BackupStoreInfo::ChangeBlocksInOldFiles(int64_t Delta) 
    515509{ 
    516         if(mReadOnly) 
    517         { 
    518                 THROW_EXCEPTION(BackupStoreException, StoreInfoIsReadOnly) 
    519         } 
    520         if((mBlocksInOldFiles + Delta) < 0) 
    521         { 
    522                 THROW_EXCEPTION(BackupStoreException, StoreInfoBlockDeltaMakesValueNegative) 
    523         } 
    524          
    525         mBlocksInOldFiles += Delta; 
    526          
    527         mIsModified = true; 
     510        APPLY_DELTA(mBlocksInOldFiles, Delta); 
    528511} 
    529512 
     
    538521void BackupStoreInfo::ChangeBlocksInDeletedFiles(int64_t Delta) 
    539522{ 
    540         if(mReadOnly) 
    541         { 
    542                 THROW_EXCEPTION(BackupStoreException, StoreInfoIsReadOnly) 
    543         } 
    544         if((mBlocksInDeletedFiles + Delta) < 0) 
    545         { 
    546                 THROW_EXCEPTION(BackupStoreException, StoreInfoBlockDeltaMakesValueNegative) 
    547         } 
    548          
    549         mBlocksInDeletedFiles += Delta; 
    550          
    551         mIsModified = true; 
     523        APPLY_DELTA(mBlocksInDeletedFiles, Delta); 
    552524} 
    553525 
     
    562534void BackupStoreInfo::ChangeBlocksInDirectories(int64_t Delta) 
    563535{ 
    564         if(mReadOnly) 
    565         { 
    566                 THROW_EXCEPTION(BackupStoreException, StoreInfoIsReadOnly) 
    567         } 
    568         if((mBlocksInDirectories + Delta) < 0) 
    569         { 
    570                 THROW_EXCEPTION(BackupStoreException, StoreInfoBlockDeltaMakesValueNegative) 
    571         } 
    572          
    573         mBlocksInDirectories += Delta; 
    574          
    575         mIsModified = true; 
     536        APPLY_DELTA(mBlocksInDirectories, Delta); 
    576537} 
    577538 
    578539void BackupStoreInfo::AdjustNumFiles(int64_t increase) 
    579540{ 
    580         if(mReadOnly) 
    581         { 
    582                 THROW_EXCEPTION(BackupStoreException, StoreInfoIsReadOnly) 
    583         } 
    584  
    585         if((mNumFiles + increase) < 0) 
    586         { 
    587                 THROW_EXCEPTION(BackupStoreException, StoreInfoBlockDeltaMakesValueNegative) 
    588         } 
    589          
    590         mNumFiles += increase; 
    591         mIsModified = true; 
    592  
     541        APPLY_DELTA(mNumFiles, increase); 
    593542} 
    594543 
    595544void BackupStoreInfo::AdjustNumOldFiles(int64_t increase) 
    596545{ 
    597         if(mReadOnly) 
    598         { 
    599                 THROW_EXCEPTION(BackupStoreException, StoreInfoIsReadOnly) 
    600         } 
    601  
    602         if((mNumOldFiles + increase) < 0) 
    603         { 
    604                 THROW_EXCEPTION(BackupStoreException, StoreInfoBlockDeltaMakesValueNegative) 
    605         } 
    606          
    607         mNumOldFiles += increase; 
    608         mIsModified = true; 
     546        APPLY_DELTA(mNumOldFiles, increase); 
    609547} 
    610548 
    611549void BackupStoreInfo::AdjustNumDeletedFiles(int64_t increase) 
    612550{ 
    613         if(mReadOnly) 
    614         { 
    615                 THROW_EXCEPTION(BackupStoreException, StoreInfoIsReadOnly) 
    616         } 
    617  
    618         if((mNumDeletedFiles + increase) < 0) 
    619         { 
    620                 THROW_EXCEPTION(BackupStoreException, StoreInfoBlockDeltaMakesValueNegative) 
    621         } 
    622          
    623         mNumDeletedFiles += increase; 
    624         mIsModified = true; 
     551        APPLY_DELTA(mNumDeletedFiles, increase); 
    625552} 
    626553 
    627554void BackupStoreInfo::AdjustNumDirectories(int64_t increase) 
    628555{ 
    629         if(mReadOnly) 
    630         { 
    631                 THROW_EXCEPTION(BackupStoreException, StoreInfoIsReadOnly) 
    632         } 
    633  
    634         if((mNumDirectories + increase) < 0) 
    635         { 
    636                 THROW_EXCEPTION(BackupStoreException, StoreInfoBlockDeltaMakesValueNegative) 
    637         } 
    638          
    639         mNumDirectories += increase; 
    640         mIsModified = true; 
     556        APPLY_DELTA(mNumDirectories, increase); 
    641557} 
    642558 
Note: See TracChangeset for help on using the changeset viewer.