summaryrefslogtreecommitdiff
path: root/src/storage.h
diff options
context:
space:
mode:
authorHuynh Tran <nthuynh75@gmail.com>2005-06-19 07:10:58 +0000
committerHuynh Tran <nthuynh75@gmail.com>2005-06-19 07:10:58 +0000
commitee3b57e273e4b0437aaaa23ba6addb68e4c4fcca (patch)
treea6218c7fc44684bd5ed3ee8683c6633767dc9de0 /src/storage.h
parent514b591061df787a840a560b2e99285eca527f2f (diff)
downloadmanaserv-ee3b57e273e4b0437aaaa23ba6addb68e4c4fcca.tar.gz
manaserv-ee3b57e273e4b0437aaaa23ba6addb68e4c4fcca.tar.bz2
manaserv-ee3b57e273e4b0437aaaa23ba6addb68e4c4fcca.tar.xz
manaserv-ee3b57e273e4b0437aaaa23ba6addb68e4c4fcca.zip
Reworked Storage APIs and reordered operations in DALStorage to match those of Storage.
Diffstat (limited to 'src/storage.h')
-rw-r--r--src/storage.h122
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_