realfactory.cpp
1 /***************************************************************************
2  * Copyright (C) 2008 by Tomassino Ferrauto *
3  * t_ferrauto@yahoo.it *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
20 
21 #include "realfactory.h"
22 #include <QStringList>
23 
24 namespace farsa {
25 
27  m_configurationParameters(configurationParameters),
28  m_observers(),
29  m_createRecursionLevel(0),
30  m_objectsConfiguredNotInitialized()
31 {
32 }
33 
35 {
36  // Nothing to do here
37 }
38 
40 {
41  m_observers.insert(observer);
42 }
43 
44 void RealFactory::addObservers(const QSet<FactoryObserver*>& observers)
45 {
46  m_observers.unite(observers);
47 }
48 
49 const QSet<FactoryObserver*>& RealFactory::getObservers() const
50 {
51  return m_observers;
52 }
53 
55 {
56  m_observers.clear();
57 }
58 
60 {
61  m_objectsConfiguredNotInitialized.append(object);
62 }
63 
65 {
66  return (m_createRecursionLevel == 0);
67 }
68 
70 {
71  for (QList<ParameterSettable*>::iterator it = m_objectsConfiguredNotInitialized.begin(); it != m_objectsConfiguredNotInitialized.end(); it++) {
72  (*it)->postConfigureInitialization();
73  }
74 }
75 
76 bool RealFactory::orderByNumberAfterColon(const QString& s1, const QString& s2)
77 {
78  // If a string doesn't contain any colon, it always follows the other string; this way strings without colons are always
79  // at the end when sorting
80  QStringList list = s1.split(':', QString::SkipEmptyParts);
81  if (list.size() < 2) {
82  return false;
83  }
84  const double ns1 = list[1].toDouble();
85  list = s2.split(':', QString::SkipEmptyParts);
86  if (list.size() < 2) {
87  return true;
88  }
89  const double ns2 = list[1].toDouble();
90 
91  return (ns1 < ns2);
92 }
93 
94 } // end namespace farsa