configuration/src/realfactory.cpp

00001 /***************************************************************************
00002  *   Copyright (C) 2008 by Tomassino Ferrauto                              *
00003  *   t_ferrauto@yahoo.it                                                   *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00019  ***************************************************************************/
00020 
00021 #include "realfactory.h"
00022 #include <QStringList>
00023 
00024 namespace farsa {
00025 
00026 RealFactory::RealFactory(ConfigurationParameters& configurationParameters) :
00027     m_configurationParameters(configurationParameters),
00028     m_observers(),
00029     m_createRecursionLevel(0),
00030     m_objectsConfiguredNotInitialized()
00031 {
00032 }
00033 
00034 RealFactory::~RealFactory()
00035 {
00036     // Nothing to do here
00037 }
00038 
00039 void RealFactory::addObserver(FactoryObserver* observer)
00040 {
00041     m_observers.insert(observer);
00042 }
00043 
00044 void RealFactory::addObservers(const QSet<FactoryObserver*>& observers)
00045 {
00046     m_observers.unite(observers);
00047 }
00048 
00049 const QSet<FactoryObserver*>& RealFactory::getObservers() const
00050 {
00051     return m_observers;
00052 }
00053 
00054 void RealFactory::clearObservers()
00055 {
00056     m_observers.clear();
00057 }
00058 
00059 void RealFactory::objectConfigured(ParameterSettable *object)
00060 {
00061     m_objectsConfiguredNotInitialized.append(object);
00062 }
00063 
00064 bool RealFactory::outsideCallsToCreate() const
00065 {
00066     return (m_createRecursionLevel == 0);
00067 }
00068 
00069 void RealFactory::callPostConfigureInitializationForConfiguredObjects()
00070 {
00071     for (QList<ParameterSettable*>::iterator it = m_objectsConfiguredNotInitialized.begin(); it != m_objectsConfiguredNotInitialized.end(); it++) {
00072         (*it)->postConfigureInitialization();
00073     }
00074 }
00075 
00076 bool RealFactory::orderByNumberAfterColon(const QString& s1, const QString& s2)
00077 {
00078     // If a string doesn't contain any colon, it always follows the other string; this way strings without colons are always
00079     // at the end when sorting
00080     QStringList list = s1.split(':', QString::SkipEmptyParts);
00081     if (list.size() < 2) {
00082         return false;
00083     }
00084     const double ns1 = list[1].toDouble();
00085     list = s2.split(':', QString::SkipEmptyParts);
00086     if (list.size() < 2) {
00087         return true;
00088     }
00089     const double ns2 = list[1].toDouble();
00090 
00091     return (ns1 < ns2);
00092 }
00093 
00094 } // end namespace farsa