Changeset 26


Ignore:
Timestamp:
06/29/09 22:12:09 (16 years ago)
Author:
mwajcht
Message:

Added some comments to converter classes

Location:
cpp/f8-to-f1
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • cpp/f8-to-f1/conv_f8tof1.cpp

    r25 r26  
    366366        SString s = SString::valueOf(params[0]);
    367367#if CONV_DEBUG > 1
    368         cout << "@@@@@ Wartosc parametru: " << this->paramName << ": " << params[0] << endl;
     368        cout << "@@@@@ Param value: " << this->paramName << ": " << params[0] << endl;
    369369#endif
    370370        return s;
     
    414414}
    415415
    416 /**
    417  * Zwracamy puste, bo co innego mamy zrobić?
    418  */
    419416const SString Production::getF1Genotype(const vector<double> params) {
    420         return SString("");
     417        return SString(); //return empty
    421418}
    422419
     
    430427        }
    431428       
    432         //jedziemy po podprodukcjach
     429        //iterate through subproductions
    433430        for (vector<SubProduction>::iterator subProdIter = this->subproductions.begin();
    434431                 subProdIter != this->subproductions.end(); subProdIter++) {
     
    438435                SubProduction &sp = *subProdIter;
    439436                bool conditionsOK = true;
    440                 //sprawdzenie warunków dla danej podprodukcji
     437                //check conditions of subproduction
    441438                for (vector<Condition>::iterator condIter = sp.conditions.begin();
    442439                         condIter != sp.conditions.end(); condIter++) {
    443440                        if (conditionsOK == false) {
    444                                 break; //bo dalsze sprawdzanie i tak nie ma sensu
     441                                break; //because it's no use checking further
    445442                        }
    446443                        Condition &c = *condIter;
     
    479476                }
    480477                if (conditionsOK) {
    481                         //jedziemy po każdej akcji w danej podprodukcji
     478                        //iterate through each action in subproduction
    482479                        for (int i = 0; i < sp.actions.size(); i++) {
    483480#if CONV_DEBUG > 1
     
    487484                                vector<SString> strParams = sp.actions[i].params;
    488485                                vector<double> params;
    489                                 //podmieniamy nazwy parametrów na ich wartości
     486                                //replace parameter names with values
    490487                                for (vector<SString>::iterator paramIter = strParams.begin();
    491488                                         paramIter != strParams.end(); paramIter++) {
     
    527524        while (in.getNextToken(pos, line, '\n')) {
    528525#if CONV_DEBUG > 1
    529                 std::cout << "### Linia: " << line << std::endl;
     526                std::cout << "### Line: " << line << std::endl;
    530527#endif
    531528                if (line.startsWith("P") && line.indexOf('(', 0) == -1) {
     
    540537                        SString prodName = line.substr(0, lParenIndex);
    541538#if CONV_DEBUG > 1
    542                         std::cout << "###Produkcja: " << prodName << std::endl;
     539                        std::cout << "###Production: " << prodName << std::endl;
    543540#endif
    544541                        names.push_back(prodName);
     
    599596       
    600597        //cout << "convert() 1" << endl;
    601         //ustawienie zmiennych dla początkowej produkcji
     598        //set parameters for start production
    602599        Production *firstProduction = lsystem->productions[lsystem->firstProductionName];
    603600        vector<double> params;
     
    674671        Lsystem *lsys = new Lsystem();
    675672       
    676         //wczytujemy nazwy produkcji i tworzymy wstępnie dla nich obiekty
     673        //read production names and create objects for them
    677674        vector<SString> names = this->readProductionNames(in);
    678675        for (vector<SString>::iterator nameIter = names.begin(); nameIter != names.end(); nameIter++) {
     
    699696#if CONV_DEBUG > 1
    700697       
    701         cout << "@@@@@ Przeparsowane" << endl;
     698        cout << "@@@@@ Parsed" << endl;
    702699       
    703700        cout << "&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&" << endl;
     
    726723
    727724bool GenoConv_F8ToF1::parseInput(const char* src, Lsystem* lsys) {
    728         //inicjalizacja zmiennych parsera
     725        //initialize parser
    729726        int yv;
    730727        istringstream input;
     
    739736        extern YYSTYPE yylval;
    740737       
    741         //parsowanie wejścia
     738        //parse input
    742739        // on EOF yylex will return 0
    743740        while((yv = scanner.yylex()) != 0) {
  • cpp/f8-to-f1/conv_f8tof1.h

    r25 r26  
    4343};
    4444
    45 class ActionP;
    46 
     45class ActionP; //only declaration
     46
     47/// superclass of all actions, e.g. Production, PrimitiveProduction etc.
    4748class Action {
    4849public:
     50        /// action's name
    4951        SString name;
     52        /// if true action should ignore params passed to it
    5053        bool ignoreParams;
     54        /// gets string representaion of this action in f1 format
    5155        virtual const SString getF1Genotype(vector<double> params) = 0;
     56        /// gets list of actions with double parameters to each of them
     57        /// @param params parameters passed to this action
    5258        virtual const list<ActionP> getActionList(const vector<double> params) = 0;
     59        /// gets string representaion of this action in f8 format
    5360        virtual const SString getF8Representation() = 0;
    5461        virtual ~Action() {}
    5562};
    5663
     64/// this class consists of pointer to some action and a list of parameters to that action;
     65/// parameters are kept as strings
    5766class ActionStrP {
    5867public:
     
    6170};
    6271
     72/// this class consists of pointer to some action and a list of parameters to that action;
     73/// parameters are kept as doubles
    6374class ActionP {
    6475public:
     
    6778};
    6879
     80/// part of production which is used in translation only if all the conditions are met
    6981class SubProduction {
    7082public:
     83        /// list of conditions necessary to be met
    7184        vector<Condition> conditions;
     85        /// actions with params (as strings)
    7286        vector<ActionStrP> actions;
    7387};
    7488
     89/// primitive production; it's directly translated to its f1 equivalent
     90/// e.g. X, r, R etc.
    7591class PrimitiveProduction : public Action {
    7692public:
     
    84100};
    85101
     102/// param production; all param productions during translation are replaced with the current value of parameter
     103/// pointed by this production
    86104class ParamProduction : public Action {
    87105public:
     
    94112};
    95113
     114/// neuron production; it is directly translated to f1 without any change
    96115class NeuronProduction : public Action {
    97116public:
     
    104123};
    105124
    106 /**
    107  * Pozycje liczone od 1 a nie od 0!
    108  */
     125/// class which keeps all parameters of a production and enables to access them in convenient way
     126/// IMPORTANT! All indices (positions) begins with 1 (not 0)!
    109127class ParameterCollection {
    110128public:
     129        /// returns parameter's value
     130        /// @param position parameter's position (first parameter has an index 1!)
    111131        const double getValue(int position);
     132        /// returns parameter's value
     133        /// @param name parameter's name
    112134        const double getValue(SString name);
     135        /// returns parameter's name
     136        /// @param position parameter's position (first parameter has an index 1!)
    113137        const SString getParameterName(int position);
    114         const int getParameterPosition(SString name); //zwróci index liczony od 1!
     138        /// returns parameter's position (first parameter has an index 1!)
     139        /// @param name parameter's name
     140        const int getParameterPosition(SString name);
     141        /// sets parameter's value
     142        /// @param position parameter's position
     143        /// @param value parameter's new value
    115144        void setValue(int position, double value);
     145        /// sets parameter's value
     146        /// @param name parameter's name
     147        /// @param value parameter's new value
    116148        void setValue(SString name, double value);
     149        /// adds parameter
     150        /// @param name parameter's name
     151        /// @param position desired parameter's position; defualts to -1 which means it will have first available position
     152        /// @param value parameter's value; defaults to 0.0
    117153        void addParameter(SString name, int position = -1, double value = 0.0);
     154        /// returns the number of parameters kept in this class
    118155        const int size();
     156        /// removes a parameter
     157        /// @param position position of parameter to be deleted
    119158        void removeParameter(int position);
     159        /// removes a parameter
     160        /// @param name name of parameter to be deleted
    120161        void removeParameter(SString name);
     162        /// returns true if parameter with given name exists
     163        /// @param name parameter's name
    121164        bool paramExist(SString name);
    122165protected:
     
    125168};
    126169
     170/// represents a general rule in L-systems
     171/// only "calls" to Production in genotype are replaced in translation procedure
    127172class Production : public Action {
    128173public:
     174        /// parameters of this production
    129175        ParameterCollection parameters;
     176        /// list of subproductions
    130177        vector<SubProduction> subproductions;
    131178       
     
    137184};
    138185
     186/// Main class that represents a genotype in f8 format
    139187class Lsystem {
    140188public:
     189        /// number of iterations in f8->f1 translation procedure
    141190        int iterations;
     191        /// map of parameters of start production; key - parameter's name, value - parameter's value
    142192        map<string, double> startParams;
     193        /// map of productions of L-system; key - productions's name, value - pointer to production
    143194        map<string, Production*> productions;
     195        /// collection of neuron productions held in L-system
    144196        vector<NeuronProduction*> neuronProductions;
     197        /// first production's name
    145198        string firstProductionName;
    146199       
    147200        Lsystem();
    148201        ~Lsystem();
     202        /// returns a primitive production of a given name
     203        /// @param name primitive production's name
    149204        PrimitiveProduction* getPrimitiveProduction(SString name);
     205        /// returns a param production of a given name
     206        /// @param name param production's name
    150207        ParamProduction* getParamProduction(SString name);
     208        /// gets string representation of this L-system (f8 genotype)
    151209        SString toString();
     210        /// returns all actions
     211        /// @param normal if true all normal actions will be included
     212        /// @param primitives if true all primitive actions will be included
     213        /// @param params if true all param actions will be included
     214        /// @param neurons if true all neuron actions will be included
    152215        vector<Action*> getAllActions(bool normal, bool primitives, bool params, bool neurons);
    153216protected:
     
    158221};
    159222
     223/// Converter between f8 and f1 format
    160224class GenoConv_F8ToF1 : public GenoConverter {
    161225public:
     226        /// Default constructor
    162227        GenoConv_F8ToF1() {
    163228                name = "f8 to f1 converter";
     
    169234        }
    170235       
     236        /// Constructor with parameter
     237        /// @param f1LengthLimit If resulting f1 genotype is longer than f1LengthLimit, converter aborts its job
    171238        GenoConv_F8ToF1(int f1LengthLimit) {
    172239                name = "f8 to f1 converter";
     
    181248       
    182249        SString convert(SString &in, MultiMap *map);
     250       
     251        /// check syntax of given f8 genotype
     252        /// @param geno f8 genotype to be checked
    183253        bool checkSyntax(const char *geno);
     254       
     255        /// returns names of productions in a given genotype
     256        /// @param in f8 genotype
    184257        vector<SString> readProductionNames(const SString &in);
    185258        //Lsystem* createLsystem(const SString &in);
     259       
     260        /// creates Lsystem object based on input genotype
     261        /// @param f8 genotype
    186262        Lsystem* createLsystem(SString in);
    187263protected:
Note: See TracChangeset for help on using the changeset viewer.