From: <dhu...@us...> - 2007-01-20 21:55:07
|
Revision: 217 http://svn.sourceforge.net/qcell/?rev=217&view=rev Author: dhubleizh Date: 2007-01-20 13:55:04 -0800 (Sat, 20 Jan 2007) Log Message: ----------- - ElementalRules started Modified Paths: -------------- trunk/qcell/baseheaders/ElementalRules.h trunk/qcell/basesources/ElementalRules.cpp trunk/qcell/visgui/MainWindow.cpp trunk/qcell/visgui/MainWindow.h Modified: trunk/qcell/baseheaders/ElementalRules.h =================================================================== --- trunk/qcell/baseheaders/ElementalRules.h 2007-01-20 21:17:33 UTC (rev 216) +++ trunk/qcell/baseheaders/ElementalRules.h 2007-01-20 21:55:04 UTC (rev 217) @@ -14,20 +14,24 @@ #include <QMultiHash> #include <QPair> -template<class Type> -class ElementalRules: public QObject +class ElementalRules : public QObject { + Q_OBJECT +public slots: + void possibleRule(QVector<int> coordinates, QVector<int> neighbours, int result); protected: int neighbours_count; int index; - QVector<Type> return_values; - QVector<QVector<Type> > neighbours; + QVector<int> return_values; + QVector<QVector<int> > neighbours; // To ease later creations - typedef QPair<Type*, QVector<Type>*> rulePair; + typedef QPair<int*, QVector<int>*> rulePair; // Rule maps a rule number to a rule. // A rule is really a pair of return value and neighbours - QMultiHash<int, QPair<Type*, QVector<Type>*> > rules; + QMultiHash<int, QPair<int*, QVector<int>*> > rules; + // This hash holds coordinates, that have a certain rule + QMultiHash<int, QVector<int> > rules_mask; public: ElementalRules(); @@ -35,8 +39,9 @@ void setNeighoursCount(const int neighbours); inline int getNeighbourCount(); - void addRule(QVector<Type> neighbours, Type return_value); + void addRule(QVector<int> coodrinates, QVector<int> neighbours, int return_value); }; + #endif // __ELEMENTALRULES_H__ Modified: trunk/qcell/basesources/ElementalRules.cpp =================================================================== --- trunk/qcell/basesources/ElementalRules.cpp 2007-01-20 21:17:33 UTC (rev 216) +++ trunk/qcell/basesources/ElementalRules.cpp 2007-01-20 21:55:04 UTC (rev 217) @@ -5,20 +5,18 @@ * Last Update: sob 20 sty 2007 17:57:01 CET */ -#include <ElementalRules.h> +#include "ElementalRules.h" -template<class Type> -ElementalRules<Type>::ElementalRules() +ElementalRules::ElementalRules() : QObject() { index = 0; } -template<class Type> -void ElementalRules<Type>::addRule(QVector<Type> neighbours, Type return_value) +void ElementalRules::addRule(QVector<int> coordinates, QVector<int> neighbours, int return_value) { // where do things reside - int value_index, neighbour_index; + int value_index, neighbour_index, rule_index; // Is this a new rule case? bool newRule = false; @@ -44,6 +42,31 @@ newRule = true; } - rules[index] = rulePair(&return_values[value_index], &this->neighbours[neighbour_index]); + // If neighbours or return_value is new + if (newRule) + { + // bumb the index + rule_index = ++index; + // and insert a new rule + rules.insert(rule_index, rulePair(&return_values[value_index], &this->neighbours[neighbour_index])); + } + // If both were present + else + { + // Find indexes, take out pointers and make a new rule + rule_index = rules.key(rulePair( + &return_values[return_values.indexOf(return_value)], + &this->neighbours[this->neighbours.indexOf(neighbours)] + ) + ); + } + + // At the end we note the coordinates + rules_mask.insert(rule_index, coordinates); } +void ElementalRules::possibleRule(QVector<int> coordinates, QVector<int> neighbours, int result) +{ + addRule(coordinates, neighbours, result); +} + Modified: trunk/qcell/visgui/MainWindow.cpp =================================================================== --- trunk/qcell/visgui/MainWindow.cpp 2007-01-20 21:17:33 UTC (rev 216) +++ trunk/qcell/visgui/MainWindow.cpp 2007-01-20 21:55:04 UTC (rev 217) @@ -371,6 +371,9 @@ tempCD->setFromXmlString(&XMLString); data.append(tempCD); *(CalculationData*)&calc = *data.last(); + // Creating elemental rules accroding to DATA_TYPE + elemental_rules = new ElementalRules; + iteration=0; // visualization update Modified: trunk/qcell/visgui/MainWindow.h =================================================================== --- trunk/qcell/visgui/MainWindow.h 2007-01-20 21:17:33 UTC (rev 216) +++ trunk/qcell/visgui/MainWindow.h 2007-01-20 21:55:04 UTC (rev 217) @@ -12,6 +12,7 @@ #include "ui_MainWindow.h" #include "ui_AboutDialog.h" #include "ExperimentSetup.h" +#include "ElementalRules.h" #include <QPluginLoader> #include "GenericParserPlugin.h" #include <QFileDialog> @@ -90,6 +91,7 @@ uint msec_delay; Calculator calc; + ElementalRules* elemental_rules; QList<CalculationData*> data; LocalFunction* local_function; Neighbourhood* neighbourhood; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |