From: <ste...@us...> - 2012-07-21 01:29:56
|
Revision: 2795 http://moneymanagerex.svn.sourceforge.net/moneymanagerex/?rev=2795&view=rev Author: stef145g Date: 2012-07-21 01:29:48 +0000 (Sat, 21 Jul 2012) Log Message: ----------- Code simplification: Importing external functions used only in mmCoreDB into the mmCoreDB class. Rearranging of inline functions into functionality Modified Paths: -------------- branches/0.9.9.0/mmex/src/mmcoredb.cpp branches/0.9.9.0/mmex/src/mmcoredb.h Modified: branches/0.9.9.0/mmex/src/mmcoredb.cpp =================================================================== --- branches/0.9.9.0/mmex/src/mmcoredb.cpp 2012-07-19 07:58:20 UTC (rev 2794) +++ branches/0.9.9.0/mmex/src/mmcoredb.cpp 2012-07-21 01:29:48 UTC (rev 2795) @@ -18,28 +18,52 @@ #include "mmcoredb.h" #include "util.h" -//---------------------------------------------------------------------------- -namespace +//---------------------------------------------------------------------------- +mmCoreDB::mmCoreDB(boost::shared_ptr<wxSQLite3Database> db) : + db_(db), + payeeList_(db), + categoryList_(db), + accountList_(db), + currencyList_(db), + bTransactionList_(db), + displayDatabaseError_(true) { + if (!db_) + { + throw wxSQLite3Exception(WXSQLITE_ERROR, wxT("Null pointer to database")); + } -void loadCurrencies(boost::shared_ptr<wxSQLite3Database> db_, mmCurrencyList &cur_list) + mmOptions::instance().loadOptions(db_.get()); + + /* Load the DB into memory */ + LoadCurrencies(); // populate currencyList_ + LoadCategories(); // populate categoryList_ + LoadPayees(); // populate payeeList_ + LoadAccounts(); // populate accountList_ + LoadTransactions(); // populate bTransactionList_ + + // Update All transactions in case of errors + bTransactionList_.updateAllTransactions(); +} +//---------------------------------------------------------------------------- + +void mmCoreDB::LoadCurrencies() { wxSQLite3ResultSet q1 = db_->ExecuteQuery(SELECT_ALL_FROM_CURRENCYFORMATS_V1); while (q1.NextRow()) { boost::shared_ptr<mmCurrency> pCurrency(new mmCurrency(q1)); - cur_list.currencies_.push_back(pCurrency); + currencyList_.currencies_.push_back(pCurrency); } q1.Finalize(); } //---------------------------------------------------------------------------- -void loadCategories(boost::shared_ptr<wxSQLite3Database> db_, mmCategoryList &cat_list) +void mmCoreDB::LoadCategories() { - boost::shared_ptr<mmCategory> pCat; wxSQLite3ResultSet q1 = db_->ExecuteQuery(SELECT_ALL_CATEGORIES); @@ -49,8 +73,10 @@ if (!pCat || pCat->categID_ != catID) { - if (pCat) cat_list.entries_.push_back(pCat); - + if (pCat) + { + categoryList_.entries_.push_back(pCat); + } pCat.reset(new mmCategory(catID, q1.GetString(wxT("CATEGNAME")))); } @@ -71,15 +97,12 @@ if (pCat) { - cat_list.entries_.push_back(pCat); + categoryList_.entries_.push_back(pCat); } } //---------------------------------------------------------------------------- -void loadPayees(boost::shared_ptr<wxSQLite3Database> db_, - mmCategoryList &cat_list, - mmPayeeList &payee_list - ) +void mmCoreDB::LoadPayees() { wxSQLite3ResultSet q1 = db_->ExecuteQuery(SELECT_ALL_FROM_PAYEE_V1); @@ -89,23 +112,19 @@ int categID = q1.GetInt(wxT("CATEGID")); int subCategID = q1.GetInt(wxT("SUBCATEGID")); - boost::shared_ptr<mmPayee> pPayee(new mmPayee(payeeID, q1.GetString(wxT("PAYEENAME")), - cat_list.getCategorySharedPtr(categID, subCategID) - ) - ); + boost::shared_ptr<mmPayee> pPayee(new mmPayee(payeeID, q1.GetString(wxT("PAYEENAME")), + categoryList_.getCategorySharedPtr(categID, subCategID)) + ); - payee_list.entries_.push_back(pPayee); + payeeList_.entries_.push_back(pPayee); } q1.Finalize(); - payee_list.sortPayeeList(); + payeeList_.sortPayeeList(); } //---------------------------------------------------------------------------- -void loadAccounts(boost::shared_ptr<wxSQLite3Database> db_, - mmCurrencyList &cur_list, - mmAccountList &acc_list - ) +void mmCoreDB::LoadAccounts() { wxSQLite3ResultSet q1 = db_->ExecuteQuery(SELECT_ALL_FROM_ACCOUNTLIST_V1); @@ -113,59 +132,27 @@ { boost::shared_ptr<mmAccount> pAccount(new mmAccount(q1)); - boost::weak_ptr<mmCurrency> pCurrency = cur_list.getCurrencySharedPtr(q1.GetInt(wxT("CURRENCYID"))); + boost::weak_ptr<mmCurrency> pCurrency = + currencyList_.getCurrencySharedPtr(q1.GetInt(wxT("CURRENCYID"))); pAccount->currency_ = pCurrency; - acc_list.accounts_.push_back(pAccount); + accountList_.accounts_.push_back(pAccount); } q1.Finalize(); } //---------------------------------------------------------------------------- -void loadTransactions(boost::shared_ptr<wxSQLite3Database> db_, - mmCoreDB *theCore, - mmBankTransactionList &trans_list - ) +void mmCoreDB::LoadTransactions() { wxSQLite3ResultSet q1 = db_->ExecuteQuery(SELECT_ALL_FROM_CHECKINGACCOUNT_V1); while (q1.NextRow()) { - boost::shared_ptr<mmBankTransaction> ptrBase(new mmBankTransaction(theCore, q1)); - trans_list.transactions_.push_back(ptrBase); + boost::shared_ptr<mmBankTransaction> ptrBase(new mmBankTransaction(this, q1)); + bTransactionList_.transactions_.push_back(ptrBase); } q1.Finalize(); } //---------------------------------------------------------------------------- - -} // namespace - -//---------------------------------------------------------------------------- - -mmCoreDB::mmCoreDB(boost::shared_ptr<wxSQLite3Database> db) : - db_(db), - payeeList_(db), - categoryList_(db), - accountList_(db), - currencyList_(db), - bTransactionList_(db), - displayDatabaseError_(true) -{ - if (!db_) - throw wxSQLite3Exception(WXSQLITE_ERROR, wxT("Null pointer to database")); - - /* Load the DB into memory */ - - mmOptions::instance().loadOptions(db_.get()); - loadCurrencies(db_, currencyList_); - loadCategories(db_, categoryList_); - loadPayees(db_, categoryList_, payeeList_); - loadAccounts(db_, currencyList_, accountList_); - loadTransactions(db_, this, bTransactionList_); - - // Update All transactions in case of errors - bTransactionList_.updateAllTransactions(); -} -//---------------------------------------------------------------------------- Modified: branches/0.9.9.0/mmex/src/mmcoredb.h =================================================================== --- branches/0.9.9.0/mmex/src/mmcoredb.h 2012-07-19 07:58:20 UTC (rev 2794) +++ branches/0.9.9.0/mmex/src/mmcoredb.h 2012-07-21 01:29:48 UTC (rev 2795) @@ -5,12 +5,12 @@ it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA @@ -31,7 +31,7 @@ class wxSQLite3Database; //---------------------------------------------------------------------------- -/** +/** mmCoreDB encapsulates most of the work in translating between the SQLite DB and the C++ datastructures used by MMEX */ @@ -39,63 +39,215 @@ class mmCoreDB { public: - int getPayeeID(const wxString& name) const { return payeeList_.getID(name); } - int getCategoryID(const wxString& name) const { return categoryList_.getID(name); } - int getSubCategoryID(int parentID, const wxString& name) const { return categoryList_.getSubCategoryID(parentID, name); } - int getAccountID(const wxString& name) const { return accountList_.getID(name); } - int getCurrencyID(const wxString& name) const { return currencyList_.getCurrencyID(name); } + /*Payee Functions*/ + int getPayeeID(const wxString& name) const + { + return payeeList_.getID(name); + } + bool payeeExists(int id) const + { + return payeeList_.exists(id); + } + bool payeeExists(const wxString& name) const + { + return payeeList_.exists(name); + } + wxString getPayeeName(int id) const + { + return payeeList_.getName(id); + } + int addPayee(const wxString& name) + { + return payeeList_.add(name); + } + bool removePayee(int id) + { + return payeeList_.remove(id); + } + void updatePayee(int id, const wxString& name) + { + return payeeList_.update(id, name); + } + boost::shared_ptr<mmPayee> getPayeeSharedPtr(int id) + { + return payeeList_.getSharedPtr(id); + } + int numPayee() const + { + return payeeList_.num(); + } + std::pair<mmPayeeList::const_iterator, mmPayeeList::const_iterator> rangePayee() const + { + return payeeList_.range(); + } - bool payeeExists(int id) const { return payeeList_.exists(id); } - bool payeeExists(const wxString& name) const { return payeeList_.exists(name); } - wxString getPayeeName(int id) const {return payeeList_.getName(id); } - int addPayee(const wxString& name) { return payeeList_.add(name); } - bool removePayee(int id) { return payeeList_.remove(id); } - void updatePayee(int id, const wxString& name) { return payeeList_.update(id, name); } - boost::shared_ptr<mmPayee> getPayeeSharedPtr(int id) { return payeeList_.getSharedPtr(id); } - int numPayee() const { return payeeList_.num(); } - std::pair<mmPayeeList::const_iterator, mmPayeeList::const_iterator> rangePayee() const { return payeeList_.range(); } + /*Category Functions*/ + int getCategoryID(const wxString& name) const + { + return categoryList_.getID(name); + } + bool categoryExists(const wxString& categoryName) const + { + return categoryList_.categoryExists(categoryName); + } + boost::shared_ptr<mmCategory> getCategorySharedPtr(int category, int subcategory) const + { + return categoryList_.getCategorySharedPtr(category, subcategory); + } + int addCategory(const wxString& category) + { + return categoryList_.addCategory(category); + } + bool deleteCategory(int categID) + { + return categoryList_.deleteCategory(categID); + } + bool updateCategory(int categID, int subCategID, const wxString& text) + { + return categoryList_.updateCategory(categID, subCategID, text); + } + wxString getCategoryName(int id) const + { + return categoryList_.getCategoryName(id); + } + wxString GetCategoryString(int categID) const + { + return categoryList_.GetCategoryString(categID); + } + wxString GetFullCategoryString(int categID, int subCategID) const + { + return categoryList_.GetFullCategoryString(categID, subCategID); + } + std::pair<mmCategoryList::const_iterator, mmCategoryList::const_iterator> rangeCategory() const + { + return categoryList_.range(); + } - wxString getAccountName(int accountID) const { return accountList_.getName(accountID); } - wxArrayInt getAccountsID(int except_id = -1) const { return accountList_.getAccountsID(except_id); } - wxArrayString getAccountsName(int except_id = -1) const { return accountList_.getAccountsName(except_id); } - boost::shared_ptr<mmAccount> getAccountSharedPtr(int accountID) const { return accountList_.getAccountSharedPtr(accountID); } - int getNumAccounts() const { return accountList_.getNumAccounts(); } - int getNumBankAccounts() const { return accountList_.getNumBankAccounts(); } - boost::weak_ptr<mmCurrency> getCurrencyWeakPtr(int accountID) const { return accountList_.getCurrencyWeakPtr(accountID); } - int addAccount(boost::shared_ptr<mmAccount> pAccount) { return accountList_.add(pAccount); }; - void updateAccount(boost::shared_ptr<mmAccount> pAccount) { return accountList_.update(pAccount); }; - bool accountExists(const wxString& name) const { return accountList_.exists(name); }; - bool deleteAccount(int accountID) { return accountList_.remove(accountID); } + /*SubCategory Functions obtained from Category List*/ + int getSubCategoryID(int parentID, const wxString& name) const + { + return categoryList_.getSubCategoryID(parentID, name); + } + wxString GetSubCategoryString(int categID, int subCategID) const + { + return categoryList_.GetSubCategoryString(categID, subCategID); + } + int addSubCategory(int parentID, const wxString& text) + { + return categoryList_.addSubCategory(parentID, text); + } + bool deleteSubCategory(int categID, int subCategID) + { + return categoryList_.deleteSubCategory(categID, subCategID); + } - bool categoryExists(const wxString& categoryName) const { return categoryList_.categoryExists(categoryName); } - boost::shared_ptr<mmCategory> getCategorySharedPtr(int category, int subcategory) const { return categoryList_.getCategorySharedPtr(category, subcategory); } - int addCategory(const wxString& category) { return categoryList_.addCategory(category); } - int addSubCategory(int parentID, const wxString& text) { return categoryList_.addSubCategory(parentID, text); } - bool deleteCategory(int categID) { return categoryList_.deleteCategory(categID); } - bool deleteSubCategory(int categID, int subCategID) { return categoryList_.deleteSubCategory(categID, subCategID); } - bool updateCategory(int categID, int subCategID, const wxString& text) { return categoryList_.updateCategory(categID, subCategID, text); } - wxString getCategoryName(int id) const { return categoryList_.getCategoryName(id); } - wxString GetCategoryString(int categID) const { return categoryList_.GetCategoryString(categID); } - wxString GetSubCategoryString(int categID, int subCategID) const { return categoryList_.GetSubCategoryString(categID, subCategID); } - wxString GetFullCategoryString(int categID, int subCategID) const { return categoryList_.GetFullCategoryString(categID, subCategID); } - std::pair<mmCategoryList::const_iterator, mmCategoryList::const_iterator> rangeCategory() const { return categoryList_.range(); } - /* Currency Functions */ - int addCurrency(boost::shared_ptr<mmCurrency> pCurrency) { return currencyList_.addCurrency(pCurrency); } - void deleteCurrency(int currencyID) { return currencyList_.deleteCurrency(currencyID); } - bool currencyInUse(int currencyID) { return currencyList_.currencyInUse(currencyID); } - void updateCurrency(boost::shared_ptr<mmCurrency> pCurrency) { return currencyList_.updateCurrency(pCurrency); } - wxString getCurrencyName(int currencyID) const { return currencyList_.getCurrencyName(currencyID); } - boost::shared_ptr<mmCurrency> getCurrencySharedPtr(int currencyID) const { return currencyList_.getCurrencySharedPtr(currencyID); } - boost::shared_ptr<mmCurrency> getCurrencySharedPtr(const wxString& currencyName) const { return currencyList_.getCurrencySharedPtr(currencyName); } - void loadBaseCurrencySettings() const { return currencyList_.loadBaseCurrencySettings(); } - int getBaseCurrencySettings() const { return currencyList_.getBaseCurrencySettings(); } - void setBaseCurrencySettings(int currencyID) { return currencyList_.setBaseCurrencySettings(currencyID); } - std::pair<mmCurrencyList::const_iterator, mmCurrencyList::const_iterator> rangeCurrency() const { return currencyList_.range(); } + int getCurrencyID(const wxString& name) const + { + return currencyList_.getCurrencyID(name); + } + int addCurrency(boost::shared_ptr<mmCurrency> pCurrency) + { + return currencyList_.addCurrency(pCurrency); + } + void deleteCurrency(int currencyID) + { + return currencyList_.deleteCurrency(currencyID); + } + bool currencyInUse(int currencyID) + { + return currencyList_.currencyInUse(currencyID); + } + void updateCurrency(boost::shared_ptr<mmCurrency> pCurrency) + { + return currencyList_.updateCurrency(pCurrency); + } + wxString getCurrencyName(int currencyID) const + { + return currencyList_.getCurrencyName(currencyID); + } + boost::shared_ptr<mmCurrency> getCurrencySharedPtr(int currencyID) const + { + return currencyList_.getCurrencySharedPtr(currencyID); + } + boost::shared_ptr<mmCurrency> getCurrencySharedPtr(const wxString& currencyName) const + { + return currencyList_.getCurrencySharedPtr(currencyName); + } + void loadBaseCurrencySettings() const + { + return currencyList_.loadBaseCurrencySettings(); + } + int getBaseCurrencySettings() const + { + return currencyList_.getBaseCurrencySettings(); + } + void setBaseCurrencySettings(int currencyID) + { + return currencyList_.setBaseCurrencySettings(currencyID); + } + std::pair<mmCurrencyList::const_iterator, mmCurrencyList::const_iterator> rangeCurrency() const + { + return currencyList_.range(); + } /*Account Functions*/ - bool has_term_account() const { return accountList_.has_term_account(); } - std::pair<mmAccountList::const_iterator, mmAccountList::const_iterator> rangeAccount() const { return accountList_.range(); } + int getAccountID(const wxString& name) const + { + return accountList_.getID(name); + } + wxString getAccountName(int accountID) const + { + return accountList_.getName(accountID); + } + wxArrayInt getAccountsID(int except_id = -1) const + { + return accountList_.getAccountsID(except_id); + } + wxArrayString getAccountsName(int except_id = -1) const + { + return accountList_.getAccountsName(except_id); + } + boost::shared_ptr<mmAccount> getAccountSharedPtr(int accountID) const + { + return accountList_.getAccountSharedPtr(accountID); + } + int getNumAccounts() const + { + return accountList_.getNumAccounts(); + } + int getNumBankAccounts() const + { + return accountList_.getNumBankAccounts(); + } + bool has_term_account() const + { + return accountList_.has_term_account(); + } + int addAccount(boost::shared_ptr<mmAccount> pAccount) + { + return accountList_.add(pAccount); + } + void updateAccount(boost::shared_ptr<mmAccount> pAccount) + { + return accountList_.update(pAccount); + } + bool accountExists(const wxString& name) const + { + return accountList_.exists(name); + } + bool deleteAccount(int accountID) + { + return accountList_.remove(accountID); + } + boost::weak_ptr<mmCurrency> getCurrencyWeakPtr(int accountID) const + { + return accountList_.getCurrencyWeakPtr(accountID); + } + std::pair<mmAccountList::const_iterator, mmAccountList::const_iterator> rangeAccount() const + { + return accountList_.range(); + } /*Transaction Functions*/ void getExpensesIncome(int accountID, double& expenses, double& income, bool ignoreDate, const wxDateTime &dtBegin, const wxDateTime &dtEnd, bool ignoreFuture = false) const @@ -114,29 +266,48 @@ { return bTransactionList_.getTransactionStats(accountID, number, ignoreDate, dtBegin, dtEnd, ignoreFuture); } - double getBalance(int accountID, bool ignoreFuture = false) const { return bTransactionList_.getBalance(accountID, ignoreFuture); } - bool getDailyBalance(int accountID, std::map<wxDateTime, double>& daily_balance, bool ignoreFuture = false) const - { - return bTransactionList_.getDailyBalance(accountID, daily_balance, ignoreFuture); + double getBalance(int accountID, bool ignoreFuture = false) const + { + return bTransactionList_.getBalance(accountID, ignoreFuture); } - double getReconciledBalance(int accountID, bool ignoreFuture = false) const { return bTransactionList_.getReconciledBalance(accountID, ignoreFuture); } - int countFollowupTransactions() const { return bTransactionList_.countFollowupTransactions(); } + bool getDailyBalance(int accountID, std::map<wxDateTime, double>& daily_balance, bool ignoreFuture = false) const + { + return bTransactionList_.getDailyBalance(accountID, daily_balance, ignoreFuture); + } + double getReconciledBalance(int accountID, bool ignoreFuture = false) const + { + return bTransactionList_.getReconciledBalance(accountID, ignoreFuture); + } + int countFollowupTransactions() const + { + return bTransactionList_.countFollowupTransactions(); + } -public: - mmCoreDB(boost::shared_ptr<wxSQLite3Database>); +public: + mmCoreDB(boost::shared_ptr<wxSQLite3Database> db); - boost::shared_ptr<wxSQLite3Database> db_; + // Global access point to the database. + boost::shared_ptr<wxSQLite3Database> db_; - mmCurrencyList currencyList_; - mmAccountList accountList_; - mmBankTransactionList bTransactionList_; + /* These variables form a global data access point. */ + mmCurrencyList currencyList_; + mmCategoryList categoryList_; + mmPayeeList payeeList_; + mmAccountList accountList_; + mmBankTransactionList bTransactionList_; - bool displayDatabaseError_; + bool displayDatabaseError_; -private: - mmPayeeList payeeList_; - mmCategoryList categoryList_; - + /// Loads database Currency into memory + void LoadCurrencies(); + /// Loads database Categories into memory + void LoadCategories(); + /// Loads database Payees into memory + void LoadPayees(); + /// Loads database Accounts list into memory + void LoadAccounts(); + /// Loads database primary Transactions into memory. + void LoadTransactions(); }; //---------------------------------------------------------------------------- This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |