From: <gua...@us...> - 2013-12-14 13:40:03
|
Revision: 5573 http://sourceforge.net/p/moneymanagerex/code/5573 Author: guanlisheng Date: 2013-12-14 13:39:56 +0000 (Sat, 14 Dec 2013) Log Message: ----------- use more metaprograming to reduce code Modified Paths: -------------- trunk/src/model/Model.h trunk/src/model/Model_Account.h trunk/src/model/Model_Asset.h trunk/src/model/Model_Billsdeposits.h trunk/src/model/Model_Budget.h trunk/src/model/Model_Budgetsplittransaction.h trunk/src/model/Model_Budgetyear.h trunk/src/model/Model_Category.h trunk/src/model/Model_Checking.h trunk/src/model/Model_Currency.h trunk/src/model/Model_Infotable.h trunk/src/model/Model_Payee.h trunk/src/model/Model_Report.h trunk/src/model/Model_Setting.h trunk/src/model/Model_Splittransaction.h trunk/src/model/Model_Stock.h trunk/src/model/Model_Subcategory.h Modified: trunk/src/model/Model.h =================================================================== --- trunk/src/model/Model.h 2013-12-14 08:58:47 UTC (rev 5572) +++ trunk/src/model/Model.h 2013-12-14 13:39:56 UTC (rev 5573) @@ -27,6 +27,7 @@ #include <wx/sharedptr.h> #include <wx/log.h> #include <wx/string.h> +#include "db/DB_Table.h" class wxString; class wxSQLite3Statement; @@ -64,4 +65,64 @@ protected: wxSQLite3Database* db_; }; + +template<class DB_TABLE> +class Model_Mix: public Model, public DB_TABLE +{ +public: + using DB_TABLE::all; + using DB_TABLE::get; + using DB_TABLE::save; + using DB_TABLE::remove; + /** Return a list of Data records (Data_Set) derived directly from the database. */ + typename DB_TABLE::Data_Set all(typename DB_TABLE::COLUMN col = typename DB_TABLE::COLUMN(0), bool asc = true) + { + this->ensure(this->db_); + return all(db_, col, asc); + } + + template<typename... Args> + typename DB_TABLE::Data_Set find(const Args&... args) + { + return find_by(this, db_, true, args...); + } + template<typename... Args> + typename DB_TABLE::Data_Set find_or(const Args&... args) + { + return find_by(this, db_, false, args...); + } + + /** Return the Data record instance for the given ID*/ + typename DB_TABLE::Data* get(int id) + { + return this->get(id, this->db_); + } + + /** Save the Data record instance in memory to the database. */ + int save(typename DB_TABLE::Data* r) + { + r->save(this->db_); + return r->id(); + } + /** + * Save the all the Data record instances in memory to the database + * for the record list (Data_Set). + */ + template<class DATA_SET> + int save(DATA_SET& rows) + { + this->Begin(); + for (auto& r : rows) this->save(&r); + this->Commit(); + + return rows.size(); + } + + /** Remove the Data record instance from memory and the database. */ + bool remove(int id) + { + return this->remove(id, db_); + } +}; + #endif // Modified: trunk/src/model/Model_Account.h =================================================================== --- trunk/src/model/Model_Account.h 2013-12-14 08:58:47 UTC (rev 5572) +++ trunk/src/model/Model_Account.h 2013-12-14 13:39:56 UTC (rev 5573) @@ -26,17 +26,16 @@ #include "Model_Billsdeposits.h" #include "Model_Stock.h" -class Model_Account : public Model, public DB_Table_ACCOUNTLIST_V1 +class Model_Account : public Model_Mix<DB_Table_ACCOUNTLIST_V1> { - using DB_Table_ACCOUNTLIST_V1::all; - using DB_Table_ACCOUNTLIST_V1::get; - using DB_Table_ACCOUNTLIST_V1::save; - using DB_Table_ACCOUNTLIST_V1::remove; public: + using Model_Mix<DB_Table_ACCOUNTLIST_V1>::remove; + using Model_Mix<DB_Table_ACCOUNTLIST_V1>::get; +public: enum STATUS { OPEN = 0, CLOSED }; enum TYPE { CHECKING = 0, TERM, INVESTMENT }; public: - Model_Account(): Model(), DB_Table_ACCOUNTLIST_V1() + Model_Account(): Model_Mix<DB_Table_ACCOUNTLIST_V1>() { }; ~Model_Account() {}; @@ -100,25 +99,6 @@ return ins; } public: - /** Return a list of Data records (Data_Set) derived directly from the database. */ - Data_Set all(COLUMN col = COLUMN(0), bool asc = true) - { - this->ensure(this->db_); - return all(db_, col, asc); - } - - template<typename... Args> - Data_Set find(const Args&... args) - { - return find_by(this, db_, true, args...); - } - - /** Return the Data record instance for the given ID*/ - Data* get(int id) - { - return this->get(id, this->db_); - } - /** Get the Data record instance in memory. */ Data* get(const wxString& name) { @@ -127,14 +107,7 @@ if (!items.empty()) account = this->get(items[0].ACCOUNTID, this->db_); return account; } - - /** Save the Data record instance in memory to the database. */ - int save(Data* r) - { - r->save(this->db_); - return r->id(); - } - + /** Remove the Data record instance from memory and the database. */ bool remove(int id) { Modified: trunk/src/model/Model_Asset.h =================================================================== --- trunk/src/model/Model_Asset.h 2013-12-14 08:58:47 UTC (rev 5572) +++ trunk/src/model/Model_Asset.h 2013-12-14 13:39:56 UTC (rev 5573) @@ -23,17 +23,14 @@ #include "db/DB_Table_Assets_V1.h" #include "Model_Currency.h" // detect base currency -class Model_Asset : public Model, public DB_Table_ASSETS_V1 +class Model_Asset : public Model_Mix<DB_Table_ASSETS_V1> { - using DB_Table_ASSETS_V1::all; - using DB_Table_ASSETS_V1::get; - using DB_Table_ASSETS_V1::remove; public: enum RATE { RATE_NONE = 0, RATE_APPRECIATE, RATE_DEPRECIATE }; enum TYPE { TYPE_PROPERTY = 0, TYPE_AUTO, TYPE_HOUSE, TYPE_ART, TYPE_JEWELLERY, TYPE_CASH, TYPE_OTHER }; public: - Model_Asset(): Model(), DB_Table_ASSETS_V1() + Model_Asset(): Model_Mix<DB_Table_ASSETS_V1>() { }; ~Model_Asset() {}; @@ -89,37 +86,6 @@ return "$Rev$"; } public: - /** Return a list of Data records (Data_Set) derived directly from the database. */ - Data_Set all(COLUMN col = COLUMN(0), bool asc = true) - { - this->ensure(this->db_); - return all(db_, col, asc); - } - - template<typename... Args> - Data_Set find(const Args&... args) - { - return find_by(this, db_, true, args...); - } - - /** Return the Data record instance for the given ID*/ - Data* get(int id) - { - return this->get(id, this->db_); - } - - /** Save the Data record instance in memory to the database. */ - int save(Data* r) - { - r->save(this->db_); - return r->id(); - } - /** Remove the Data record instance from memory and the database. */ - bool remove(int id) - { - return this->remove(id, db_); - } - double balance() { double balance = 0.0; Modified: trunk/src/model/Model_Billsdeposits.h =================================================================== --- trunk/src/model/Model_Billsdeposits.h 2013-12-14 08:58:47 UTC (rev 5572) +++ trunk/src/model/Model_Billsdeposits.h 2013-12-14 13:39:56 UTC (rev 5573) @@ -26,12 +26,11 @@ const int BD_REPEATS_MULTIPLEX_BASE = 100; -class Model_Billsdeposits : public Model, public DB_Table_BILLSDEPOSITS_V1 +class Model_Billsdeposits : public Model_Mix<DB_Table_BILLSDEPOSITS_V1> { - using DB_Table_BILLSDEPOSITS_V1::all; - using DB_Table_BILLSDEPOSITS_V1::get; - using DB_Table_BILLSDEPOSITS_V1::remove; public: + using Model_Mix<DB_Table_BILLSDEPOSITS_V1>::remove; +public: enum TYPE { WITHDRAWAL = 0, DEPOSIT, TRANSFER }; enum STATUS_ENUM { NONE = 0, RECONCILED, VOID_, FOLLOWUP, DUPLICATE_ }; enum REPEAT_TYPE { @@ -56,7 +55,7 @@ }; public: - Model_Billsdeposits(): Model(), DB_Table_BILLSDEPOSITS_V1() + Model_Billsdeposits(): Model_Mix<DB_Table_BILLSDEPOSITS_V1>() { }; ~Model_Billsdeposits() {}; @@ -153,51 +152,7 @@ } public: - /** Return a list of Data records (Data_Set) derived directly from the database. */ - Data_Set all(COLUMN col = COLUMN(0), bool asc = true) - { - this->ensure(this->db_); - return all(db_, col, asc); - } - - template<typename... Args> - Data_Set find(const Args&... args) - { - return find_by(this, db_, true, args...); - } - template<typename... Args> - Data_Set find_or(const Args&... args) - { - return find_by(this, db_, false, args...); - } - - /** Return the Data record instance for the given ID*/ - Data* get(int id) - { - return this->get(id, this->db_); - } - - /** Save the Data record instance in memory to the database. */ - int save(Data* r) - { - r->save(this->db_); - return r->id(); - } - /** - * Save the all the Data record instances in memory to the database - * for the record list (Data_Set). - */ - int save(Data_Set& rows) - { - this->Begin(); - for (auto& r : rows) this->save(&r); - this->Commit(); - - return rows.size(); - } - - /** * Remove the Data record instance from memory and the database * including any splits associated with the Data Record. */ Modified: trunk/src/model/Model_Budget.h =================================================================== --- trunk/src/model/Model_Budget.h 2013-12-14 08:58:47 UTC (rev 5572) +++ trunk/src/model/Model_Budget.h 2013-12-14 13:39:56 UTC (rev 5573) @@ -24,14 +24,10 @@ #include "model/Model_Category.h" #include "model/Model_Subcategory.h" -class Model_Budget : public Model, public DB_Table_BUDGETTABLE_V1 +class Model_Budget : public Model_Mix<DB_Table_BUDGETTABLE_V1> { - using DB_Table_BUDGETTABLE_V1::all; - using DB_Table_BUDGETTABLE_V1::get; - using DB_Table_BUDGETTABLE_V1::save; - using DB_Table_BUDGETTABLE_V1::remove; public: - Model_Budget(): Model(), DB_Table_BUDGETTABLE_V1() {}; + Model_Budget(): Model_Mix<DB_Table_BUDGETTABLE_V1>() {}; ~Model_Budget() { }; @@ -100,45 +96,6 @@ return ins; } - /** Return a list of Data records (Data_Set) derived directly from the database. */ - Data_Set all(COLUMN col = COLUMN(0), bool asc = true) - { - this->ensure(this->db_); - return this->all(this->db_, col, asc); - } - - template<typename... Args> - Data_Set find(const Args&... args) - { - return find_by(this, db_, true, args...); - } - - /** Return the Data record instance for the given ID*/ - Data* get(int id) - { - return this->get(id, this->db_); - } - - /** Save the Data record instance in memory to the database. */ - int save(Data* r) - { - r->save(this->db_); - return r->id(); - } - int save(Data_Set& rows) - { - this->Begin(); - for (auto& r : rows) this->save(&r); - this->Commit(); - - return rows.size(); - } - - /** Remove the Data record instance from memory and the database. */ - bool remove(int id) - { - return this->remove(id, db_); - } static void getBudgetEntry(int budgetYearID, std::map<int, std::map<int, PERIOD_ENUM> > &budgetPeriod, std::map<int, std::map<int, double> > &budgetAmt) { Modified: trunk/src/model/Model_Budgetsplittransaction.h =================================================================== --- trunk/src/model/Model_Budgetsplittransaction.h 2013-12-14 08:58:47 UTC (rev 5572) +++ trunk/src/model/Model_Budgetsplittransaction.h 2013-12-14 13:39:56 UTC (rev 5573) @@ -22,21 +22,15 @@ #include "Model.h" #include "db/DB_Table_Budgetsplittransactions_V1.h" -class Model_Budgetsplittransaction : public Model, public DB_Table_BUDGETSPLITTRANSACTIONS_V1 +class Model_Budgetsplittransaction : public Model_Mix<DB_Table_BUDGETSPLITTRANSACTIONS_V1> { - using DB_Table_BUDGETSPLITTRANSACTIONS_V1::all; - using DB_Table_BUDGETSPLITTRANSACTIONS_V1::get; - using DB_Table_BUDGETSPLITTRANSACTIONS_V1::remove; public: - Model_Budgetsplittransaction() : Model(), DB_Table_BUDGETSPLITTRANSACTIONS_V1() + Model_Budgetsplittransaction() : Model_Mix<DB_Table_BUDGETSPLITTRANSACTIONS_V1>() { }; ~Model_Budgetsplittransaction() {}; public: - wxArrayString types_; - -public: /** Return the static instance of Model_Budgetsplittransaction table */ static Model_Budgetsplittransaction& instance() { @@ -56,47 +50,7 @@ return ins; } -public: - /** Return a list of Data records (Data_Set) derived directly from the database. */ - Data_Set all(COLUMN col = COLUMN(0), bool asc = true) - { - this->ensure(this->db_); - return all(db_, col, asc); - } - template<typename... Args> - Data_Set find(const Args&... args) - { - return find_by(this, db_, true, args...); - } - - /** Return the Data record instance for the given ID*/ - Data* get(int id) - { - return this->get(id, this->db_); - } - - /** Save the Data record instance in memory to the database. */ - int save(Data* r) - { - r->save(this->db_); - return r->id(); - } - int save(Data_Set& rows) - { - this->Begin(); - for (auto& r : rows) this->save(&r); - this->Commit(); - - return rows.size(); - } - - /** Remove the Data record instance from memory and the database. */ - bool remove(int id) - { - return this->remove(id, this->db_); - } - public: double get_total(Data_Set& rows) { Modified: trunk/src/model/Model_Budgetyear.h =================================================================== --- trunk/src/model/Model_Budgetyear.h 2013-12-14 08:58:47 UTC (rev 5572) +++ trunk/src/model/Model_Budgetyear.h 2013-12-14 13:39:56 UTC (rev 5573) @@ -23,12 +23,12 @@ #include "Model_Budget.h" #include "db/DB_Table_Budgetyear_V1.h" -class Model_Budgetyear : public Model, public DB_Table_BUDGETYEAR_V1 +class Model_Budgetyear : public Model_Mix<DB_Table_BUDGETYEAR_V1> { - using DB_Table_BUDGETYEAR_V1::all; - using DB_Table_BUDGETYEAR_V1::remove; public: - Model_Budgetyear(): Model(), DB_Table_BUDGETYEAR_V1() {}; + using Model_Mix<DB_Table_BUDGETYEAR_V1>::remove; +public: + Model_Budgetyear(): Model_Mix<DB_Table_BUDGETYEAR_V1>() {}; ~Model_Budgetyear() { }; @@ -54,12 +54,6 @@ return ins; } - /** Return a list of Data records (Data_Set) derived directly from the database. */ - Data_Set all(COLUMN col = COLUMN(0), bool asc = true) - { - this->ensure(this->db_); - return this->all(this->db_, col, asc); - } bool remove(int id) { for (Model_Budget::Data& d : Model_Budget::instance().find(Model_Budget::BUDGETYEARID(id))) Modified: trunk/src/model/Model_Category.h =================================================================== --- trunk/src/model/Model_Category.h 2013-12-14 08:58:47 UTC (rev 5572) +++ trunk/src/model/Model_Category.h 2013-12-14 13:39:56 UTC (rev 5573) @@ -27,13 +27,12 @@ #include "Model_Billsdeposits.h" #include "reports/mmDateRange.h" -class Model_Category : public Model, public DB_Table_CATEGORY_V1 +class Model_Category : public Model_Mix<DB_Table_CATEGORY_V1> { - using DB_Table_CATEGORY_V1::all; - using DB_Table_CATEGORY_V1::get; - using DB_Table_CATEGORY_V1::remove; public: - Model_Category(): Model(), DB_Table_CATEGORY_V1() + using Model_Mix<DB_Table_CATEGORY_V1>::get; +public: + Model_Category(): Model_Mix<DB_Table_CATEGORY_V1>() { }; ~Model_Category() {}; @@ -62,11 +61,6 @@ return ins; } public: - /** Return a list of Data records (Data_Set) derived directly from the database. */ - Data_Set all(COLUMN col = COLUMN(0), bool asc = true) - { - return all(db_, col, asc); - } void initialize() { std::vector < std::pair<wxString /*category*/, std::vector<wxString> > > all_categoris; @@ -237,15 +231,6 @@ } this->Commit(); } - template<typename... Args> - Data_Set find(const Args&... args) - { - return find_by(this, db_, true, args...); - } - Data* get(int id) - { - return this->get(id, this->db_); - } Data* get(const wxString& name) { Data* category = 0; @@ -253,15 +238,6 @@ if (!items.empty()) category = this->get(items[0].CATEGID, this->db_); return category; } - int save(Data* r) - { - r->save(this->db_); - return r->id(); - } - bool remove(int id) - { - return this->remove(id, db_); - } public: static Model_Subcategory::Data_Set sub_category(const Data* r) { Modified: trunk/src/model/Model_Checking.h =================================================================== --- trunk/src/model/Model_Checking.h 2013-12-14 08:58:47 UTC (rev 5572) +++ trunk/src/model/Model_Checking.h 2013-12-14 13:39:56 UTC (rev 5573) @@ -23,12 +23,11 @@ #include "db/DB_Table_Checkingaccount_V1.h" #include "Model_Splittransaction.h" -class Model_Checking : public Model, public DB_Table_CHECKINGACCOUNT_V1 +class Model_Checking : public Model_Mix<DB_Table_CHECKINGACCOUNT_V1> { - using DB_Table_CHECKINGACCOUNT_V1::all; - using DB_Table_CHECKINGACCOUNT_V1::get; - using DB_Table_CHECKINGACCOUNT_V1::remove; public: + using Model_Mix<DB_Table_CHECKINGACCOUNT_V1>::remove; +public: enum TYPE { WITHDRAWAL = 0, DEPOSIT, TRANSFER }; enum STATUS_ENUM { NONE = 0, RECONCILED, VOID_, FOLLOWUP, DUPLICATE_ }; public: @@ -55,7 +54,7 @@ } }; public: - Model_Checking(): Model(), DB_Table_CHECKINGACCOUNT_V1() + Model_Checking(): Model_Mix<DB_Table_CHECKINGACCOUNT_V1>() { }; ~Model_Checking() {}; @@ -104,42 +103,6 @@ return ins; } public: - /** Return a list of Data records (Data_Set) directly from the database.*/ - Data_Set all(COLUMN col = COLUMN(0), bool asc = true) - { - this->ensure(this->db_); - return all(db_, col, asc); - } - template<typename... Args> - Data_Set find(const Args&... args) - { - return find_by(this, db_, true, args...); - } - template<typename... Args> - Data_Set find_or(const Args&... args) - { - return find_by(this, db_, false, args...); - } - Data* get(int id) - { - return this->get(id, this->db_); - } - - /** Create a new record or update the existing record in the database.*/ - int save(Data* r) - { - r->save(this->db_); - return r->id(); - } - template<class DATA_SET> - int save(DATA_SET& rows) - { - this->Begin(); - for (auto& r : rows) this->save(&r); - this->Commit(); - - return rows.size(); - } bool remove(int id) { //TODO: remove all split at once Modified: trunk/src/model/Model_Currency.h =================================================================== --- trunk/src/model/Model_Currency.h 2013-12-14 08:58:47 UTC (rev 5572) +++ trunk/src/model/Model_Currency.h 2013-12-14 13:39:56 UTC (rev 5573) @@ -25,13 +25,10 @@ #include <wx/numformatter.h> #include <tuple> -class Model_Currency : public Model, public DB_Table_CURRENCYFORMATS_V1 +class Model_Currency : public Model_Mix<DB_Table_CURRENCYFORMATS_V1> { - using DB_Table_CURRENCYFORMATS_V1::all; - using DB_Table_CURRENCYFORMATS_V1::get; - using DB_Table_CURRENCYFORMATS_V1::remove; public: - Model_Currency(): Model(), DB_Table_CURRENCYFORMATS_V1() {}; + Model_Currency(): Model_Mix<DB_Table_CURRENCYFORMATS_V1>() {}; ~Model_Currency() {}; public: @@ -58,16 +55,6 @@ } public: - /** Return a list of Data records (Data_Set) derived directly from the database. */ - Data_Set all(COLUMN col = COLUMN(0), bool asc = true) - { - return all(db_, col, asc); - } - template<typename... Args> - Data_Set find(const Args&... args) - { - return find_by(this, db_, true, args...); - } wxArrayString all_currency_names() { wxArrayString c; @@ -103,27 +90,6 @@ } this->Commit(); } - Data* get(int id) - { - return get(id, this->db_); - } - int save(Data* r) - { - r->save(this->db_); - return r->id(); - } - int save(Data_Set& rows) - { - this->Begin(); - for (auto& r : rows) this->save(&r); - this->Commit(); - - return rows.size(); - } - bool remove(int id) - { - return this->remove(id, db_); - } public: // Getter static Data* GetBaseCurrency() Modified: trunk/src/model/Model_Infotable.h =================================================================== --- trunk/src/model/Model_Infotable.h 2013-12-14 08:58:47 UTC (rev 5572) +++ trunk/src/model/Model_Infotable.h 2013-12-14 13:39:56 UTC (rev 5573) @@ -24,13 +24,10 @@ #include "defs.h" #include "constants.h" -class Model_Infotable : public Model, public DB_Table_INFOTABLE_V1 +class Model_Infotable : public Model_Mix<DB_Table_INFOTABLE_V1> { - using DB_Table_INFOTABLE_V1::all; - using DB_Table_INFOTABLE_V1::get; - using DB_Table_INFOTABLE_V1::remove; public: - Model_Infotable(): Model(), DB_Table_INFOTABLE_V1() {}; + Model_Infotable(): Model_Mix<DB_Table_INFOTABLE_V1>() {}; ~Model_Infotable() { }; @@ -64,27 +61,6 @@ } public: - /** Return a list of Data records (Data_Set) derived directly from the database. */ - Data_Set all(COLUMN col = COLUMN(0), bool asc = true) - { - this->ensure(this->db_); - return this->all(this->db_, col, asc); - } - template<typename... Args> - Data_Set find(const Args&... args) - { - return find_by(this, db_, true, args...); - } - Data* get(int id) - { - return this->get(id, this->db_); - } - bool remove(int id) - { - return this->remove(id, db_); - } - -public: // Setter void Set(const wxString& key, int value) { Modified: trunk/src/model/Model_Payee.h =================================================================== --- trunk/src/model/Model_Payee.h 2013-12-14 08:58:47 UTC (rev 5572) +++ trunk/src/model/Model_Payee.h 2013-12-14 13:39:56 UTC (rev 5573) @@ -24,13 +24,12 @@ #include "Model_Checking.h" // detect whether the payee is used or not #include "Model_Billsdeposits.h" -class Model_Payee : public Model, public DB_Table_PAYEE_V1 +class Model_Payee : public Model_Mix<DB_Table_PAYEE_V1> { - using DB_Table_PAYEE_V1::all; - using DB_Table_PAYEE_V1::get; - using DB_Table_PAYEE_V1::remove; public: - Model_Payee(): Model(), DB_Table_PAYEE_V1() + using Model_Mix<DB_Table_PAYEE_V1>::get; +public: + Model_Payee(): Model_Mix<DB_Table_PAYEE_V1>() { }; ~Model_Payee() {}; @@ -56,16 +55,6 @@ return ins; } public: - Data_Set all(COLUMN col = COLUMN(0), bool asc = true) - { - this->ensure(this->db_); - return all(db_, col, asc); - } - template<typename... Args> - Data_Set find(const Args&... args) - { - return find_by(this, db_, true, args...); - } Data_Set FilterPayees(const wxString& payee_pattern) { Data_Set payees; @@ -76,10 +65,6 @@ } return payees; } - Data* get(int id) - { - return this->get(id, this->db_); - } Data* get(const wxString& name) { Data* payee = 0; @@ -87,24 +72,11 @@ if (!items.empty()) payee = this->get(items[0].PAYEEID, this->db_); return payee; } - int save(Data* r) - { - r->save(this->db_); - return r->id(); - } - int save(Data_Set& rows) - { - this->Begin(); - for (auto& r : rows) this->save(&r); - this->Commit(); - - return rows.size(); - } bool remove(int id) { if (is_used(id)) return false; - return this->remove(id, db_); + return this->remove(id); } public: wxArrayString all_payee_names() Modified: trunk/src/model/Model_Report.h =================================================================== --- trunk/src/model/Model_Report.h 2013-12-14 08:58:47 UTC (rev 5572) +++ trunk/src/model/Model_Report.h 2013-12-14 13:39:56 UTC (rev 5573) @@ -23,13 +23,10 @@ #include "db/DB_Table_Report_V1.h" #include "reports/htmlbuilder.h" -class Model_Report : public Model, public DB_Table_REPORT_V1 +class Model_Report : public Model_Mix<DB_Table_REPORT_V1> { - using DB_Table_REPORT_V1::all; - using DB_Table_REPORT_V1::get; - using DB_Table_REPORT_V1::remove; public: - Model_Report(): Model(), DB_Table_REPORT_V1() + Model_Report(): Model_Mix<DB_Table_REPORT_V1>() { }; ~Model_Report() {}; @@ -55,45 +52,6 @@ return ins; } public: - /** Return a list of Data records (Data_Set) derived directly from the database. */ - Data_Set all(COLUMN col = COLUMN(0), bool asc = true) - { - this->ensure(this->db_); - return all(db_, col, asc); - } - template<typename... Args> - Data_Set find(const Args&... args) - { - return find_by(this, db_, true, args...); - } - Data* get(int id) - { - return this->get(id, this->db_); - } - - /** Create a new record or update the existing record in the database.*/ - int save(Data* r) - { - r->save(this->db_); - return r->id(); - } - - /** Create new or update existing records in the database for the record list.*/ - int save(Data_Set& rows) - { - this->Begin(); - for (auto& r : rows) this->save(&r); - this->Commit(); - - return rows.size(); - } - bool remove(int id) - { - Data *entry = get(id); - return entry->remove(this->db_); - } - -public: wxString get_html(const Data* r) { mm_html_template report(r->TEMPLATEPATH); Modified: trunk/src/model/Model_Setting.h =================================================================== --- trunk/src/model/Model_Setting.h 2013-12-14 08:58:47 UTC (rev 5572) +++ trunk/src/model/Model_Setting.h 2013-12-14 13:39:56 UTC (rev 5573) @@ -24,11 +24,10 @@ #include "defs.h" #include "paths.h" -class Model_Setting : public Model, public DB_Table_SETTING_V1 +class Model_Setting : public Model_Mix<DB_Table_SETTING_V1> { - using DB_Table_SETTING_V1::all; public: - Model_Setting(): Model(), DB_Table_SETTING_V1() {}; + Model_Setting(): Model_Mix<DB_Table_SETTING_V1>() {}; ~Model_Setting() {}; public: @@ -52,20 +51,6 @@ } public: - /** Return a list of Data records (Data_Set) derived directly from the database. */ - Data_Set all(COLUMN col = COLUMN(0), bool asc = true) - { - this->ensure(this->db_); - return this->all(this->db_, col, asc); - } - - template<typename... Args> - Data_Set find(const Args&... args) - { - return find_by(this, db_, true, args...); - } - -public: // Setter void Set(const wxString& key, int value) { Modified: trunk/src/model/Model_Splittransaction.h =================================================================== --- trunk/src/model/Model_Splittransaction.h 2013-12-14 08:58:47 UTC (rev 5572) +++ trunk/src/model/Model_Splittransaction.h 2013-12-14 13:39:56 UTC (rev 5573) @@ -22,20 +22,15 @@ #include "Model.h" #include "db/DB_Table_Splittransactions_V1.h" -class Model_Splittransaction : public Model, public DB_Table_SPLITTRANSACTIONS_V1 +class Model_Splittransaction : public Model_Mix<DB_Table_SPLITTRANSACTIONS_V1> { - using DB_Table_SPLITTRANSACTIONS_V1::all; - using DB_Table_SPLITTRANSACTIONS_V1::get; public: - Model_Splittransaction(): Model(), DB_Table_SPLITTRANSACTIONS_V1() + Model_Splittransaction(): Model_Mix<DB_Table_SPLITTRANSACTIONS_V1>() { }; ~Model_Splittransaction() {}; public: - wxArrayString types_; - -public: /** Return the static instance of Model_Splittransaction table */ static Model_Splittransaction& instance() { @@ -56,47 +51,8 @@ return ins; } public: - /** Return a list of Data records (Data_Set) derived directly from the database. */ - Data_Set all(COLUMN col = COLUMN(0), bool asc = true) + static double get_total(const Data_Set& rows) { - this->ensure(this->db_); - return all(db_, col, asc); - } - template<typename... Args> - Data_Set find(const Args&... args) - { - return find_by(this, db_, true, args...); - } - Data* get(int id) - { - return this->get(id, this->db_); - } - - /** Create a new record or update the existing record in the database.*/ - int save(Data* r) - { - r->save(this->db_); - return r->id(); - } - - /** Create new or update existing records in the database for the record list.*/ - int save(Data_Set& rows) - { - this->Begin(); - for (auto& r : rows) this->save(&r); - this->Commit(); - - return rows.size(); - } - bool remove(int id) - { - Data *entry = get(id); - return entry->remove(this->db_); - } - -public: - static double get_total(Data_Set& rows) - { double total = 0.0; for (auto& r : rows) total += r.SPLITTRANSAMOUNT; return total; Modified: trunk/src/model/Model_Stock.h =================================================================== --- trunk/src/model/Model_Stock.h 2013-12-14 08:58:47 UTC (rev 5572) +++ trunk/src/model/Model_Stock.h 2013-12-14 13:39:56 UTC (rev 5573) @@ -23,14 +23,10 @@ #include "db/DB_Table_Stock_V1.h" #include "Model_Currency.h" // detect base currency -class Model_Stock : public Model, public DB_Table_STOCK_V1 +class Model_Stock : public Model_Mix<DB_Table_STOCK_V1> { - using DB_Table_STOCK_V1::all; - using DB_Table_STOCK_V1::get; - using DB_Table_STOCK_V1::save; - using DB_Table_STOCK_V1::remove; public: - Model_Stock(): Model(), DB_Table_STOCK_V1() {}; + Model_Stock(): Model_Mix<DB_Table_STOCK_V1>() {}; ~Model_Stock() {}; public: @@ -54,37 +50,6 @@ return ins; } public: - /** Return a list of Data records (Data_Set) derived directly from the database. */ - Data_Set all(COLUMN col = COLUMN(0), bool asc = true) - { - this->ensure(this->db_); - return all(db_, col, asc); - } - - template<typename... Args> - Data_Set find(const Args&... args) - { - return find_by(this, db_, true, args...); - } - - /** Return the Data record instance for the given ID*/ - Data* get(int id) - { - return this->get(id, this->db_); - } - /** Save the Data record instance in memory to the database. */ - int save(Data* r) - { - r->save(this->db_); - return r->id(); - } - /** Remove the Data record instance from memory and the database. */ - bool remove(int id) - { - return this->remove(id, db_); - } - -public: static wxDate PURCHASEDATE(const Data* stock) { return Model::to_date(stock->PURCHASEDATE); } static wxDate PURCHASEDATE(const Data& stock) { return Model::to_date(stock.PURCHASEDATE); } public: Modified: trunk/src/model/Model_Subcategory.h =================================================================== --- trunk/src/model/Model_Subcategory.h 2013-12-14 08:58:47 UTC (rev 5572) +++ trunk/src/model/Model_Subcategory.h 2013-12-14 13:39:56 UTC (rev 5573) @@ -25,21 +25,17 @@ #include "Model_Checking.h" #include "Model_Billsdeposits.h" -class Model_Subcategory : public Model, public DB_Table_SUBCATEGORY_V1 +class Model_Subcategory : public Model_Mix<DB_Table_SUBCATEGORY_V1> { - using DB_Table_SUBCATEGORY_V1::all; - using DB_Table_SUBCATEGORY_V1::get; - using DB_Table_SUBCATEGORY_V1::remove; public: - Model_Subcategory(): Model(), DB_Table_SUBCATEGORY_V1() + using Model_Mix<DB_Table_SUBCATEGORY_V1>::get; +public: + Model_Subcategory(): Model_Mix<DB_Table_SUBCATEGORY_V1>() { }; ~Model_Subcategory() {}; public: - wxArrayString types_; - -public: /** Return the static instance of Model_Subcategory table */ static Model_Subcategory& instance() { @@ -60,25 +56,6 @@ return ins; } public: - /** Return a list of Data records (Data_Set) derived directly from the database. */ - Data_Set all(COLUMN col = COLUMN(0), bool asc = true) - { - this->ensure(this->db_); - return all(db_, col, asc); - } - - template<typename... Args> - Data_Set find(const Args&... args) - { - return find_by(this, db_, true, args...); - } - - /** Return the Data record instance for the given ID*/ - Data* get(int id) - { - return this->get(id, this->db_); - } - /** Return the Data record instance for the given subcategory name and category ID */ Data* get(const wxString& name, int category_id = -1) { @@ -88,18 +65,6 @@ return category; } - /** Save the Data record instance in memory to the database. */ - int save(Data* r) - { - r->save(this->db_); - return r->id(); - } - - /** Remove the Data record instance from memory and the database. */ - bool remove(int id) - { - return this->remove(id, db_); - } public: static bool is_used(int id) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |