aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHugo Lima <hugo.lima@openbossa.org>2009-09-18 15:02:04 -0300
committerHugo Lima <hugo.lima@openbossa.org>2009-09-18 15:02:04 -0300
commit38283f8ae3a479dbc213ff16c8b727094028bb9a (patch)
tree48dbd447ab9e2f7d6702bcc78c0a386c30357cc7
parentbe5fb84cf7a20d7fe446ef8fdb3b03914fca8526 (diff)
- Turn ctors of TypeDatabase private (It's a singleton!)
- Makes possible to reset the TypeDatabase, this is usefull in unit tests when you need to make all unit tests independent of each other.
-rw-r--r--typesystem.cpp9
-rw-r--r--typesystem.h11
2 files changed, 16 insertions, 4 deletions
diff --git a/typesystem.cpp b/typesystem.cpp
index 4b32b965f..ae5c3a1c8 100644
--- a/typesystem.cpp
+++ b/typesystem.cpp
@@ -1591,9 +1591,14 @@ bool Handler::startElement(const QString &, const QString &n,
return true;
}
-TypeDatabase *TypeDatabase::instance()
+TypeDatabase *TypeDatabase::instance(bool newInstance)
{
- static TypeDatabase *db = new TypeDatabase();
+ static TypeDatabase *db = 0;
+ if (!db || newInstance) {
+ if (db)
+ delete db;
+ db = new TypeDatabase;
+ }
return db;
}
diff --git a/typesystem.h b/typesystem.h
index 65dd28a01..945461a2d 100644
--- a/typesystem.h
+++ b/typesystem.h
@@ -1718,10 +1718,17 @@ struct TypeRejection
class TypeDatabase
{
-public:
TypeDatabase();
+ TypeDatabase(const TypeDatabase&);
+ TypeDatabase& operator=(const TypeDatabase&);
+public:
- static TypeDatabase *instance();
+ /**
+ * Return the type system instance.
+ * \param newInstance This parameter is usefull just for unit testing, because singletons causes
+ * too many side effects on unit testing.
+ */
+ static TypeDatabase *instance(bool newInstance = false);
QStringList requiredTargetImports()
{