[Tux4kids-commits] r1228 - in tux4kids-admin/trunk: libtux4kidsadmin libtux4kidsadmin_tuxmath libtux4kidsadmin_tuxtype tux4kids-admin/src
Michał Świtakowski
swistakers-guest at alioth.debian.org
Sat Jul 18 00:07:37 UTC 2009
Author: swistakers-guest
Date: 2009-07-18 00:07:31 +0000 (Sat, 18 Jul 2009)
New Revision: 1228
Added:
tux4kids-admin/trunk/libtux4kidsadmin_tuxmath/profileDirTuxmathRegister.cpp
tux4kids-admin/trunk/libtux4kidsadmin_tuxtype/profileDirTuxtypeRegister.cpp
Modified:
tux4kids-admin/trunk/libtux4kidsadmin/objectFactory.h
tux4kids-admin/trunk/libtux4kidsadmin/profileDir.cpp
tux4kids-admin/trunk/libtux4kidsadmin/profileDirFactory.h
tux4kids-admin/trunk/libtux4kidsadmin/profileDirFactory_p.h
tux4kids-admin/trunk/libtux4kidsadmin_tuxmath/CMakeLists.txt
tux4kids-admin/trunk/libtux4kidsadmin_tuxmath/libtux4kidsadmin_tuxmath.pro
tux4kids-admin/trunk/libtux4kidsadmin_tuxmath/profileDirTuxmath.cpp
tux4kids-admin/trunk/libtux4kidsadmin_tuxtype/CMakeLists.txt
tux4kids-admin/trunk/libtux4kidsadmin_tuxtype/libtux4kidsadmin_tuxtype.pro
tux4kids-admin/trunk/libtux4kidsadmin_tuxtype/profileDirTuxtype.cpp
tux4kids-admin/trunk/tux4kids-admin/src/mainController.cpp
Log:
factory works
Modified: tux4kids-admin/trunk/libtux4kidsadmin/objectFactory.h
===================================================================
--- tux4kids-admin/trunk/libtux4kidsadmin/objectFactory.h 2009-07-17 22:10:17 UTC (rev 1227)
+++ tux4kids-admin/trunk/libtux4kidsadmin/objectFactory.h 2009-07-18 00:07:31 UTC (rev 1228)
@@ -29,13 +29,14 @@
#define OBJECT_FACTORY_H
#include <QMap>
+#include <QDebug>
/****************************** 0 parameters *************************/
template <typename CtorSignature, typename UniqueIdType> class ObjectFactory;
template<typename BaseClassType, typename ClassType>
-BaseClassType createObject()
+BaseClassType *CreateObject()
{
return new ClassType();
}
@@ -44,7 +45,7 @@
class ObjectFactory<BaseClassType (), UniqueIdType>
{
protected:
- typedef BaseClassType (*CreateObjectFunc)();
+ typedef BaseClassType *(*CreateObjectFunc)();
public:
template<typename ClassType>
@@ -52,7 +53,7 @@
{
if (m_objectCreator.contains(uniqueId))
return false;
- m_objectCreator[uniqueId] = &createObject<BaseClassType, ClassType>;
+ m_objectCreator[uniqueId] = &CreateObject<BaseClassType, ClassType>;
return true;
}
@@ -61,12 +62,12 @@
return (m_objectCreator.remove(uniqueId) >= 1);
}
- BaseClassType create(UniqueIdType uniqueId)
+ BaseClassType *create(UniqueIdType uniqueId)
{
if (!m_objectCreator.contains(uniqueId))
return 0;
else
- return new BaseClassType();
+ return m_objectCreator[uniqueId]();
}
protected:
@@ -76,7 +77,7 @@
/****************************** 1 parameter *************************/
template<typename BaseClassType, typename Param1Type, typename ClassType>
-BaseClassType createObject(Param1Type param1)
+BaseClassType *CreateObject(Param1Type param1)
{
return new ClassType(param1);
}
@@ -85,7 +86,7 @@
class ObjectFactory<BaseClassType (Param1Type), UniqueIdType>
{
protected:
- typedef BaseClassType (*CreateObjectFunc)(Param1Type);
+ typedef BaseClassType *(*CreateObjectFunc)(Param1Type);
public:
@@ -94,7 +95,7 @@
{
if (m_objectCreator.contains(uniqueId))
return false;
- m_objectCreator[uniqueId] = &createObject<BaseClassType, Param1Type, ClassType>;
+ m_objectCreator[uniqueId] = &CreateObject<BaseClassType, Param1Type, ClassType>;
return true;
}
@@ -103,12 +104,12 @@
return (m_objectCreator.remove(uniqueId) >= 1);
}
- BaseClassType create(UniqueIdType uniqueId, Param1Type param1)
+ BaseClassType *create(UniqueIdType uniqueId, Param1Type param1)
{
if (!m_objectCreator.contains(uniqueId))
return 0;
else
- return new BaseClassType(param1);
+ return m_objectCreator[uniqueId](param1);
}
protected:
@@ -119,7 +120,7 @@
/****************************** 2 parameters *************************/
template<typename BaseClassType, typename Param1Type, typename Param2Type, typename ClassType>
-BaseClassType createObject(Param1Type param1, Param2Type param2)
+BaseClassType *CreateObject(Param1Type param1, Param2Type param2)
{
return new ClassType(param1, param2);
}
@@ -128,7 +129,7 @@
class ObjectFactory<BaseClassType (Param1Type, Param2Type), UniqueIdType>
{
protected:
- typedef BaseClassType (*CreateObjectFunc)(Param1Type);
+ typedef BaseClassType *(*CreateObjectFunc)(Param1Type, Param2Type);
public:
@@ -137,7 +138,7 @@
{
if (m_objectCreator.contains(uniqueId))
return false;
- m_objectCreator[uniqueId] = &createObject<BaseClassType, Param1Type, ClassType>;
+ m_objectCreator[uniqueId] = &CreateObject<BaseClassType, Param1Type, Param2Type, ClassType>;
return true;
}
@@ -146,12 +147,14 @@
return (m_objectCreator.remove(uniqueId) >= 1);
}
- BaseClassType create(UniqueIdType uniqueId, Param1Type param1, Param2Type param2)
+ BaseClassType *create(UniqueIdType uniqueId, Param1Type param1, Param2Type param2)
{
- if (!m_objectCreator.contains(uniqueId))
+ if (!m_objectCreator.contains(uniqueId)) {
return 0;
- else
- return new BaseClassType(param1, param2);
+ } else {
+ BaseClassType *tmp = (m_objectCreator[uniqueId])(param1, param2);
+ return tmp;
+ }
}
protected:
Modified: tux4kids-admin/trunk/libtux4kidsadmin/profileDir.cpp
===================================================================
--- tux4kids-admin/trunk/libtux4kidsadmin/profileDir.cpp 2009-07-17 22:10:17 UTC (rev 1227)
+++ tux4kids-admin/trunk/libtux4kidsadmin/profileDir.cpp 2009-07-18 00:07:31 UTC (rev 1228)
@@ -18,14 +18,14 @@
}
mainDir.setPath(path);
- if (!mainDir.mkdir("data")) {
+ /*if (!mainDir.mkdir("data")) {
status = ProfileDir::InitializationError;
return;
- }
+ }*/
dataDir = QDir(mainDir.absolutePath() + "/data");
- attributes = new QSettings(path + "/attributes.ini", QSettings::IniFormat);
- if (!attributes->status() != QSettings::NoError) {
+ attributes = new QSettings(mainDir.absolutePath() + "/attributes.ini", QSettings::IniFormat);
+ if (attributes->status() != QSettings::NoError) {
status = ProfileDir::InitializationError;
return;
}
Modified: tux4kids-admin/trunk/libtux4kidsadmin/profileDirFactory.h
===================================================================
--- tux4kids-admin/trunk/libtux4kidsadmin/profileDirFactory.h 2009-07-17 22:10:17 UTC (rev 1227)
+++ tux4kids-admin/trunk/libtux4kidsadmin/profileDirFactory.h 2009-07-18 00:07:31 UTC (rev 1228)
@@ -3,10 +3,12 @@
#include <QtGlobal>
#include <QString>
+#include <QDebug>
#include "profileDirFactory_p.h"
+#include "libtux4kidsadmin_global.h"
-class ProfileDirFactory
+class LIBTUX4KIDSADMIN_SHARED_EXPORT ProfileDirFactory
{
public:
ProfileDirFactory();
@@ -14,13 +16,28 @@
static ProfileDirFactory &instance();
static void destroy();
+
template<typename ClassType>
bool registerType(QString uniqueId)
{
Q_D(ProfileDirFactory);
+ qDebug() << "registering" << uniqueId << "in the factory";
return d->objectFactory.registerType<ClassType>(uniqueId);
}
+ bool unregisterType(QString uniqueId)
+ {
+ Q_D(ProfileDirFactory);
+ qDebug() << "unregistering" << uniqueId;
+ return d->objectFactory.unregisterType(uniqueId);
+ }
+
+ ProfileDir *create(QString uniqueId, QString path, QObject *parent = 0)
+ {
+ Q_D(ProfileDirFactory);
+ return d->objectFactory.create(uniqueId, path, parent);
+ }
+
protected:
ProfileDirFactoryPrivate * const d_ptr;
ProfileDirFactory(ProfileDirFactoryPrivate &dd);
Modified: tux4kids-admin/trunk/libtux4kidsadmin/profileDirFactory_p.h
===================================================================
--- tux4kids-admin/trunk/libtux4kidsadmin/profileDirFactory_p.h 2009-07-17 22:10:17 UTC (rev 1227)
+++ tux4kids-admin/trunk/libtux4kidsadmin/profileDirFactory_p.h 2009-07-18 00:07:31 UTC (rev 1228)
@@ -3,8 +3,8 @@
#include <QtGlobal>
#include "objectFactory.h"
+#include "profileDir.h"
-class ProfileDir;
class ProfileDirFactory;
class QObject;
class QString;
@@ -17,7 +17,7 @@
virtual ~ProfileDirFactoryPrivate();
ProfileDirFactory *q_ptr;
- ObjectFactory<ProfileDir (QString, QObject), QString> objectFactory;
+ ObjectFactory<ProfileDir (QString, QObject *), QString> objectFactory;
};
Modified: tux4kids-admin/trunk/libtux4kidsadmin_tuxmath/CMakeLists.txt
===================================================================
--- tux4kids-admin/trunk/libtux4kidsadmin_tuxmath/CMakeLists.txt 2009-07-17 22:10:17 UTC (rev 1227)
+++ tux4kids-admin/trunk/libtux4kidsadmin_tuxmath/CMakeLists.txt 2009-07-18 00:07:31 UTC (rev 1228)
@@ -3,7 +3,8 @@
SET(LIBTUX4KIDSADMIN_TUXMATH_SOURCES
libtux4kidsadmin_tuxmath.cpp
- profileDirTuxmath.cpp )
+ profileDirTuxmath.cpp
+ profileDirTuxmathRegister.cpp )
SET(LIBTUX4KIDSADMIN_TUXMATH_MOC_HEADERS
profileDirTuxmath.h )
Modified: tux4kids-admin/trunk/libtux4kidsadmin_tuxmath/libtux4kidsadmin_tuxmath.pro
===================================================================
--- tux4kids-admin/trunk/libtux4kidsadmin_tuxmath/libtux4kidsadmin_tuxmath.pro 2009-07-17 22:10:17 UTC (rev 1227)
+++ tux4kids-admin/trunk/libtux4kidsadmin_tuxmath/libtux4kidsadmin_tuxmath.pro 2009-07-18 00:07:31 UTC (rev 1228)
@@ -3,7 +3,8 @@
TEMPLATE = lib
DEFINES += LIBTUX4KIDSADMIN_TUXMATH_LIBRARY
SOURCES += libtux4kidsadmin_tuxmath.cpp \
- profileDirTuxmath.cpp
+ profileDirTuxmath.cpp \
+ profileDirTuxmathRegister.cpp
HEADERS += libtux4kidsadmin_tuxmath.h \
libtux4kidsadmin_tuxmath_global.h \
profileDirTuxmath.h \
Modified: tux4kids-admin/trunk/libtux4kidsadmin_tuxmath/profileDirTuxmath.cpp
===================================================================
--- tux4kids-admin/trunk/libtux4kidsadmin_tuxmath/profileDirTuxmath.cpp 2009-07-17 22:10:17 UTC (rev 1227)
+++ tux4kids-admin/trunk/libtux4kidsadmin_tuxmath/profileDirTuxmath.cpp 2009-07-18 00:07:31 UTC (rev 1228)
@@ -2,12 +2,14 @@
#include "profileDirTuxmath_p.h"
#include <QString>
+#include <QDebug>
/************** ProfileDirTuxmathPrivate ****************/
ProfileDirTuxmathPrivate::ProfileDirTuxmathPrivate(QString path)
: ProfileDirPrivate(path)
{
+ attributes->setValue("profile_type", "tuxmath");
}
ProfileDirTuxmathPrivate::~ProfileDirTuxmathPrivate()
Added: tux4kids-admin/trunk/libtux4kidsadmin_tuxmath/profileDirTuxmathRegister.cpp
===================================================================
--- tux4kids-admin/trunk/libtux4kidsadmin_tuxmath/profileDirTuxmathRegister.cpp (rev 0)
+++ tux4kids-admin/trunk/libtux4kidsadmin_tuxmath/profileDirTuxmathRegister.cpp 2009-07-18 00:07:31 UTC (rev 1228)
@@ -0,0 +1,20 @@
+#include "profileDirFactory.h"
+#include "profileDirTuxmath.h"
+
+#include <QDebug>
+
+class ProfileDirTuxmathRegister
+{
+public:
+ ProfileDirTuxmathRegister()
+ {
+ ProfileDirFactory::instance().registerType<ProfileDirTuxmath>("tuxmath");
+ }
+
+ ~ProfileDirTuxmathRegister()
+ {
+ ProfileDirFactory::instance().unregisterType("tuxmath");
+ }
+};
+
+static const ProfileDirTuxmathRegister reg;
Modified: tux4kids-admin/trunk/libtux4kidsadmin_tuxtype/CMakeLists.txt
===================================================================
--- tux4kids-admin/trunk/libtux4kidsadmin_tuxtype/CMakeLists.txt 2009-07-17 22:10:17 UTC (rev 1227)
+++ tux4kids-admin/trunk/libtux4kidsadmin_tuxtype/CMakeLists.txt 2009-07-18 00:07:31 UTC (rev 1228)
@@ -3,7 +3,8 @@
SET(LIBTUX4KIDSADMIN_TUXTYPE_SOURCES
libtux4kidsadmin_tuxtype.cpp
- profileDirTuxtype.cpp )
+ profileDirTuxtype.cpp
+ profileDirTuxtypeRegister.cpp )
SET(LIBTUX4KIDSADMIN_TUXTYPE_MOC_HEADERS
profileDirTuxtype.h )
Modified: tux4kids-admin/trunk/libtux4kidsadmin_tuxtype/libtux4kidsadmin_tuxtype.pro
===================================================================
--- tux4kids-admin/trunk/libtux4kidsadmin_tuxtype/libtux4kidsadmin_tuxtype.pro 2009-07-17 22:10:17 UTC (rev 1227)
+++ tux4kids-admin/trunk/libtux4kidsadmin_tuxtype/libtux4kidsadmin_tuxtype.pro 2009-07-18 00:07:31 UTC (rev 1228)
@@ -3,7 +3,8 @@
TEMPLATE = lib
DEFINES += LIBTUX4KIDSADMIN_TUXTYPE_LIBRARY
SOURCES += libtux4kidsadmin_tuxtype.cpp \
- profileDirTuxtype.cpp
+ profileDirTuxtype.cpp \
+ profileDirTuxtypeRegister.cpp
HEADERS += libtux4kidsadmin_tuxtype.h \
libtux4kidsadmin_tuxtype_global.h \
profileDirTuxtype.h \
Modified: tux4kids-admin/trunk/libtux4kidsadmin_tuxtype/profileDirTuxtype.cpp
===================================================================
--- tux4kids-admin/trunk/libtux4kidsadmin_tuxtype/profileDirTuxtype.cpp 2009-07-17 22:10:17 UTC (rev 1227)
+++ tux4kids-admin/trunk/libtux4kidsadmin_tuxtype/profileDirTuxtype.cpp 2009-07-18 00:07:31 UTC (rev 1228)
@@ -2,12 +2,14 @@
#include "profileDirTuxtype_p.h"
#include <QString>
+#include <QDebug>
/************** ProfileDirTuxtypePrivate ****************/
ProfileDirTuxtypePrivate::ProfileDirTuxtypePrivate(QString path)
: ProfileDirPrivate(path)
{
+ attributes->setValue("profile_type", "tuxtype");
}
ProfileDirTuxtypePrivate::~ProfileDirTuxtypePrivate()
Added: tux4kids-admin/trunk/libtux4kidsadmin_tuxtype/profileDirTuxtypeRegister.cpp
===================================================================
--- tux4kids-admin/trunk/libtux4kidsadmin_tuxtype/profileDirTuxtypeRegister.cpp (rev 0)
+++ tux4kids-admin/trunk/libtux4kidsadmin_tuxtype/profileDirTuxtypeRegister.cpp 2009-07-18 00:07:31 UTC (rev 1228)
@@ -0,0 +1,20 @@
+#include "profileDirFactory.h"
+#include "profileDirTuxtype.h"
+
+#include <QDebug>
+
+class ProfileDirTuxtypeRegister
+{
+public:
+ ProfileDirTuxtypeRegister()
+ {
+ ProfileDirFactory::instance().registerType<ProfileDirTuxtype>("tuxtype");
+ }
+
+ ~ProfileDirTuxtypeRegister()
+ {
+ ProfileDirFactory::instance().unregisterType("tuxtype");
+ }
+};
+
+static const ProfileDirTuxtypeRegister reg;
Modified: tux4kids-admin/trunk/tux4kids-admin/src/mainController.cpp
===================================================================
--- tux4kids-admin/trunk/tux4kids-admin/src/mainController.cpp 2009-07-17 22:10:17 UTC (rev 1227)
+++ tux4kids-admin/trunk/tux4kids-admin/src/mainController.cpp 2009-07-18 00:07:31 UTC (rev 1228)
@@ -4,6 +4,7 @@
#include "mainController.h"
#include "schoolData.h"
+#include "profileDirFactory.h"
MainController::MainController()
{
@@ -16,6 +17,9 @@
m_schoolData = new SchoolData(QDir::homePath() + "/school_data");
m_studentTableModel.setSchoolData(m_schoolData);
+
+ //ProfileDirFactory::instance().create("tuxmath", "/home/swistak/lala");
+ //ProfileDirFactory::instance().create("tuxtype", "/home/swistak/lala2");
}
MainController::~MainController()
More information about the Tux4kids-commits
mailing list