From 9e3df7f5e0b6d365852903c84302edc0ee939419 Mon Sep 17 00:00:00 2001 From: Sverre Rabbelier Date: Sun, 30 Mar 2008 18:49:48 +0200 Subject: [PATCH] More documentation, it made me realise Savable.h belongs in Core instead of DAL. --- src/Core/Core.project | 1 + src/{DAL => Core}/Savable.h | 39 ++++++++++++++++++- src/DAL/DAL.project | 1 - src/DAL/SavableHeaders.h | 5 +++ src/DAL/SavableManagers.h | 27 ++++++++++++- src/DAL/SqliteMgr.h | 93 +++++++++++++++++++++++++++++++++++++-------- 6 files changed, 145 insertions(+), 21 deletions(-) rename src/{DAL => Core}/Savable.h (66%) diff --git a/src/Core/Core.project b/src/Core/Core.project index 7e80ef1..19da14b 100644 --- a/src/Core/Core.project +++ b/src/Core/Core.project @@ -50,6 +50,7 @@ + diff --git a/src/DAL/Savable.h b/src/Core/Savable.h similarity index 66% rename from src/DAL/Savable.h rename to src/Core/Savable.h index f7be1b0..52f5ca3 100644 --- a/src/DAL/Savable.h +++ b/src/Core/Savable.h @@ -19,27 +19,62 @@ ***************************************************************************/ #pragma once +/** + * @file Savable.h + * @brief This file contains the Savable class. + * + * @see Savable + */ + #include "Types.h" +/** + * An interface to for SavableManager wrappers. + * + * This interface is meant to wrap a SavableManager. + * It provides basic functionality to allow general interaction with SavableManagers. + * + * @see SavableManager + */ class Savable { public: + /** Construct a new Savable. */ Savable(void) { }; + /** Destructor, a noop. */ virtual ~Savable(void) { }; + /** Delete this savable. */ virtual void Delete() = 0; + + /** Save this savable. */ virtual void Save() = 0; + + /** Delete this savable providing details as to who deleted it and why. */ virtual void Delete(value_type accountid, const std::string& description) { this->Delete(); } + + /** Save this savable providing details as to who deleted it and why. */ virtual void Save(value_type accountid, const std::string& description) { this->Save(); } + + /** Discard changes made to this savable. */ virtual void Discard() = 0; + + /** Wether this savable has been saved yet. */ virtual bool Exists() = 0; + + /** Returns an elaborate string representation of the savable. */ virtual std::vector Show() = 0; + + /** Returns a one-line string representation of the savable. */ virtual std::string ShowShort() = 0; + + /** Returns the table this savable belongs to. */ virtual TableImplPtr getTable() const = 0; private: - Savable(const Savable& rhs) {}; + /** Hide the copy constructor. */ + Savable(const Savable& rhs); }; -typedef SmartPtr SavablePtr; +typedef SmartPtr SavablePtr; /**< The type of a pointer to a savable. */ diff --git a/src/DAL/DAL.project b/src/DAL/DAL.project index 55e5cfe..009c1c4 100644 --- a/src/DAL/DAL.project +++ b/src/DAL/DAL.project @@ -37,7 +37,6 @@ - diff --git a/src/DAL/SavableHeaders.h b/src/DAL/SavableHeaders.h index 27a96f2..3ea6645 100644 --- a/src/DAL/SavableHeaders.h +++ b/src/DAL/SavableHeaders.h @@ -19,6 +19,11 @@ ***************************************************************************/ #pragma once +/** + * @file SavableHeaders.h + * @brief This file contains all the headers required to use the DAL. + */ + #include "Types.h" #include "Table.h" #include "Tables.h" diff --git a/src/DAL/SavableManagers.h b/src/DAL/SavableManagers.h index cd36e20..f440edd 100644 --- a/src/DAL/SavableManagers.h +++ b/src/DAL/SavableManagers.h @@ -21,22 +21,45 @@ #include "Types.h" +/** + * This class is a bucket for SavableManager objects. + * + * It will only add SavableManagers that belong to the same table the bucket was constructed with. + * This is asserted at run-time. + * + * @see SavableManager + */ class SavableManagers { public: + /** Constructs a SavableManager bucket with the specified table. */ SavableManagers(TableImplPtr table); + + /** Destructor, a noop. */ ~SavableManagers(); + /** Returns the table this SavableManager bucket is for. */ TableImplPtr getTable() const; + + + /** Add a manager to the bucket, it is asserted at run-time to belong to the same table this bucket was constructed with. */ void addManager(SavableManagerPtr manager); + + /** Returns a header that details all the fields for the table this SavableManager bucket was constructed with. */ Strings getHeader() const; + + /** Returns the size of the SavableManagers in this bucket. */ size_t size() const { return m_managers.size(); } + + /** Returns an iterator to the first SavableManager in this bucket. */ SavableManagerVector::const_iterator begin() const { return m_managers.begin(); } + + /** Returns the 'end' iterator of the SavableManagers in this bucket. */ SavableManagerVector::const_iterator end() const { return m_managers.end(); } private: - TableImplPtr m_table; - SavableManagerVector m_managers; + TableImplPtr m_table; /**< The table this SavableManager bucket is for. */ + SavableManagerVector m_managers; /**< The SavableManagers contained in this bucket. */ }; diff --git a/src/DAL/SqliteMgr.h b/src/DAL/SqliteMgr.h index 6d3750f..416e484 100644 --- a/src/DAL/SqliteMgr.h +++ b/src/DAL/SqliteMgr.h @@ -20,55 +20,116 @@ #pragma once +/** + * @file SqliteMgr.h + * @brief This file contains the SqliteMgr class. + * + * @see SqliteMgr + */ + #include "Types.h" #include class Statements; -typedef SmartPtr StatementsPtr; +typedef SmartPtr StatementsPtr; /**< The type of a pointer to a prepared statement bucket. */ class StatementStrings; -typedef SmartPtr StatementStringsPtr; +typedef SmartPtr StatementStringsPtr; /**< The type of a pointer to a sql statement bucket. */ -typedef std::map TableStatements; -typedef std::map TableStatementStrings; +typedef std::map TableStatements; /**< The type of a TableImpl to statements pointer map. */ +typedef std::map TableStatementStrings; /**< The type of a TableImpl to a sql statment pointer map. */ +/** + * This class interfaces between savable managers and an Sqlite database. + */ class SqliteMgr : public Singleton { public: + /** Execute an insertion with the specified savable manager. */ void doInsert(SavableManager* bindable); + + /** Execute an erase with the specified savable manager. */ void doErase(SavableManager* bindable); + + /** Execute an update with the specified savable manager. */ void doUpdate(SavableManager* bindable); + + /** Execute a selection with the specified savable manager. */ void doSelect(SavableManager* bindable); + + /** Execute a lookup on the specified field with the specified savable manager. */ void doLookup(SavableManager* bindable, FieldPtr field); + /** Execute a selection on multiple entries from the databse with the specified mask. */ void doSelectMulti(SelectionMask* mask); + + /** Returns the query of the specified table. */ std::string tableQuery(TableDefPtr table) const; + + /** + * Returns the query to create the specified table. + * + * @param verify Whether the query is to verify the entry in the database or to insert it. + */ std::string creationQuery(TableDefPtr table, bool verify = false) const; + + /** Returns the query to create a specific field in the table. */ std::string creationString(FieldDefPtr table) const; private: - Database* m_db; - Database::OPENDB* m_odb; - const char* m_leftover; + /** + * This is a singleton class, use the Get method to get the instance. + * + * @see Get + */ + SqliteMgr(); - TableStatements m_statements; - TableStatementStrings m_statementstrings; + /** + * This is a singleton class, use the Free method to free the instance. + * + * @see Free + */ + ~SqliteMgr(); + friend class Singleton; + /** Execute the specified statement once, returns true if there are more rows available. */ + bool doStatement(sqlite3_stmt* stmt); + + /** Commits changes to table, currently clears all prepared statements. */ void commit(TableImpl* table); - StatementsPtr getStatements(TableImpl* table); - StatementStringsPtr getStatementStrings(TableImpl* table); + /** Returns the prepared statement to insert an entry into the specified table. */ sqlite3_stmt* getInsertStmt(TableImpl* table); + + /** Returns the prepared statement to erase an entry from the specified table. */ sqlite3_stmt* getEraseStmt(TableImpl* table); + + /** Returns the preppared statement to update an entry in the specified table. */ sqlite3_stmt* getUpdateStmt(TableImpl* table); + + /** Returns the preppared statement to select an entry from the specified table. */ sqlite3_stmt* getSelectStmt(TableImpl* table); + + /** Returns the preppared statement to lookup an entry for the specified table on the specified field. */ sqlite3_stmt* getLookupStmt(TableImpl* table, FieldPtr field); - sqlite3_stmt* getSelectMultiStmt(SelectionMask* table); - friend class Singleton; - SqliteMgr(); - ~SqliteMgr(); - bool doStatement(sqlite3_stmt* stmt); + /** Returns the preppared statement to select multiple entries from the specified table. */ + sqlite3_stmt* getSelectMultiStmt(SelectionMask* table); + + + /** Returns the prepared statements bucket for the specified table. */ + StatementsPtr getStatements(TableImpl* table); + + /** Returns the SQL statements buckeet for the specified table. */ + StatementStringsPtr getStatementStrings(TableImpl* table); + + + Database* m_db; /**< The database used. */ + Database::OPENDB* m_odb; /**< The database connection used. */ + const char* m_leftover; /**< The leftover from preparing a statement. */ + + TableStatements m_statements; /**< A map containing the prepared statements per table. */ + TableStatementStrings m_statementstrings; /**< A map containing the SQL statements per table. */ }; -- 2.11.4.GIT