aboutsummaryrefslogtreecommitdiff
path: root/common/singleton.h
diff options
context:
space:
mode:
authorMax Horn2003-10-08 21:59:23 +0000
committerMax Horn2003-10-08 21:59:23 +0000
commitd1773647159f9ef1393d7a1d33204de5886edce5 (patch)
treed31f1a3689fa34a525671f21d7a858fe8570762f /common/singleton.h
parent3c78c0929c553fd67016f87c6cdc38d3f50d7ca2 (diff)
downloadscummvm-rg350-d1773647159f9ef1393d7a1d33204de5886edce5.tar.gz
scummvm-rg350-d1773647159f9ef1393d7a1d33204de5886edce5.tar.bz2
scummvm-rg350-d1773647159f9ef1393d7a1d33204de5886edce5.zip
new config manager. not everything is completed, and some things will still be changed, but it seems to work well enough to put it into CVS
svn-id: r10687
Diffstat (limited to 'common/singleton.h')
-rw-r--r--common/singleton.h57
1 files changed, 57 insertions, 0 deletions
diff --git a/common/singleton.h b/common/singleton.h
new file mode 100644
index 0000000000..be40b45f42
--- /dev/null
+++ b/common/singleton.h
@@ -0,0 +1,57 @@
+/* ScummVM - Scumm Interpreter
+ * Copyright (C) 2001 Ludvig Strigeus
+ * Copyright (C) 2001-2003 The ScummVM project
+ *
+ * This program 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 (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.
+ *
+ * $Header$
+ *
+ */
+
+#ifndef COMMON_SINGLETON_H
+#define COMMON_SINGLETON_H
+
+namespace Common {
+
+/**
+ * Generic template base class for implementing the singleton design pattern.
+ */
+template <class T>
+class Singleton
+{
+public:
+ static T& instance() {
+ // TODO: We aren't thread safe. For now we ignore it since the
+ // only thing using this singleton template is the config manager,
+ // and that is first instantiated long before any threads.
+ // TODO: We don't leak, but the destruction order is nevertheless
+ // semi-random. If we use multiple singletons, the destruction
+ // order might become an issue. There are various approaches
+ // to solve that problem, but for now this is sufficient
+ static T singleton;
+ return singleton;
+ }
+protected:
+ Singleton<T>() { }
+ ~Singleton<T>() { }
+
+private:
+ Singleton(const Singleton&);
+ Singleton& operator= (const Singleton&);
+};
+
+} // End of namespace Common
+
+#endif