From: <dhu...@us...> - 2007-01-20 19:56:46
|
Revision: 215 http://svn.sourceforge.net/qcell/?rev=215&view=rev Author: dhubleizh Date: 2007-01-20 11:56:44 -0800 (Sat, 20 Jan 2007) Log Message: ----------- - new ElementalRules Modified Paths: -------------- trunk/qcell/visgui/visgui.pro Added Paths: ----------- trunk/qcell/baseheaders/ElementalRules.h trunk/qcell/basesources/ElementalRules.cpp Added: trunk/qcell/baseheaders/ElementalRules.h =================================================================== --- trunk/qcell/baseheaders/ElementalRules.h (rev 0) +++ trunk/qcell/baseheaders/ElementalRules.h 2007-01-20 19:56:44 UTC (rev 215) @@ -0,0 +1,42 @@ +/**@file ElementalRules.h + * @author czarny + * @date + * Created: sob 20 sty 2007 17:53:58 CET \n + * Last Update: sob 20 sty 2007 17:53:58 CET + * @brief A containter combining neighbours values with output + */ + +#ifndef __ELEMENTALRULES_H__ +#define __ELEMENTALRULES_H__ + +#include <QObject> +#include <QVector> +#include <QMultiHash> +#include <QPair> + +template<class Type> +class ElementalRules: public QObject +{ +protected: + int neighbours_count; + int index; + + QVector<Type> return_values; + QVector<QVector<Type> > neighbours; + // To ease later creations + typedef QPair<Type*, QVector<Type>*> 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; + +public: + ElementalRules(); + + void setNeighoursCount(const int neighbours); + inline int getNeighbourCount(); + + void addRule(QVector<Type> neighbours, Type return_value); + +}; + +#endif // __ELEMENTALRULES_H__ Added: trunk/qcell/basesources/ElementalRules.cpp =================================================================== --- trunk/qcell/basesources/ElementalRules.cpp (rev 0) +++ trunk/qcell/basesources/ElementalRules.cpp 2007-01-20 19:56:44 UTC (rev 215) @@ -0,0 +1,49 @@ +/**@file ElementalRules.cpp + * @author czarny + * @date + * Created: sob 20 sty 2007 17:57:01 CET \n + * Last Update: sob 20 sty 2007 17:57:01 CET + */ + +#include <ElementalRules.h> + +template<class Type> +ElementalRules<Type>::ElementalRules() + : QObject() +{ + index = 0; +} + +template<class Type> +void ElementalRules<Type>::addRule(QVector<Type> neighbours, Type return_value) +{ + // where do things reside + int value_index, neighbour_index; + // Is this a new rule case? + bool newRule = false; + + // search if we haven't already have this return value + // or this neighbours configuration in databse + value_index = return_values.indexOf(return_value); + this->neighbours.indexOf(neighbours); + + // if we don't have the return vale, let's add it + // and modify the value_index accordingly + if (value_index == -1) + { + return_values.append(return_value); + value_index = return_values.count() - 1; + newRule = true; + } + + // same thing with neighbours + if (neighbour_index == -1) + { + this->neighbours.append(neighbours); + neighbour_index = this->neighbours.count() - 1; + newRule = true; + } + + rules[index] = rulePair(&return_values[value_index], &this->neighbours[neighbour_index]); +} + Modified: trunk/qcell/visgui/visgui.pro =================================================================== --- trunk/qcell/visgui/visgui.pro 2007-01-20 19:37:30 UTC (rev 214) +++ trunk/qcell/visgui/visgui.pro 2007-01-20 19:56:44 UTC (rev 215) @@ -29,7 +29,8 @@ ../baseheaders/basetools.h \ ../baseheaders/view3dtools.h \ ../baseheaders/view2dtexttools.h \ - ../baseheaders/view1dtexttools.h + ../baseheaders/view1dtexttools.h \ + ../baseheaders/ElementalRules.h SOURCES = ../basesources/GenericParserPlugin.cpp \ main.cpp \ @@ -46,7 +47,8 @@ ../basesources/basetools.cpp \ ../basesources/view3dtools.cpp \ ../basesources/view2dtexttools.cpp \ - ../basesources/view1dtexttools.cpp + ../basesources/view1dtexttools.cpp \ + ../basesources/ElementalRules.cpp LIBS = -L../libs -lN -lFQT -lKI -lREAK -lLTFL -lZIFW -lZIFWP This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |