Ignore:
Timestamp:
07/03/20 00:37:13 (4 years ago)
Author:
Maciej Komosinski
Message:

Increased SString and std::string compatibility: introduced length(), size(), and capacity(), and removed legacy methods that have std::string equivalents

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/genetics/fL/fL_general.cpp

    r857 r973  
    11// This file is a part of Framsticks SDK.  http://www.framsticks.com/
    2 // Copyright (C) 1999-2018  Maciej Komosinski and Szymon Ulatowski.
     2// Copyright (C) 1999-2020  Maciej Komosinski and Szymon Ulatowski.
    33// See LICENSE.txt for details.
    44
     
    7676{
    7777        // if position exceeds length then return false
    78         if (pos >= src.len()) return false;
     78        if (pos >= src.length()) return false;
    7979        int opencount = -1;
    8080        int i = pos;
    81         for (; i < src.len(); i++)
     81        for (; i < src.length(); i++)
    8282        {
    8383                // token cannot contain branching parenthesis
     
    169169        SString temp;
    170170        temp = token.substr(tokpos);
    171         temp = temp.substr(0, temp.len() - 1);
     171        temp = temp.substr(0, temp.length() - 1);
    172172
    173173        // if word has parameters
     
    199199                                // if string is empty, then evaluate this with 0
    200200                                // if sequence could not be evaluated, then return error
    201                                 if (seq.len() > 0)
     201                                if (seq.length() > 0)
    202202                                {
    203203                                        eval = new MathEvaluation(numparams);
     
    217217                }
    218218        }
    219         else if (word->npar == 0 && temp.len() > 0)
     219        else if (word->npar == 0 && temp.length() > 0)
    220220        {
    221221                SString message = "Too many parameters for word:  ";
     
    351351{
    352352        // if word already exist, then return error
    353         if (this->name.len() == 0)
     353        if (this->name.length() == 0)
    354354        {
    355355                logMessage("fL_Word", "processDefinition", LOG_ERROR, "Axiom name is empty");
     
    456456        switch (type)
    457457        {
    458                 case fLElementType::TERM:
    459                 {
    460                         tab = fL_word_paramtab;
    461                         obj = new fL_Word();
    462                         break;
    463                 }
    464                 case fLElementType::INFO:
    465                 {
    466                         tab = fL_builder_paramtab;
    467                         obj = this;
    468                         break;
    469                 }
    470                 case fLElementType::RULE:
    471                 {
    472                         tab = fL_rule_paramtab;
    473                         obj = new fL_Rule(begin, end);
    474                         break;
    475                 }
    476                 default:
    477                         tab = NULL;
    478                         obj = NULL;
    479                         break;
     458        case fLElementType::TERM:
     459        {
     460                tab = fL_word_paramtab;
     461                obj = new fL_Word();
     462                break;
     463        }
     464        case fLElementType::INFO:
     465        {
     466                tab = fL_builder_paramtab;
     467                obj = this;
     468                break;
     469        }
     470        case fLElementType::RULE:
     471        {
     472                tab = fL_rule_paramtab;
     473                obj = new fL_Rule(begin, end);
     474                break;
     475        }
     476        default:
     477                tab = NULL;
     478                obj = NULL;
     479                break;
    480480        }
    481481        Param par(tab);
     
    573573        while (genotype.getNextToken(pos, line, '\n'))
    574574        {
    575                 if (line.len() > 0)
     575                if (line.length() > 0)
    576576                {
    577577                        // words can be defined in the beginning of genotype
     
    851851                                {
    852852                                        SString t = par.getString(q);
    853                                         if (t.len() > 0)
     853                                        if (t.length() > 0)
    854854                                        {
    855855                                                fL_Word *attrword = NULL;
     
    957957                }
    958958                double partprop = (ppar.getDoubleById(fL_part_names[i]) * alterationcount +
    959                                 currval) / (alterationcount + 1.0);
     959                        currval) / (alterationcount + 1.0);
    960960                ppar.setDoubleById(fL_part_names[i], partprop);
    961961        }
     
    10971097                                                delete newpart;
    10981098                                                logMessage("fL_Builder", "developModel", LOG_ERROR,
    1099                                                                 "Error parsing word parameter");
     1099                                                        "Error parsing word parameter");
    11001100                                                return 1;
    11011101                                        }
     
    11241124                                                {
    11251125                                                        logMessage("fL_Builder", "developModel", LOG_ERROR,
    1126                                                                         "Error parsing word parameter");
     1126                                                                "Error parsing word parameter");
    11271127                                                        delete newjoint;
    11281128                                                        return 1;
     
    11621162                        else if (word->name == "C")
    11631163                        {
    1164                                 connsbuffer.push_back({w, currstate.currneuron});
     1164                                connsbuffer.push_back({ w, currstate.currneuron });
    11651165                        }
    11661166                        else if (word->name.startsWith("rot"))
     
    11821182                                if (word->name == "rotX")
    11831183                                {
    1184                                         rotmatrix.rotate(Pt3D(rot,0,0));
     1184                                        rotmatrix.rotate(Pt3D(rot, 0, 0));
    11851185                                }
    11861186                                else if (word->name == "rotY")
    11871187                                {
    1188                                         rotmatrix.rotate(Pt3D(0,rot,0));
     1188                                        rotmatrix.rotate(Pt3D(0, rot, 0));
    11891189                                }
    11901190                                else if (word->name == "rotZ")
    11911191                                {
    1192                                         rotmatrix.rotate(Pt3D(0,0,rot));
     1192                                        rotmatrix.rotate(Pt3D(0, 0, rot));
    11931193                                }
    11941194                                currstate.direction = rotmatrix.transform(currstate.direction);
     
    12121212        {
    12131213                if (connsbuffer[i].second == NULL ||
    1214                                 (connsbuffer[i].second->getClass()->getPreferredInputs() != -1 &&
     1214                        (connsbuffer[i].second->getClass()->getPreferredInputs() != -1 &&
    12151215                                connsbuffer[i].second->getInputCount() >=
    12161216                                connsbuffer[i].second->getClass()->getPreferredInputs()))
     
    12251225                        SString attr = par.getStringById(FL_PE_CONN_ATTR);
    12261226                        fL_Word *attractor = NULL;
    1227                         if (attr.len() > 0)
     1227                        if (attr.length() > 0)
    12281228                        {
    12291229                                createWord(attr, attractor, 0, (*connsbuffer[i].first)->begin, (*connsbuffer[i].first)->end);
     
    12361236                                {
    12371237                                        logMessage("fL_Builder", "developModel", LOG_ERROR,
    1238                                                         "Error parsing word parameter");
     1238                                                "Error parsing word parameter");
    12391239                                        delete attractor;
    12401240                                        return 1;
     
    12451245                                connsbuffer[i].second->addInput(neu, weight);
    12461246                                if (using_mapping) neu->addMapping(
    1247                                                 IRange((*connsbuffer[i].first)->begin,
    1248                                                                 (*connsbuffer[i].first)->end));
     1247                                        IRange((*connsbuffer[i].first)->begin,
     1248                                                (*connsbuffer[i].first)->end));
    12491249                        }
    12501250                        else
     
    12521252                                connsbuffer[i].second->addInput(connsbuffer[i].second, weight);
    12531253                                if (using_mapping) neu->addMapping(
    1254                                                 IRange((*connsbuffer[i].first)->begin,
    1255                                                                 (*connsbuffer[i].first)->end));
     1254                                        IRange((*connsbuffer[i].first)->begin,
     1255                                                (*connsbuffer[i].first)->end));
    12561256                        }
    12571257                        delete attractor;
     
    12861286        m->open(using_checkpoints);
    12871287        bool wordsexceeded = false;
    1288         for (; t <= time; t+= timestamp)
     1288        for (; t <= time; t += timestamp)
    12891289        {
    12901290                alterTimedProperties(t); // always alter timed properties in the beginning
     
    12931293                {
    12941294                        iterate(t);
    1295                         curriter+=1.0;
     1295                        curriter += 1.0;
    12961296                }
    12971297                if (using_checkpoints)
     
    13621362{
    13631363        int count = genotype.size();
    1364         for (fL_Rule *rul: rules)
     1364        for (fL_Rule *rul : rules)
    13651365        {
    13661366                count += rul->objsucc.size();
     
    13731373{
    13741374        for (std::vector<fL_Rule *>::iterator it = rules.begin();
    1375                         it != rules.end(); it++)
     1375                it != rules.end(); it++)
    13761376        {
    13771377                std::vector<fL_Rule *>::iterator it2 = it;
     
    13931393                                {
    13941394                                        if ((*it)->condeval->getStringifiedRPN() ==
    1395                                                         (*it2)->condeval->getStringifiedRPN())
     1395                                                (*it2)->condeval->getStringifiedRPN())
    13961396                                        {
    13971397                                                todelete = true;
Note: See TracChangeset for help on using the changeset viewer.