From 7723643183f186fc0d5064755d8ba825cb8755cb Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Sun, 2 Mar 2014 09:00:43 +0000 Subject: Replace most of APPLY_DELTA macro with a new method. Using methods instead of macros where possible makes debugging easier. Especially long macros like this one. --- lib/backupstore/BackupStoreInfo.cpp | 36 +++++++++++++++++++++--------------- lib/backupstore/BackupStoreInfo.h | 3 +++ 2 files changed, 24 insertions(+), 15 deletions(-) (limited to 'lib') diff --git a/lib/backupstore/BackupStoreInfo.cpp b/lib/backupstore/BackupStoreInfo.cpp index bfacc6e6..dd120c86 100644 --- a/lib/backupstore/BackupStoreInfo.cpp +++ b/lib/backupstore/BackupStoreInfo.cpp @@ -452,22 +452,28 @@ int BackupStoreInfo::ReportChangesTo(BackupStoreInfo& rOldInfo) return numChanges; } -#define APPLY_DELTA(field, delta) \ - if(mReadOnly) \ - { \ - THROW_EXCEPTION(BackupStoreException, StoreInfoIsReadOnly) \ - } \ - \ - if((field + delta) < 0) \ - { \ - THROW_EXCEPTION_MESSAGE(BackupStoreException, \ - StoreInfoBlockDeltaMakesValueNegative, \ - "Failed to reduce " << #field << " from " << \ - field << " by " << delta); \ - } \ - \ - field += delta; \ +void BackupStoreInfo::ApplyDelta(int64_t& field, const std::string& field_name, + const int64_t delta) +{ + if(mReadOnly) + { + THROW_EXCEPTION(BackupStoreException, StoreInfoIsReadOnly); + } + + if((field + delta) < 0) + { + THROW_EXCEPTION_MESSAGE(BackupStoreException, + StoreInfoBlockDeltaMakesValueNegative, + "Failed to reduce " << field_name << " from " << + field << " by " << delta); + } + + field += delta; mIsModified = true; +} + +#define APPLY_DELTA(field, delta) \ + ApplyDelta(field, #field, delta) // -------------------------------------------------------------------------- // diff --git a/lib/backupstore/BackupStoreInfo.h b/lib/backupstore/BackupStoreInfo.h index cb9f8f32..1eb67894 100644 --- a/lib/backupstore/BackupStoreInfo.h +++ b/lib/backupstore/BackupStoreInfo.h @@ -196,6 +196,9 @@ private: std::vector mDeletedDirectories; bool mAccountEnabled; CollectInBufferStream mExtraData; + + void ApplyDelta(int64_t& field, const std::string& field_name, + const int64_t delta); }; #endif // BACKUPSTOREINFO__H -- cgit v1.2.3