diff options
Diffstat (limited to 'src/storage.h')
-rw-r--r-- | src/storage.h | 122 |
1 files changed, 95 insertions, 27 deletions
diff --git a/src/storage.h b/src/storage.h index e5be589d..e6c93ba7 100644 --- a/src/storage.h +++ b/src/storage.h @@ -4,65 +4,133 @@ * * This file is part of The Mana World. * - * The Mana World is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. + * The Mana World is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or any later version. * - * The Mana World 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. + * The Mana World 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 The Mana World; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * You should have received a copy of the GNU General Public License along + * with The Mana World; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * $Id$ */ -#ifndef TMWSERV_STORAGE_H -#define TMWSERV_STORAGE_H + + +#ifndef _TMWSERV_STORAGE_H_ +#define _TMWSERV_STORAGE_H_ + #include "object.h" #include "account.h" + +namespace tmwserv +{ + + /** - * A storage of persistent dynamic data. + * A storage to load and persist dynamic data. + * + * Notes: + * - this class implements the singleton design pattern. + * - destroy() must be called at least once before the application + * exits or else there will be a memory leak. */ class Storage { public: - static Storage *getInstance(); - static void deleteInstance(); + /** + * Create an instance of Storage. + * + * @return the unique instance of Storage. + * + * @exception std::bad_alloc if the instance cannot be created. + */ + static Storage& + instance(void); + /** - * Make sure any changes are saved. + * Delete the storage. */ - virtual void flush() = 0; + static void + destroy(void); + /** - * Account count (test function). + * Get an account by user name. + * + * @param userName the owner of the account. + * + * @return the account associated to the user name. + */ + virtual Account* + getAccount(const std::string& userName) = 0; + + + /** + * Add a new account. + * + * @param account the new account. */ - virtual unsigned int getAccountCount() = 0; + virtual void + addAccount(const Account* account) = 0; + /** - * Get account by username. + * Make sure any changes are saved. */ - virtual Account *getAccount(const std::string &username) = 0; + virtual void + flush(void) = 0; + + + /** + * Account count (test function). + */ + virtual unsigned int + getAccountCount(void) = 0; + protected: /** - * Constructor. + * Default constructor. */ - Storage(); + Storage(void) + throw(); + /** * Destructor. */ - virtual ~Storage(); + virtual + ~Storage(void) + throw(); + + + /** + * Copy constructor. + */ + Storage(const Storage& rhs); + + + /** + * Assignment operator. + */ + Storage& + operator=(const Storage& rhs); + private: - static Storage *instance; + static Storage* mInstance; /**< the unique instance of Storage */ }; -#endif /* TMWSERV_STORAGE_H */ + +} // namespace tmwserv + + +#endif // _TMWSERV_STORAGE_H_ |