Changeset 973 for cpp


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

Location:
cpp/frams
Files:
34 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/_demos/genooper_test.cpp

    r955 r973  
    11// This file is a part of Framsticks SDK.  http://www.framsticks.com/
    2 // Copyright (C) 1999-2015  Maciej Komosinski and Szymon Ulatowski.
     2// Copyright (C) 1999-2020  Maciej Komosinski and Szymon Ulatowski.
    33// See LICENSE.txt for details.
    44
     
    99{
    1010        printf("Genotype: %s\nFormat: %s\nValid: %s\nComment: %s\n",
    11                 g.getGenes().c_str(), g.getFormat().c_str(), g.isValid() ? "yes" : "no", g.getComment().len() == 0 ? "(empty)" : g.getComment().c_str());
     11                g.getGenes().c_str(), g.getFormat().c_str(), g.isValid() ? "yes" : "no", g.getComment().length() == 0 ? "(empty)" : g.getComment().c_str());
    1212}
    1313
  • cpp/frams/_demos/loader_test_geno.cpp

    r732 r973  
    11// This file is a part of Framsticks SDK.  http://www.framsticks.com/
    2 // Copyright (C) 1999-2015  Maciej Komosinski and Szymon Ulatowski.
     2// Copyright (C) 1999-2020  Maciej Komosinski and Szymon Ulatowski.
    33// See LICENSE.txt for details.
    44
     
    2020                        "If a genotype is indicated (by providing the optional genotype identifier), the program will output the raw genotype, suitable for Framsticks Theater's genotype viewer mode. If a genotype and a field name is given, the field value (instead of the raw genotype) is printed. If the second argument is not given, the genotype names from the file will be listed.\n"
    2121                        "Example: loader_test walking.gen \"Basic Quadruped\" | theater -g -\n"
    22                         );
     22                );
    2323                return 1;
    2424        }
     
    2929        const char* selected = (argc < 3) ? NULL : argv[2];
    3030        const char* field_name = (argc < 4) ? NULL : argv[3];
    31         int selected_index = (selected&&isdigit(selected[0])) ? atol(selected) : 0;
     31        int selected_index = (selected && isdigit(selected[0])) ? atol(selected) : 0;
    3232        // using char* constructor (passing the file name to open)
    3333        GenotypeMini *loaded;
     
    3636                // loaded into MiniGenotype object
    3737                count++;
    38                 totalsize += loaded->genotype.len();
     38                totalsize += loaded->genotype.length();
    3939                if (selected)
    4040                {
     
    6565                        return 0;
    6666                }
    67                 fprintf(stderr, "%d. %s\t(%d characters)\n", count, loaded->name.c_str(), loaded->genotype.len());
     67                fprintf(stderr, "%d. %s\t(%d characters)\n", count, loaded->name.c_str(), loaded->genotype.length());
    6868        }
    6969        // the loop repeats until loaded==NULL, which could be beacause of error
  • cpp/frams/_demos/paramtree_stdin_test.cpp

    r744 r973  
    4545        while (group_names.getNextToken(pos, line, '\n'))
    4646        {
    47                 if ((line.len() > 0) && (line[line.len() - 1] == '\r')) //support for reading \r\n files...
    48                         line = line.substr(0, line.len() - 1);
    49                 if (line.len() > 0 && line[0] != '#') //skip empty lines and #commment lines
     47                if ((line.length() > 0) && (line[line.length() - 1] == '\r')) //support for reading \r\n files...
     48                        line = line.substr(0, line.length() - 1);
     49                if (line.length() > 0 && line[0] != '#') //skip empty lines and #commment lines
    5050                        param.addGroup(line.c_str());
    5151        }
  • cpp/frams/_demos/printconvmap.cpp

    r739 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
     
    4848                return;
    4949        }
    50         len1 = gen1.len();
     50        len1 = gen1.length();
    5151        SString g1 = gen1;
    5252        stripstring(g1);
     
    7373                        y2 = len1;
    7474                }
    75                 else    {
     75                else {
    7676                        id = map.findMappingId(y);
    7777                        mr = &map.getMapping(id)->to;
     
    8080                if ((y2 - y) > left_column_padding) y2 = y + left_column_padding;
    8181                if (y2 > (y + len1)) y2 = y + len1;
    82                 printmapping(g + y, y2 - y, *mr, g2.c_str(), g2.len(), left_column_padding);
     82                printmapping(g + y, y2 - y, *mr, g2.c_str(), g2.length(), left_column_padding);
    8383                y = y2;
    8484        }
  • cpp/frams/_demos/simil_test.cpp

    r895 r973  
    11// This file is a part of Framsticks SDK.  http://www.framsticks.com/
    2 // Copyright (C) 1999-2016  Maciej Komosinski and Szymon Ulatowski.
     2// Copyright (C) 1999-2020  Maciej Komosinski and Szymon Ulatowski.
    33// See LICENSE.txt for details.
    44
     
    7878                M.m_adFactors[i] = -1.0;
    7979        }
    80        
     80
    8181        iCurrParam++;
    8282        szCurrParam = argv[iCurrParam];
    83         int measure_type = -1; 
     83        int measure_type = -1;
    8484        nResult = sscanf(szCurrParam, "%d", &measure_type);
    8585        if (nResult != 1)
     
    8888                return -1;
    8989        }
    90        
     90
    9191        if (measure_type != 0 && measure_type != 1)
    9292        {
    9393                printf("Measure type should be 0 (flexible criteria order and optimal matching) or 1 (vertex degree order and greedy matching)!\n");
    94                 return -1;             
    95         }
    96        
     94                return -1;
     95        }
     96
    9797        M.matching_method = measure_type;
    9898
     
    150150                // while a valid genotype was loaded
    151151                count++;
    152                 totalsize += loaded->genotype.len();
     152                totalsize += loaded->genotype.length();
    153153                // create a Geno object based on the MiniGenotype
    154154                Geno *pNextGenotype = new Geno(loaded->genotype);
     
    156156                {
    157157                        pvGenos.push_back(pNextGenotype);
    158                         char *szNewName = new char[loaded->name.len() + 1];
     158                        char *szNewName = new char[loaded->name.length() + 1];
    159159                        strcpy(szNewName, loaded->name.c_str());
    160160                        pvNames.push_back(szNewName);
  • cpp/frams/canvas/neurodiagram.cpp

    r838 r973  
    11// This file is a part of Framsticks SDK.  http://www.framsticks.com/
    2 // Copyright (C) 1999-2017  Maciej Komosinski and Szymon Ulatowski.
     2// Copyright (C) 1999-2020  Maciej Komosinski and Szymon Ulatowski.
    33// See LICENSE.txt for details.
    44
     
    136136                int *xywh = GetXYWH(el);
    137137                XY[0] = 0;
    138                 XY[1] = ((1 + i)*xywh[3]) / (GetInputs(el) + 1);
     138                XY[1] = ((1 + i) * xywh[3]) / (GetInputs(el) + 1);
    139139                return XY;
    140140        }
     
    230230        if (i >= countNeurons()) return;
    231231        NeuroProbe *probe = new NeuroProbe(getNS(i));
    232         Pixel s=getSize();
    233         s.x=s.y=max(probe->getSize().x,min(s.x/3,s.y/3));
     232        Pixel s = getSize();
     233        s.x = s.y = max(probe->getSize().x, min(s.x / 3, s.y / 3));
    234234        probes += (void*)probe;
    235235        add(probe);
     
    255255        addNeuroDescription(tooltip, n);
    256256        label += n->getClassName();
    257         if (n->getClassParams().len())
     257        if (n->getClassParams().length())
    258258        {
    259259                tooltip += "\n"; tooltip += n->getClassParams();
     
    319319                                */
    320320
    321         // NeuroSymbol is also responsible for drawing connection lines from its inputs to other NeuroSymbols' outputs
     321                                // NeuroSymbol is also responsible for drawing connection lines from its inputs to other NeuroSymbols' outputs
    322322        NeuroSymbol *ns2;
    323323        if (!diagram.isLive())
     
    350350                        {
    351351                                y2 = pos.y - yw / 3;
    352                                 if ((ns2->pos.y<pos.y) && (ns2->pos.y>(pos.y - ns2->size.y))) y2 -= pos.y - ns2->pos.y;
     352                                if ((ns2->pos.y < pos.y) && (ns2->pos.y > (pos.y - ns2->size.y))) y2 -= pos.y - ns2->pos.y;
    353353                        }
    354354                        // note: "diagram" uses global coordinate system, so we add "pos" or "ns2->pos" to get NeuroSymbol's global positions
     
    413413int NeuroSymbol::inputY(int i)
    414414{
    415         return (1 + i)*size.y / ((n->getInputCount()) + 1);
     415        return (1 + i) * size.y / ((n->getInputCount()) + 1);
    416416}
    417417
     
    421421                if (x < size.x / 4)
    422422                { // inputs?
    423                 if (n->getInputCount() > 0)
    424                 {
    425                         int i = (y*n->getInputCount()) / size.y;
    426                         double w;
    427                         Neuro* target = n->getInput(i, w);
    428                         if (target)
     423                        if (n->getInputCount() > 0)
    429424                        {
    430                                 SString t = "connected to #";
    431                                 t += SString::valueOf((int)target->refno);
    432                                 t += " - ";
    433                                 addNeuroDescription(t, target);
    434                                 //              if (w!=1.0)
     425                                int i = (y * n->getInputCount()) / size.y;
     426                                double w;
     427                                Neuro* target = n->getInput(i, w);
     428                                if (target)
    435429                                {
    436                                         t += ", weight=";
    437                                         t += SString::valueOf(w);
     430                                        SString t = "connected to #";
     431                                        t += SString::valueOf((int)target->refno);
     432                                        t += " - ";
     433                                        addNeuroDescription(t, target);
     434                                        //              if (w!=1.0)
     435                                        {
     436                                                t += ", weight=";
     437                                                t += SString::valueOf(w);
     438                                        }
     439                                        return t;
    438440                                }
    439                                 return t;
    440441                        }
    441                 }
    442442                }
    443443        return CanvasWindow::hint(x, y);
     
    448448NeuroProbe::NeuroProbe(NeuroSymbol* ns)
    449449        :DCanvasWindow(DCanvasWindow::Title + DCanvasWindow::Border + DCanvasWindow::Close + DCanvasWindow::Size,
    450         ns->getLabel().c_str(), &neurochart, &neurochart)
     450                ns->getLabel().c_str(), &neurochart, &neurochart)
    451451{
    452452        holdismine = 0;
     
    515515                                        while (*dr != NeuroImpl::ENDDRAWING)
    516516                                        {
    517                                                 int x = ((*(dr++))*scale) / (NeuroImpl::MAXDRAWINGXY + 1) + x0;
    518                                                 int y = ((*(dr++))*scale) / (NeuroImpl::MAXDRAWINGXY + 1) + y0;
     517                                                int x = ((*(dr++)) * scale) / (NeuroImpl::MAXDRAWINGXY + 1) + x0;
     518                                                int y = ((*(dr++)) * scale) / (NeuroImpl::MAXDRAWINGXY + 1) + y0;
    519519                                                if (first) { moveTo(x, y); first = 0; }
    520520                                                else lineTo(x, y);
     
    577577        {
    578578                double st = neurochart.unmapData(unmapClientY(y));
    579                 if (st<-1.0) st = -1.0; else if (st>1.0) st = 1.0;
     579                if (st < -1.0) st = -1.0; else if (st > 1.0) st = 1.0;
    580580                if (chsel == 0)
    581581                        link->n->state = st;
     
    602602                int sy = size.y;
    603603                if (chsel >= 0) sy -= textHeight();
    604                 return ((y<sy) && (y>(sy - textHeight())));
     604                return ((y < sy) && (y > (sy - textHeight())));
    605605        }
    606606        return 0;
     
    635635                {
    636636                        link->n->flags ^= Neuro::HoldState;
    637                         holdismine = ((link->n->flags&Neuro::HoldState) != 0);
     637                        holdismine = ((link->n->flags & Neuro::HoldState) != 0);
    638638                        requestPaint();
    639639                        return LeftButton;
     
    645645SString NeuroProbe::hint(int x, int y)
    646646{
    647         if ((chsel >= 0) && (x<size.x - 16) && (y>size.y - 16))
    648                 return SString((link->n->flags&Neuro::HoldState) ? "Click to release" : "Click to hold");
     647        if ((chsel >= 0) && (x < size.x - 16) && (y > size.y - 16))
     648                return SString((link->n->flags & Neuro::HoldState) ? "Click to release" : "Click to hold");
    649649        else if (insideChSelector(x, y))
    650650                return SString::sprintf("channel %d of %d (click and drag to switch channels)", chsel, chnum);
  • cpp/frams/genetics/f4/f4_general.cpp

    r955 r973  
    11// This file is a part of Framsticks SDK.  http://www.framsticks.com/
    2 // Copyright (C) 1999-2019  Maciej Komosinski and Szymon Ulatowski.
     2// Copyright (C) 1999-2020  Maciej Komosinski and Szymon Ulatowski.
    33// See LICENSE.txt for details.
    44
     
    12931293        if (2 == childCount())
    12941294                if (0 == out[0]) out += ">"; else
    1295                         if ('>' != out[out.len() - 1]) out += ">";
     1295                        if ('>' != out[out.length() - 1]) out += ">";
    12961296        if (NULL != child2)    child2->sprint(out);
    12971297        // make sure last char is a '>'
    12981298        if (0 == out[0]) out += ">"; else
    1299                 if ('>' != out[out.len() - 1]) out += ">";
     1299                if ('>' != out[out.length() - 1]) out += ">";
    13001300}
    13011301
     
    13101310
    13111311        // very last '>' can be omitted
    1312         len = out.len();
     1312        len = out.length();
    13131313        if (len > 1)
    13141314                if ('>' == out[len - 1]) { (out.directWrite())[len - 1] = 0; out.endWrite(); };
  • cpp/frams/genetics/f9/f9_conv.cpp

    r779 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
     
    3232        m.open(using_checkpoints);
    3333        int recently_added = addSegment(m, 0, vertices, current, 0xDead);
    34         for (int i = 0; i < in.len(); i++)
     34        for (int i = 0; i < in.length(); i++)
    3535        {
    3636                char command = in[i];
     
    119119        double d1 = ind - indpre;
    120120        double d2 = indpost - ind;
    121         double v = indpre == indpost ? v1 : d2*v1 + d1*v2; //d1+d2==1
     121        double v = indpre == indpost ? v1 : d2 * v1 + d1 * v2; //d1+d2==1
    122122        return v;
    123123}
     
    136136                Joint *j = m.getJoint(i);
    137137                double x = joints_count < 2 ? 0 : (double)i / (joints_count - 1); //0..1, postion in the rainbow
    138                 double ind = x*maxind;
     138                double ind = x * maxind;
    139139                j->vcolor.x = mix(r, maxind, ind);
    140140                j->vcolor.y = mix(g, maxind, ind);
     
    153153                        averagecolor += j->vcolor;
    154154                p->vcolor = averagecolor / count;
    155                 if (count>5) count = 5; //avoid too fat...
     155                if (count > 5) count = 5; //avoid too fat...
    156156                p->vsize = 0.3 + count / 15.0; //the more Joints is attached to a Part, the fatter it is
    157157        }
     
    169169                        ((3 * i + 5) % 10) - 4.5,
    170170                        ((7 * i + 2) % 10) - 4.5
    171                         ); //-4.5 .. 4.5 in each axis
     171                ); //-4.5 .. 4.5 in each axis
    172172                p->p += noise / 1000;
    173173        }
  • cpp/frams/genetics/fB/fB_conv.cpp

    r954 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
     
    8080                int endoffset = 0;
    8181                if (gene.indexOf("zz", 0) != -1) endoffset = 2;
    82                 if (gene.len() - endoffset < 3)
     82                if (gene.length() - endoffset < 3)
    8383                {
    8484                        fH_StickHandle *handle = new fH_StickHandle(dims, start, end);
     
    124124                if (gene.indexOf("zz", 0) != -1) endoffset = 2;
    125125                int nclassdefcount = 1;
    126                 while (z < gene.len() - endoffset)
     126                while (z < gene.length() - endoffset)
    127127                {
    128128                        if (processNextLetter(creature, handle, par, gene, propindex, z, ranges, nclassdefcount) == -1)
     
    185185                        }
    186186                        nextid++;
    187                 }
    188                 while (genotype[nextid] == '"');
     187                } while (genotype[nextid] == '"');
    189188                i = nextid;
    190189        }
  • cpp/frams/genetics/fB/fB_general.h

    r802 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
     
    3535                do {
    3636                        count++;
    37                         if (start < genotype.len())
     37                        if (start < genotype.length())
    3838                                result = getNextGene(start, genotype, tmp, start);
    3939                        else
     
    5252                do {
    5353                        count++;
    54                         if (start < geno.len())
     54                        if (start < geno.length())
    5555                                getNextGene(start, geno, tmp, start);
    5656                        else
     
    8989                } while (quotecount % 2 != 0 && end != -1);
    9090
    91                 if (end == -1) end = genotype.len();
     91                if (end == -1) end = genotype.length();
    9292                else end += 2;
    9393                start -= 1;
     
    124124                } while (quotecount % 2 != 0 && end != -1);
    125125
    126                 if (end == -1) end = genotype.len();
     126                if (end == -1) end = genotype.length();
    127127                else end += 2;
    128128                start -= 1;
  • cpp/frams/genetics/fB/fB_oper.cpp

    r961 r973  
    4747                int endoffset = 0;
    4848                if (gene.indexOf("zz", 0) != -1) endoffset = 2;
    49                 if (gene.len() - endoffset < 3)
     49                if (gene.length() - endoffset < 3)
    5050                {
    5151                        return true; // genes with length < 3 are always sticks
     
    8383        }
    8484        // check if rest of characters are lowercase
    85         for (int i = genstart; i < genotype.len(); i++)
     85        for (int i = genstart; i < genotype.length(); i++)
    8686        {
    8787                if (!islower(genotype[i]))
     
    144144                fix = true;
    145145        }
    146         for (int i = pos; i < genotype.len(); i++)
     146        for (int i = pos; i < genotype.length(); i++)
    147147        {
    148148                // if character is not alphabetic - error
     
    208208        std::list<SString> res;
    209209        int i = 0;
    210         while (i < genotype.len())
     210        while (i < genotype.length())
    211211        {
    212212                // if character is not alphabetic - error
     
    252252                std::advance(it, rndid);
    253253                SString t = (*it);
    254                 if ((*it).len() == 1)
     254                if ((*it).length() == 1)
    255255                {
    256256                        if (rndUint(2) == 0)
     
    264264                                else (*it).directWrite()[0] = (*it)[0] + 1;
    265265                        }
    266                         chg = 1.0 / line.len();
     266                        chg = 1.0 / line.length();
    267267                }
    268268                else
     
    270270                        // first method needs to extract quotes
    271271                        SString def = (*it);
    272                         def = def.substr(1, def.len() - 2);
     272                        def = def.substr(1, def.length() - 2);
    273273                        Geno_fH::mutateNeuronProperties(def);
    274274                        SString res = "\"";
     
    276276                        res += "\"";
    277277                        (*it) = res;
    278                         chg = (double)def.len() / line.len();
     278                        chg = (double)def.length() / line.length();
    279279                }
    280280                line = detokenizeSequence(&tokenized);
     
    296296                        res += "\"";
    297297                        tokenized.insert(it, res);
    298                         chg = (double)classdef.len() / line.len();
     298                        chg = (double)classdef.length() / line.length();
    299299                        line = detokenizeSequence(&tokenized);
    300300                        break;
     
    304304        case FB_INSERTION:
    305305        {
    306                 chg = 1.0 / line.len();
     306                chg = 1.0 / line.length();
    307307                std::list<SString> tokenized = tokenizeSequence(line);
    308308                int rndid = rndUint(tokenized.size()); // select random insertion point
     
    317317        case FB_DELETION:
    318318        {
    319                 chg = 1.0 / line.len();
     319                chg = 1.0 / line.length();
    320320                std::list<SString> tokenized = tokenizeSequence(line);
    321321                std::list<SString>::iterator it = tokenized.begin();
     
    332332                SString gene = fB_GenoHelpers::getGene(rndgene, line, start, end);
    333333                if (gene.indexOf("zz", 0) == -1) gene += "zz";
    334                 chg = (float)gene.len() / line.len();
     334                chg = (float)gene.length() / line.length();
    335335                line = gene + line;
    336336                break;
     
    364364                //                      line.substr(cuts[1], cuts[2] - cuts[1]) + first + line.substr(cuts[3]);
    365365                line = detokenizeSequence(&res);
    366                 chg = (float)(cuts[3] - cuts[2] + cuts[1] - cuts[0]) / line.len();
     366                chg = (float)(cuts[3] - cuts[2] + cuts[1] - cuts[0]) / line.length();
    367367                break;
    368368        }
     
    412412                // add this gene to the beginning of the second parent genotype
    413413                child2 = gene + parent2;
    414                 chg2 = (float)parent2.len() / (float)child2.len();
     414                chg2 = (float)parent2.length() / (float)child2.length();
    415415                // do the same for second parent
    416416                choice = rndUint(fB_GenoHelpers::geneCount(parent2));
    417417                gene = fB_GenoHelpers::getGene(choice, parent2, start, end);
    418418                child1 = gene + parent1;
    419                 chg1 = (float)parent1.len() / (float)child1.len();
     419                chg1 = (float)parent1.length() / (float)child1.length();
    420420                break;
    421421        }
     
    523523        free(g1);
    524524        free(g2);
    525         if (child1.len() > 0 && child2.len() == 0)
     525        if (child1.length() > 0 && child2.length() == 0)
    526526        {
    527527                child1 = strdims + "\n" + child1;
     
    529529                g2 = strdup("");
    530530        }
    531         else if (child2.len() > 0 && child1.len() == 0)
     531        else if (child2.length() > 0 && child1.length() == 0)
    532532        {
    533533                child2 = strdims + "\n" + child2;
  • cpp/frams/genetics/fF/fF_genotype.h

    r841 r973  
    11// This file is a part of Framsticks SDK.  http://www.framsticks.com/
    2 // Copyright (C) 1999-2017  Maciej Komosinski and Szymon Ulatowski.
     2// Copyright (C) 1999-2020  Maciej Komosinski and Szymon Ulatowski.
    33// See LICENSE.txt for details.
    44
     
    3636                SString s = serialized;
    3737                ParamInterface::LoadOptions opts;
    38                 return ((param.load(ParamInterface::FormatSingleLine, s, &opts) == param.getPropCount()) && (opts.offset == s.len()));
     38                return ((param.load(ParamInterface::FormatSingleLine, s, &opts) == param.getPropCount()) && (opts.offset == s.length()));
    3939        }
    4040
  • cpp/frams/genetics/fH/fH_general.cpp

    r966 r973  
    214214        while (genotype.getNextToken(pos, line, '\n'))
    215215        {
    216                 if (line.len() > 0)
     216                if (line.length() > 0)
    217217                {
    218218                        int res = processLine(line, linenumber, lastpos, pos - 1);
  • 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;
  • cpp/frams/genetics/fL/fL_oper.cpp

    r935 r973  
    285285        switch (method)
    286286        {
    287                 case FL_CHG_ITER:
    288                 {
    289                         if (rndUint(2) == 0)
    290                         {
    291                                 creature->time = creature->time + iterchangestep <= ExtValue::getDouble(FL_MAXITER) ?
    292                                                 creature->time + iterchangestep : creature->time - iterchangestep;
    293                         }
    294                         else
    295                         {
    296                                 creature->time = creature->time - iterchangestep >= 0 ?
    297                                                 creature->time - iterchangestep : creature->time + iterchangestep;
    298                         }
     287        case FL_CHG_ITER:
     288        {
     289                if (rndUint(2) == 0)
     290                {
     291                        creature->time = creature->time + iterchangestep <= ExtValue::getDouble(FL_MAXITER) ?
     292                                creature->time + iterchangestep : creature->time - iterchangestep;
     293                }
     294                else
     295                {
     296                        creature->time = creature->time - iterchangestep >= 0 ?
     297                                creature->time - iterchangestep : creature->time + iterchangestep;
     298                }
     299                break;
     300        }
     301        case FL_CHG_COND:
     302        {
     303                if (creature->rules.size() > 0)
     304                {
     305                        int ruleid = rndUint(creature->rules.size());
     306                        if (!creature->rules[ruleid]->condeval)
     307                        {
     308                                creature->rules[ruleid]->condeval = new MathEvaluation(creature->rules[ruleid]->objpred->npar);
     309                        }
     310                        creature->rules[ruleid]->condeval->mutateConditional();
    299311                        break;
    300312                }
    301                 case FL_CHG_COND:
    302                 {
    303                         if (creature->rules.size() > 0)
    304                         {
    305                                 int ruleid = rndUint(creature->rules.size());
    306                                 if (!creature->rules[ruleid]->condeval)
    307                                 {
    308                                         creature->rules[ruleid]->condeval = new MathEvaluation(creature->rules[ruleid]->objpred->npar);
    309                                 }
    310                                 creature->rules[ruleid]->condeval->mutateConditional();
    311                                 break;
    312                         }
    313                         // if there are no rules - create one
    314                 }
    315                 [[fallthrough]];
    316                 case FL_ADD_RULE:
    317                 {
    318                         std::unordered_map<std::string, fL_Word *>::iterator pred = creature->words.begin();
    319                         std::vector<fL_Word *> wordswithnorules;
    320                         for (; pred != creature->words.end(); pred++)
    321                         {
    322                                 if (!pred->second->builtin)
    323                                 {
    324                                         bool norules = true;
    325                                         for (fL_Rule * r : creature->rules)
    326                                         {
    327                                                 if (pred->second->name == r->objpred->name &&
    328                                                                 pred->second->npar == r->objpred->npar)
    329                                                 {
    330                                                         norules = false;
    331                                                         break;
    332                                                 }
    333                                         }
    334                                         if (norules)
    335                                         {
    336                                                 wordswithnorules.push_back(pred->second);
    337                                         }
    338                                 }
    339                         }
    340                         if (wordswithnorules.size() > 0)
    341                         {
    342                                 int predid = rndUint(wordswithnorules.size());
    343                                 fL_Rule *newrule = new fL_Rule(0,0);
    344                                 fL_Word *pred = new fL_Word();
    345                                 *pred = *wordswithnorules[predid];
    346                                 newrule->objpred = pred;
    347                                 fL_Word *initdef = randomWordDefinition(creature, roulette(addtypes, FL_ADD_COUNT - 1)); // -1 to avoid branching
    348                                 addWord(&newrule->objsucc, initdef, newrule->objsucc.begin());
    349                                 creature->rules.push_back(newrule);
    350                                 break;
    351                         }
    352                         else if (creature->rules.size() > 0)
    353                         {
    354                                 int ruleid = rndUint(creature->rules.size());
    355                                 fL_Rule *newrule = new fL_Rule(0, 0);
    356                                 fL_Word *pred = new fL_Word();
    357                                 *pred = *creature->rules[ruleid]->objpred;
    358                                 newrule->objpred = pred;
    359                                 if (creature->rules[ruleid]->condeval)
    360                                 {
    361                                         std::string formula = "";
    362                                         creature->rules[ruleid]->condeval->RPNToInfix(formula);
    363                                         if (formula.find("1.0-(") != 0)
    364                                         {
    365                                                 std::string res = "1.0-(";
    366                                                 res += formula;
    367                                                 res += ")";
    368                                                 newrule->condeval = new MathEvaluation(pred->npar);
    369                                                 newrule->condeval->convertString(res);
    370                                         }
    371                                         else
    372                                         {
    373                                                 newrule->condeval = new MathEvaluation(pred->npar);
    374                                                 newrule->condeval->mutateConditional();
    375                                         }
     313                // if there are no rules - create one
     314        }
     315        [[fallthrough]];
     316        case FL_ADD_RULE:
     317        {
     318                std::unordered_map<std::string, fL_Word *>::iterator pred = creature->words.begin();
     319                std::vector<fL_Word *> wordswithnorules;
     320                for (; pred != creature->words.end(); pred++)
     321                {
     322                        if (!pred->second->builtin)
     323                        {
     324                                bool norules = true;
     325                                for (fL_Rule * r : creature->rules)
     326                                {
     327                                        if (pred->second->name == r->objpred->name &&
     328                                                pred->second->npar == r->objpred->npar)
     329                                        {
     330                                                norules = false;
     331                                                break;
     332                                        }
     333                                }
     334                                if (norules)
     335                                {
     336                                        wordswithnorules.push_back(pred->second);
     337                                }
     338                        }
     339                }
     340                if (wordswithnorules.size() > 0)
     341                {
     342                        int predid = rndUint(wordswithnorules.size());
     343                        fL_Rule *newrule = new fL_Rule(0, 0);
     344                        fL_Word *pred = new fL_Word();
     345                        *pred = *wordswithnorules[predid];
     346                        newrule->objpred = pred;
     347                        fL_Word *initdef = randomWordDefinition(creature, roulette(addtypes, FL_ADD_COUNT - 1)); // -1 to avoid branching
     348                        addWord(&newrule->objsucc, initdef, newrule->objsucc.begin());
     349                        creature->rules.push_back(newrule);
     350                        break;
     351                }
     352                else if (creature->rules.size() > 0)
     353                {
     354                        int ruleid = rndUint(creature->rules.size());
     355                        fL_Rule *newrule = new fL_Rule(0, 0);
     356                        fL_Word *pred = new fL_Word();
     357                        *pred = *creature->rules[ruleid]->objpred;
     358                        newrule->objpred = pred;
     359                        if (creature->rules[ruleid]->condeval)
     360                        {
     361                                std::string formula = "";
     362                                creature->rules[ruleid]->condeval->RPNToInfix(formula);
     363                                if (formula.find("1.0-(") != 0)
     364                                {
     365                                        std::string res = "1.0-(";
     366                                        res += formula;
     367                                        res += ")";
     368                                        newrule->condeval = new MathEvaluation(pred->npar);
     369                                        newrule->condeval->convertString(res);
    376370                                }
    377371                                else
     
    380374                                        newrule->condeval->mutateConditional();
    381375                                }
    382                                 fL_Word *worddef = randomWordDefinition(creature, roulette(addtypes, FL_ADD_COUNT - 1));
    383                                 addWord(&newrule->objsucc, worddef, newrule->objsucc.begin());
    384                                 creature->rules.push_back(newrule);
    385                                 break;
    386                         }
    387                         // if there are no words, from which rules can be formed, then add one
    388                 }
    389                 [[fallthrough]];
    390                 case FL_ADD_WDEF:
    391                 {
    392                         if (creature->countDefinedWords() <= maxdefinedwords)
    393                         {
    394                                 int npar = rndUint(ExtValue::getInt(FL_MAXPARAMS, false));
    395                                 for (int i = 0; i < maxdefinedwords; i++)
    396                                 {
    397                                         std::string name = "w";
    398                                         name += std::to_string(i);
    399                                         if (creature->words.find(name) == creature->words.end())
    400                                         {
    401                                                 fL_Word *word = new fL_Word(false, 0, 0);
    402                                                 word->npar = npar;
    403                                                 word->name = name.c_str();
    404                                                 word->processDefinition(creature);
    405                                                 break;
    406                                         }
    407                                 }
    408                                 break;
    409                         }
    410                         //no break at the end of case - if there is too many words, then
    411                         // deletion should be performed
    412                 }
    413                 [[fallthrough]];
    414                 case FL_DEL_WORD:
    415                 {
     376                        }
     377                        else
     378                        {
     379                                newrule->condeval = new MathEvaluation(pred->npar);
     380                                newrule->condeval->mutateConditional();
     381                        }
     382                        fL_Word *worddef = randomWordDefinition(creature, roulette(addtypes, FL_ADD_COUNT - 1));
     383                        addWord(&newrule->objsucc, worddef, newrule->objsucc.begin());
     384                        creature->rules.push_back(newrule);
     385                        break;
     386                }
     387                // if there are no words, from which rules can be formed, then add one
     388        }
     389        [[fallthrough]];
     390        case FL_ADD_WDEF:
     391        {
     392                if (creature->countDefinedWords() <= maxdefinedwords)
     393                {
     394                        int npar = rndUint(ExtValue::getInt(FL_MAXPARAMS, false));
     395                        for (int i = 0; i < maxdefinedwords; i++)
     396                        {
     397                                std::string name = "w";
     398                                name += std::to_string(i);
     399                                if (creature->words.find(name) == creature->words.end())
     400                                {
     401                                        fL_Word *word = new fL_Word(false, 0, 0);
     402                                        word->npar = npar;
     403                                        word->name = name.c_str();
     404                                        word->processDefinition(creature);
     405                                        break;
     406                                }
     407                        }
     408                        break;
     409                }
     410                //no break at the end of case - if there is too many words, then
     411                // deletion should be performed
     412        }
     413        [[fallthrough]];
     414        case FL_DEL_WORD:
     415        {
     416                int numpars = 0;
     417                int ruleid = 0;
     418                std::list<fL_Word *> *list = selectRandomSequence(creature, numpars, ruleid);
     419                if (ruleid == -1 && creature->countSticksInSequence(list) == 1)
     420                {
     421                        if (list->size() > 1)
     422                        {
     423                                int rndid = rndUint(list->size() - 1);
     424                                int j = 0;
     425                                std::list<fL_Word *>::iterator it = list->begin();
     426                                if ((*it)->name == "S")
     427                                {
     428                                        it++;
     429                                }
     430                                while (it != list->end() && j < rndid && ((*it)->name == "S"))
     431                                {
     432                                        if ((*it)->name != "S")
     433                                        {
     434                                                j++;
     435                                        }
     436                                        it++;
     437                                }
     438                                if (it != list->end())
     439                                {
     440                                        if ((*it)->type == fLElementType::BRANCH)
     441                                        {
     442                                                deleteBranch(list, it);
     443                                        }
     444                                        else
     445                                        {
     446                                                delete (*it);
     447                                                list->erase(it);
     448                                        }
     449                                        break;
     450                                }
     451                                // else add word
     452                        }
     453                        // else add word
     454                }
     455                else
     456                {
     457                        int rndid = rndUint(list->size());
     458                        std::list<fL_Word *>::iterator it = list->begin();
     459                        std::advance(it, rndid);
     460                        if ((*it)->type == fLElementType::BRANCH)
     461                        {
     462                                deleteBranch(list, it);
     463                        }
     464                        else
     465                        {
     466                                delete (*it);
     467                                list->erase(it);
     468                        }
     469                        if (ruleid > -1 && creature->rules[ruleid]->objsucc.size() == 0)
     470                        {
     471                                delete creature->rules[ruleid];
     472                                creature->rules.erase(creature->rules.begin() + ruleid);
     473                        }
     474                        break;
     475                }
     476                // if no words available, then add word
     477        }
     478        [[fallthrough]];
     479        case FL_ADD_WORD:
     480        {
     481                int numpars = 0;
     482                int tmp = 0;
     483                std::list<fL_Word *> *list = selectRandomSequence(creature, numpars, tmp);
     484                int rndid = rndUint(list->size());
     485                std::list<fL_Word *>::iterator it = list->begin();
     486                std::advance(it, rndid);
     487                int meth = roulette(addtypes, FL_ADD_COUNT);
     488                if (tmp == -1)
     489                { // if sequence is axiom and it does not have non-builtin words
     490                        bool hasdefined = false;
     491                        for (std::list<fL_Word *>::iterator elem = list->begin(); elem != list->end(); elem++)
     492                        {
     493                                if (!(*elem)->builtin)
     494                                {
     495                                        hasdefined = true;
     496                                        break;
     497                                }
     498                        }
     499                        if (!hasdefined)
     500                        {
     501                                meth = FL_ADD_OTHER;
     502                        }
     503
     504                }
     505                if (meth != FL_ADD_BRANCH)
     506                {
     507                        fL_Word *worddef = randomWordDefinition(creature, meth);
     508                        addWord(list, worddef, it);
     509                }
     510                else
     511                {
     512                        fL_Branch *start = new fL_Branch(fL_Branch::BranchType::OPEN, 0, 0);
     513                        list->insert(it, start);
     514                        int rottype = rndUint(2);
     515                        switch (rottype)
     516                        {
     517                        case 0:
     518                                addWord(list, creature->words["rotY"], it);
     519                        case 1:
     520                                addWord(list, creature->words["rotZ"], it);
     521                        }
     522                        addWord(list, creature->words["S"], it);
     523                        fL_Branch *end = new fL_Branch(fL_Branch::BranchType::CLOSE, 0, 0);
     524                        list->insert(it, end);
     525                }
     526                break;
     527        }
     528        case FL_CHG_WORD:
     529        {
     530                int numpars = 0;
     531                int tmp = 0;
     532                std::list<fL_Word *> *list = selectRandomSequence(creature, numpars, tmp);
     533                int rndid = rndUint(list->size());
     534                std::list<fL_Word *>::iterator selectedword = list->begin();
     535                std::advance(selectedword, rndid);
     536                if ((*selectedword)->type == fLElementType::BRANCH)
     537                {
     538                        break;
     539                }
     540                int chgtype = roulette(chgoperations, FL_CHG_COUNT);
     541                if (creature->countSticksInSequence(list) == 1 && tmp == -1) // if sequence is axiom
     542                {
     543                        fL_Word *worddef = randomWordDefinition(creature, roulette(addtypes, FL_ADD_COUNT - 1));
     544
    416545                        int numpars = 0;
    417                         int ruleid = 0;
    418                         std::list<fL_Word *> *list = selectRandomSequence(creature, numpars, ruleid);
    419                         if (ruleid == -1 && creature->countSticksInSequence(list) == 1)
    420                         {
    421                                 if (list->size() > 1)
    422                                 {
    423                                         int rndid = rndUint(list->size() - 1);
    424                                         int j = 0;
    425                                         std::list<fL_Word *>::iterator it = list->begin();
    426                                         if ((*it)->name == "S")
    427                                         {
    428                                                 it++;
    429                                         }
    430                                         while (it != list->end() && j < rndid && ((*it)->name == "S"))
    431                                         {
    432                                                 if ((*it)->name != "S")
    433                                                 {
    434                                                         j++;
    435                                                 }
    436                                                 it++;
    437                                         }
    438                                         if (it != list->end())
    439                                         {
    440                                                 if ((*it)->type == fLElementType::BRANCH)
    441                                                 {
    442                                                         deleteBranch(list, it);
    443                                                 }
    444                                                 else
    445                                                 {
    446                                                         delete (*it);
    447                                                         list->erase(it);
    448                                                 }
    449                                                 break;
    450                                         }
    451                                         // else add word
    452                                 }
    453                                 // else add word
    454                         }
    455                         else
    456                         {
    457                                 int rndid = rndUint(list->size());
    458                                 std::list<fL_Word *>::iterator it = list->begin();
    459                                 std::advance(it, rndid);
    460                                 if ((*it)->type == fLElementType::BRANCH)
    461                                 {
    462                                         deleteBranch(list, it);
    463                                 }
    464                                 else
    465                                 {
    466                                         delete (*it);
    467                                         list->erase(it);
    468                                 }
    469                                 if (ruleid > -1 && creature->rules[ruleid]->objsucc.size() == 0)
    470                                 {
    471                                         delete creature->rules[ruleid];
    472                                         creature->rules.erase(creature->rules.begin() + ruleid);
    473                                 }
    474                                 break;
    475                         }
    476                         // if no words available, then add word
    477                 }
    478                 [[fallthrough]];
    479                 case FL_ADD_WORD:
    480                 {
    481                         int numpars = 0;
    482                         int tmp = 0;
    483546                        std::list<fL_Word *> *list = selectRandomSequence(creature, numpars, tmp);
    484547                        int rndid = rndUint(list->size());
    485548                        std::list<fL_Word *>::iterator it = list->begin();
    486549                        std::advance(it, rndid);
    487                         int meth = roulette(addtypes, FL_ADD_COUNT);
    488                         if (tmp == -1)
    489                         { // if sequence is axiom and it does not have non-builtin words
    490                                 bool hasdefined = false;
    491                                 for (std::list<fL_Word *>::iterator elem = list->begin(); elem != list->end(); elem++)
    492                                 {
    493                                         if (!(*elem)->builtin)
    494                                         {
    495                                                 hasdefined = true;
    496                                                 break;
    497                                         }
    498                                 }
    499                                 if (!hasdefined)
    500                                 {
    501                                         meth = FL_ADD_OTHER;
    502                                 }
    503 
    504                         }
    505                         if (meth != FL_ADD_BRANCH)
    506                         {
    507                                 fL_Word *worddef = randomWordDefinition(creature, meth);
    508                                 addWord(list, worddef, it);
     550
     551                        addWord(list, worddef, it);
     552
     553                        break;
     554                }
     555                else if (chgtype == FL_CHG_WORD_NAME)
     556                {
     557                        if ((*selectedword)->builtin)
     558                        {
     559                                delete (*selectedword);
     560                                selectedword = list->erase(selectedword);
     561                                fL_Word *worddef = randomWordDefinition(creature, roulette(addtypes, FL_ADD_COUNT - 1));
     562                                addWord(list, worddef, selectedword);
    509563                        }
    510564                        else
    511565                        {
    512                                 fL_Branch *start = new fL_Branch(fL_Branch::BranchType::OPEN, 0, 0);
    513                                 list->insert(it, start);
    514                                 int rottype = rndUint(2);
    515                                 switch (rottype)
    516                                 {
    517                                 case 0:
    518                                         addWord(list, creature->words["rotY"], it);
    519                                 case 1:
    520                                         addWord(list, creature->words["rotZ"], it);
    521                                 }
    522                                 addWord(list, creature->words["S"], it);
    523                                 fL_Branch *end = new fL_Branch(fL_Branch::BranchType::CLOSE, 0, 0);
    524                                 list->insert(it, end);
    525                         }
    526                         break;
    527                 }
    528                 case FL_CHG_WORD:
    529                 {
    530                         int numpars = 0;
    531                         int tmp = 0;
    532                         std::list<fL_Word *> *list = selectRandomSequence(creature, numpars, tmp);
    533                         int rndid = rndUint(list->size());
    534                         std::list<fL_Word *>::iterator selectedword = list->begin();
    535                         std::advance(selectedword, rndid);
    536                         if ((*selectedword)->type == fLElementType::BRANCH)
    537                         {
    538                                 break;
    539                         }
    540                         int chgtype = roulette(chgoperations, FL_CHG_COUNT);
    541                         if (creature->countSticksInSequence(list) == 1 && tmp == -1) // if sequence is axiom
    542                         {
    543                                 fL_Word *worddef = randomWordDefinition(creature, roulette(addtypes, FL_ADD_COUNT - 1));
    544 
    545                                 int numpars = 0;
    546                                 std::list<fL_Word *> *list = selectRandomSequence(creature, numpars, tmp);
    547                                 int rndid = rndUint(list->size());
    548                                 std::list<fL_Word *>::iterator it = list->begin();
    549                                 std::advance(it, rndid);
    550 
    551                                 addWord(list, worddef, it);
    552 
    553                                 break;
    554                         }
    555                         else if (chgtype == FL_CHG_WORD_NAME)
    556                         {
    557                                 if ((*selectedword)->builtin)
     566                                std::vector<fL_Word *> available;
     567                                for (std::unordered_map<std::string, fL_Word *>::iterator wit = creature->words.begin();
     568                                        wit != creature->words.end(); wit++)
     569                                {
     570                                        if ((*selectedword)->npar == wit->second->npar &&
     571                                                (*selectedword)->name != wit->second->name &&
     572                                                !wit->second->builtin)
     573                                        {
     574                                                available.push_back(wit->second);
     575                                        }
     576                                }
     577                                if (available.size() > 0)
     578                                {
     579                                        int newnameid = rndUint(available.size());
     580                                        (*selectedword)->name = available[newnameid]->name;
     581                                }
     582                                else
    558583                                {
    559584                                        delete (*selectedword);
     
    562587                                        addWord(list, worddef, selectedword);
    563588                                }
    564                                 else
    565                                 {
    566                                         std::vector<fL_Word *> available;
    567                                         for (std::unordered_map<std::string, fL_Word *>::iterator wit = creature->words.begin();
    568                                                         wit != creature->words.end(); wit++)
    569                                         {
    570                                                 if ((*selectedword)->npar == wit->second->npar &&
    571                                                                 (*selectedword)->name != wit->second->name &&
    572                                                                 !wit->second->builtin)
     589                        }
     590                }
     591                else
     592                {
     593                        if ((*selectedword)->npar > 0)
     594                        {
     595                                int randeval = rndUint((*selectedword)->npar);
     596                                Param par((*selectedword)->tab, (*selectedword)->data);
     597                                if ((*selectedword)->builtin && (*selectedword)->name == "N"
     598                                        && strcmp(par.id(randeval), FL_PE_NEURO_DET) == 0)
     599                                {
     600                                        SString res = par.getStringById(FL_PE_NEURO_DET);
     601                                        Geno_fH::mutateNeuronProperties(res);
     602                                        par.setStringById(FL_PE_NEURO_DET, res);
     603                                }
     604                                else if ((*selectedword)->builtin &&
     605                                        (*selectedword)->name == "C" &&
     606                                        strcmp(par.id(randeval), FL_PE_CONN_ATTR) == 0)
     607                                {
     608                                        SString strattractor = par.getStringById(FL_PE_CONN_ATTR);
     609                                        if (strattractor.length() > 0)
     610                                        {
     611                                                fL_Word *w = NULL;
     612                                                creature->createWord(strattractor, w, numpars, 0, 0);
     613                                                // mutate attractor parameter
     614                                                if (w->npar > 0)
    573615                                                {
    574                                                         available.push_back(wit->second);
     616                                                        int rndattr = rndUint(w->npar);
     617                                                        if (!w->parevals[rndattr])
     618                                                        {
     619                                                                w->parevals[rndattr] = new MathEvaluation(numpars);
     620                                                        }
     621                                                        w->parevals[rndattr]->mutate(false, false);
    575622                                                }
    576                                         }
    577                                         if (available.size() > 0)
    578                                         {
    579                                                 int newnameid = rndUint(available.size());
    580                                                 (*selectedword)->name = available[newnameid]->name;
     623                                                strattractor = w->stringify(true);
     624                                                par.setStringById(FL_PE_CONN_ATTR, strattractor);
     625                                                delete w;
    581626                                        }
    582627                                        else
    583628                                        {
    584                                                 delete (*selectedword);
    585                                                 selectedword = list->erase(selectedword);
    586                                                 fL_Word *worddef = randomWordDefinition(creature, roulette(addtypes, FL_ADD_COUNT - 1));
    587                                                 addWord(list, worddef, selectedword);
    588                                         }
    589                                 }
    590                         }
    591                         else
    592                         {
    593                                 if ((*selectedword)->npar > 0)
    594                                 {
    595                                         int randeval = rndUint((*selectedword)->npar);
    596                                         Param par((*selectedword)->tab, (*selectedword)->data);
    597                                         if ((*selectedword)->builtin && (*selectedword)->name == "N"
    598                                                         && strcmp(par.id(randeval), FL_PE_NEURO_DET) == 0)
    599                                         {
    600                                                 SString res = par.getStringById(FL_PE_NEURO_DET);
    601                                                 Geno_fH::mutateNeuronProperties(res);
    602                                                 par.setStringById(FL_PE_NEURO_DET, res);
    603                                         }
    604                                         else if ((*selectedword)->builtin &&
    605                                                         (*selectedword)->name == "C" &&
    606                                                         strcmp(par.id(randeval), FL_PE_CONN_ATTR) == 0)
    607                                         {
    608                                                 SString strattractor = par.getStringById(FL_PE_CONN_ATTR);
    609                                                 if (strattractor.len() > 0)
     629                                                if (creature->builtincount < (int)creature->words.size())
    610630                                                {
    611                                                         fL_Word *w = NULL;
    612                                                         creature->createWord(strattractor, w, numpars, 0, 0);
    613                                                         // mutate attractor parameter
     631                                                        fL_Word *wdef = randomWordDefinition(creature, FL_ADD_OTHER);
     632                                                        fL_Word *w = new fL_Word();
     633                                                        *w = *wdef;
     634                                                        w->data = ParamObject::makeObject(w->tab);
     635                                                        Param apar(w->tab);
     636                                                        apar.select(w->data);
     637                                                        apar.setDefault();
    614638                                                        if (w->npar > 0)
    615639                                                        {
    616640                                                                int rndattr = rndUint(w->npar);
    617                                                                 if (!w->parevals[rndattr])
     641                                                                for (int i = 0; i < w->npar; i++)
    618642                                                                {
    619                                                                         w->parevals[rndattr] = new MathEvaluation(numpars);
     643                                                                        if (i == rndattr)
     644                                                                        {
     645                                                                                MathEvaluation *ev = new MathEvaluation(numpars);
     646                                                                                ev->mutate(false, false);
     647                                                                                w->parevals.push_back(ev);
     648                                                                        }
     649                                                                        else
     650                                                                        {
     651                                                                                w->parevals.push_back(NULL);
     652                                                                        }
    620653                                                                }
    621                                                                 w->parevals[rndattr]->mutate(false, false);
     654
    622655                                                        }
    623                                                         strattractor = w->stringify(true);
     656                                                        strattractor = w->stringify(false);
    624657                                                        par.setStringById(FL_PE_CONN_ATTR, strattractor);
    625658                                                        delete w;
    626659                                                }
    627                                                 else
    628                                                 {
    629                                                         if (creature->builtincount < (int)creature->words.size())
    630                                                         {
    631                                                                 fL_Word *wdef = randomWordDefinition(creature, FL_ADD_OTHER);
    632                                                                 fL_Word *w = new fL_Word();
    633                                                                 *w = *wdef;
    634                                                                 w->data = ParamObject::makeObject(w->tab);
    635                                                                 Param apar(w->tab);
    636                                                                 apar.select(w->data);
    637                                                                 apar.setDefault();
    638                                                                 if (w->npar > 0)
    639                                                                 {
    640                                                                         int rndattr = rndUint(w->npar);
    641                                                                         for (int i = 0; i < w->npar; i++)
    642                                                                         {
    643                                                                                 if (i == rndattr)
    644                                                                                 {
    645                                                                                         MathEvaluation *ev = new MathEvaluation(numpars);
    646                                                                                         ev->mutate(false, false);
    647                                                                                         w->parevals.push_back(ev);
    648                                                                                 }
    649                                                                                 else
    650                                                                                 {
    651                                                                                         w->parevals.push_back(NULL);
    652                                                                                 }
    653                                                                         }
    654 
    655                                                                 }
    656                                                                 strattractor = w->stringify(false);
    657                                                                 par.setStringById(FL_PE_CONN_ATTR, strattractor);
    658                                                                 delete w;
    659                                                         }
    660                                                 }
    661                                         }
    662                                         else
    663                                         {
    664                                                 if (!(*selectedword)->parevals[randeval])
    665                                                 {
    666                                                         (*selectedword)->parevals[randeval] = new MathEvaluation(numpars);
    667                                                 }
    668                                                 (*selectedword)->parevals[randeval]->mutate(false, iterchangestep != 1.0);
    669                                         }
    670                                 }
    671                         }
    672                         break;
    673                 }
     660                                        }
     661                                }
     662                                else
     663                                {
     664                                        if (!(*selectedword)->parevals[randeval])
     665                                        {
     666                                                (*selectedword)->parevals[randeval] = new MathEvaluation(numpars);
     667                                        }
     668                                        (*selectedword)->parevals[randeval]->mutate(false, iterchangestep != 1.0);
     669                                }
     670                        }
     671                }
     672                break;
     673        }
    674674        }
    675675
     
    702702        }
    703703        else if (to->words.find(fromword->name.c_str()) != to->words.end() &&
    704                         to->words[fromword->name.c_str()]->npar == fromword->npar) // if there is already same word with same number of parameters
     704                to->words[fromword->name.c_str()]->npar == fromword->npar) // if there is already same word with same number of parameters
    705705        {
    706706                fL_Word *newword = new fL_Word();
     
    710710        }
    711711        for (std::unordered_map<std::string, fL_Word *>::iterator it = to->words.begin();
    712                         it != to->words.end(); it++)
     712                it != to->words.end(); it++)
    713713        { // find word with same number of parameters
    714714                if (fromword->npar == it->second->npar && map.find(fromword->name.c_str()) == map.end() && !it->second->builtin)
     
    774774                                        std::string form;
    775775                                        if (w->builtin && w->name == "N"
    776                                                         && strcmp(par.id(i), FL_PE_NEURO_DET) == 0)
     776                                                && strcmp(par.id(i), FL_PE_NEURO_DET) == 0)
    777777                                        {
    778778                                                SString res = origpar.getStringById(FL_PE_NEURO_DET);
     
    781781                                        }
    782782                                        else if (w->builtin && w->name == "C"
    783                                                         && strcmp(par.id(i), FL_PE_CONN_ATTR) == 0)
     783                                                && strcmp(par.id(i), FL_PE_CONN_ATTR) == 0)
    784784                                        {
    785785                                                SString strattractor = origpar.getStringById(FL_PE_CONN_ATTR);
    786                                                 if (strattractor.len() > 0)
     786                                                if (strattractor.length() > 0)
    787787                                                {
    788788                                                        fL_Word *tmp = NULL;
  • cpp/frams/genetics/fS/fS_general.cpp

    r969 r973  
    9999                if (separatorIndex == -1)
    100100                {
    101                         keyLength = keyValue.len();
     101                        keyLength = keyValue.length();
    102102                        value = DEFAULT_NEURO_CONNECTION_WEIGHT;
    103103                } else
    104104                {
    105105                        keyLength = separatorIndex;
    106                         size_t valueLength = keyValue.len() - (separatorIndex);
     106                        size_t valueLength = keyValue.length() - (separatorIndex);
    107107                        value = fS_stod(buffer + separatorIndex + 1, start, &valueLength);
    108108                }
     
    859859{
    860860        SString geno;
    861         geno.memoryHint(100);     // Provide a small buffer from the start to improve performance
     861        geno.reserve(100);     // Provide a small buffer from the start to improve performance
    862862        startNode->getGeno(geno);
    863863        return geno;
  • cpp/frams/model/autoname.cpp

    r534 r973  
    11// This file is a part of Framsticks SDK.  http://www.framsticks.com/
    2 // Copyright (C) 1999-2015  Maciej Komosinski and Szymon Ulatowski.
     2// Copyright (C) 1999-2020  Maciej Komosinski and Szymon Ulatowski.
    33// See LICENSE.txt for details.
    44
     
    1111        SString t;
    1212        t = firstName(model);
    13         SString last=lastName(model);
    14         if (last.len()>0)
    15                 {
     13        SString last = lastName(model);
     14        if (last.length() > 0)
     15        {
    1616                t += ' ';
    1717                t += last;
    18                 }
     18        }
    1919        return t;
    2020}
     
    4242        unsigned int s1 = 0, s2 = 0, s3 = 0;
    4343        const char *x = g.c_str();
    44         if (*x==0) return SString();
    45         for (; *x; x++) { s1 += *x; s2 = s2**x + *x; s3 = (s3^*x) + *x; }
     44        if (*x == 0) return SString();
     45        for (; *x; x++) { s1 += *x; s2 = s2 * *x + *x; s3 = (s3 ^ *x) + *x; }
    4646        char* t = buf;
    4747        t = cat_syl(t, s1);
     
    7171                for (i = 0; i <= pp; i++)
    7272                {
    73                 p = (i*d1) / pp - 1; for (; p1 <= p; p1++) *(out++) = *(in1++);
    74                 p = (i*d2) / pp - 1; for (; p2 <= p; p2++) *(out++) = *(in2++);
     73                        p = (i * d1) / pp - 1; for (; p1 <= p; p1++) *(out++) = *(in1++);
     74                        p = (i * d2) / pp - 1; for (; p2 <= p; p2++) *(out++) = *(in2++);
    7575                }
    7676        *out = 0;
     
    100100        if (model.getPartCount() > 0)
    101101        {
    102                 cialo = min((int)(sqrt(double(model.getPartCount()) - 1)*NAME_BODYLEN), NAME_MAXLENBODY - 1);
     102                cialo = min((int)(sqrt(double(model.getPartCount()) - 1) * NAME_BODYLEN), NAME_MAXLENBODY - 1);
    103103                poz = 0;
    104104                for (i = 0; i <= cialo; i++) // budowanie "opisu" ciala
    105105                {
    106                         nextpoz = ((model.getPartCount())*(i + 1)) / (cialo + 1) - 1;
     106                        nextpoz = ((model.getPartCount()) * (i + 1)) / (cialo + 1) - 1;
    107107                        w = 1.0;
    108108                        for (; poz <= nextpoz; poz++) w = max(w, model.getPart(poz)->mass);
    109                         tmpc[i] = Sp[min(int((w - 1.0)*NAME_BODYMASS), int(sizeof(Sp)) - 2)];
     109                        tmpc[i] = Sp[min(int((w - 1.0) * NAME_BODYMASS), int(sizeof(Sp)) - 2)];
    110110                }
    111111                tmpc[i] = 0;
     
    117117        if (model.getNeuroCount() > 0)
    118118        {
    119                 mozg = min((int)(sqrt((double)model.getNeuroCount())*NAME_BRAINLEN), NAME_MAXLENBRAIN - 1);
     119                mozg = min((int)(sqrt((double)model.getNeuroCount()) * NAME_BRAINLEN), NAME_MAXLENBRAIN - 1);
    120120                poz = 0;
    121121                for (i = 0; i <= mozg; i++) // budowanie "opisu" mozgu
    122122                {
    123                         nextpoz = (model.getNeuroCount()*(i + 1)) / (mozg + 1) - 1;
     123                        nextpoz = (model.getNeuroCount() * (i + 1)) / (mozg + 1) - 1;
    124124                        wint = 0;
    125125                        for (; poz <= nextpoz; poz++) wint = max(wint, model.getNeuro(poz)->getInputCount());
    126                         tmpm[i] = Sam[min(int(wint*NAME_BRAININP), int(sizeof(Sam)) - 2)];
     126                        tmpm[i] = Sam[min(int(wint * NAME_BRAININP), int(sizeof(Sam)) - 2)];
    127127                }
    128128                tmpm[i] = 0;
  • cpp/frams/model/modelparts.cpp

    r952 r973  
    149149        SString t;
    150150        t = getDescription();
    151         if (t.len()) t += "\n\n";
     151        if (t.length()) t += "\n\n";
    152152        t += "Characteristics:\n";
    153153        if (getPreferredInputs())
     
    171171        if (p.getPropCount())
    172172        {
    173                 if (t.len()) t += "\n\n";
     173                if (t.length()) t += "\n\n";
    174174                t += "Properties:\n";
    175175                const char *h;
     
    341341{
    342342        SString ret = getClassName();
    343         if (myclassparams.len()) { if (!ret.len()) ret = "N"; ret += ":"; ret += myclassparams; }
     343        if (myclassparams.length()) { if (!ret.length()) ret = "N"; ret += ":"; ret += myclassparams; }
    344344        return ret;
    345345}
     
    372372int Neuro::addInput(Neuro *child, double weight, const SString *info)
    373373{
    374         inputs += NInput(child, weight, (info && (info->len())) ? new SString(*info) : 0);
     374        inputs += NInput(child, weight, (info && (info->length())) ? new SString(*info) : 0);
    375375        child->parentcount++;
    376376        if (child->parentcount == 1) { child->parent = this; }
     
    759759                ParamEntry entries[] = {
    760760                 { "class", 2, 0, "neuro class", "s", GETSET(neuroclass) },
    761                  { "liveNeuro", 2, 1, "live Neuro object", "oNeuro", GETONLY(liveNeuro) }};
     761                 { "liveNeuro", 2, 1, "live Neuro object", "oNeuro", GETONLY(liveNeuro) } };
    762762#undef FIELDSTRUCT
    763                 for(auto& e : entries) add(&e);
     763                for (auto& e : entries) add(&e);
    764764
    765765#define FIELDSTRUCT Neuro
     
    804804{
    805805#ifndef SDK_WITHOUT_FRAMS
    806         NeuroNetImpl::getLiveNeuroObject(this,ret);
     806        NeuroNetImpl::getLiveNeuroObject(this, ret);
    807807#endif
    808808}
  • cpp/frams/neuro/impl/neuroimpl-fuzzy-f0.cpp

    r827 r973  
    11// This file is a part of Framsticks SDK.  http://www.framsticks.com/
    2 // Copyright (C) 1999-2015  Maciej Komosinski and Szymon Ulatowski.
     2// Copyright (C) 1999-2020  Maciej Komosinski and Szymon Ulatowski.
    33// See LICENSE.txt for details.
    44
     
    8383int FuzzyF0String::convertStrToRules(const SString& str, const int ruledef[], int **rules, int setsNr, int rulesNr, int &maxOutputNr)
    8484{
    85         int pos = 0, j, k, len = str.len();
     85        int pos = 0, j, k, len = str.length();
    8686        int dNr = 0, sNr = 0;
    8787        int inNr, outNr; //number of inputs/outputs and corresponding fuzzy sets
  • cpp/frams/neuro/impl/neuroimpl-fuzzy.cpp

    r907 r973  
    11// This file is a part of Framsticks SDK.  http://www.framsticks.com/
    2 // Copyright (C) 1999-2015  Maciej Komosinski and Szymon Ulatowski.
     2// Copyright (C) 1999-2020  Maciej Komosinski and Szymon Ulatowski.
    33// See LICENSE.txt for details.
    44
     
    2121
    2222        //check correctness of given parameters: string must not be null, sets&rules number > 0
    23         if ((fuzzySetsNr < 1) || (rulesNr < 1) || (fuzzySetString.len() == 0) || (fuzzyRulesString.len() == 0))
     23        if ((fuzzySetsNr < 1) || (rulesNr < 1) || (fuzzySetString.length() == 0) || (fuzzyRulesString.length() == 0))
    2424                return 0; //error
    2525
  • cpp/frams/neuro/neurofactory.cpp

    r935 r973  
    103103                }
    104104        }
    105         if (removed.len())
     105        if (removed.length())
    106106                logPrintf("NeuroFactory", "removeUninmplemented", LOG_INFO,
    107107                        "Removed Neuro classes: %s", removed.c_str());
  • cpp/frams/neuro/neurolibparam.cpp

    r790 r973  
    11// This file is a part of Framsticks SDK.  http://www.framsticks.com/
    2 // Copyright (C) 1999-2015  Maciej Komosinski and Szymon Ulatowski.
     2// Copyright (C) 1999-2020  Maciej Komosinski and Szymon Ulatowski.
    33// See LICENSE.txt for details.
    44
     
    3333static bool isGoodName(const SString& name)
    3434{
    35         for (int i = 0; i < name.len(); i++)
     35        for (int i = 0; i < name.length(); i++)
    3636                if (!isalnum(name[i])) return false;
    3737        return true;
  • cpp/frams/param/multiparamload.cpp

    r720 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
     
    158158                }
    159159                buf = trim(buf);
    160                 if (buf.len() == 0)
    161                         unexpected_line = 0;
    162                 else if ((buf.len() > 1) && (buf[buf.len() - 1] == ':'))
     160                if (buf.length() == 0)
     161                        unexpected_line = 0;
     162                else if ((buf.length() > 1) && (buf[buf.length() - 1] == ':'))
    163163                {
    164164                        unexpected_line = 0;
    165165                        lastunknown = 0;
    166                         lastunknown = buf.substr(0, buf.len() - 1);
     166                        lastunknown = buf.substr(0, buf.length() - 1);
    167167                        lastobject.setEmpty();
    168168                        FOREACH(ExtObject*, o, objects)
     
    193193                                        thisfilename ? SString::sprintf(" while reading '%s'", thisfilename).c_str() : "");
    194194                        }
    195                                 break;
     195                        break;
    196196
    197197                        case 1:
     
    293293                if (stat == OnError)
    294294                {
    295                 abort();
    296                 return 0;
     295                        abort();
     296                        return 0;
    297297                }
    298298        return 1;
  • cpp/frams/param/mutableparam.cpp

    r884 r973  
    11// This file is a part of Framsticks SDK.  http://www.framsticks.com/
    2 // Copyright (C) 1999-2019  Maciej Komosinski and Szymon Ulatowski.
     2// Copyright (C) 1999-2020  Maciej Komosinski and Szymon Ulatowski.
    33// See LICENSE.txt for details.
    44
     
    3333int MutableParam::findGroup(const SString name, int ignoreprefix)
    3434{
    35         int skipprefix = grprefix.len() ? grprefix.len() + 2 : 0;
     35        int skipprefix = grprefix.length() ? grprefix.length() + 2 : 0;
    3636        for (int i = 0; i < groups.size(); i++)
    3737        {
     
    5757        {
    5858                tmp = grprefix;
    59                 if (tmp.len()) tmp += ": ";
     59                if (tmp.length()) tmp += ": ";
    6060                tmp += gname;
    6161        }
  • cpp/frams/param/param.cpp

    r950 r973  
    11// This file is a part of Framsticks SDK.  http://www.framsticks.com/
    2 // Copyright (C) 1999-2019  Maciej Komosinski and Szymon Ulatowski.
     2// Copyright (C) 1999-2020  Maciej Komosinski and Szymon Ulatowski.
    33// See LICENSE.txt for details.
    44
     
    5656        int j;
    5757        for (int i = 0; i < n; i++)
    58                 if ((!(flags(i)&PARAM_READONLY))
     58                if ((!(flags(i) & PARAM_READONLY))
    5959                        && (*type(i) != 'p'))
    6060                {
     
    7171        ExtValue v;
    7272        for (int i = 0; i < n; i++)
    73                 if ((!(flags(i)&PARAM_READONLY))
     73                if ((!(flags(i) & PARAM_READONLY))
    7474                        && (*type(i) != 'p'))
    7575                {
     
    178178                else
    179179                {
    180                         if (def.len() > 0) setExtValue(i, ExtValue(def)); else setExtValue(i, ExtValue::empty());
     180                        if (def.length() > 0) setExtValue(i, ExtValue(def)); else setExtValue(i, ExtValue::empty());
    181181                }
    182182        }
     
    303303int ParamInterface::saveprop(VirtFILE* f, int i, const char* p, bool force)
    304304{
    305         if ((flags(i)&PARAM_DONTSAVE) && (!force)) return 0;
     305        if ((flags(i) & PARAM_DONTSAVE) && (!force)) return 0;
    306306        const char *typ = type(i);
    307307        if (*typ == 'p') return 0;
     
    323323        quoteTilde(ws);
    324324        w = ws.c_str();
    325         if (ws.len() > 50) cr = 1;
     325        if (ws.length() > 50) cr = 1;
    326326        else for (t = w; *t; t++) if ((*t == 10) || (*t == 13)) { cr = 1; break; }
    327327        if (cr) f->Vputs("~\n");
     
    334334{
    335335        SString ret = getName();
    336         ret+=".";
    337         ret+=id(prop);
     336        ret += ".";
     337        ret += id(prop);
    338338        return ret;
    339339}
     
    342342{
    343343        SString name_dot_prop = nameDotProperty(prop);
    344         if (strcmp(getName(),getLongName())==0)
    345                 {
    346                 if (strcmp(id(prop),name(prop))==0)
     344        if (strcmp(getName(), getLongName()) == 0)
     345        {
     346                if (strcmp(id(prop), name(prop)) == 0)
    347347                        return name_dot_prop;
    348348                else
    349                         return SString("'")+name(prop)+"': "+name_dot_prop;
    350                 }
    351         else
    352                 return SString("'")+name(prop)+"' in '"+getLongName()+"': "+name_dot_prop;
     349                        return SString("'") + name(prop) + "': " + name_dot_prop;
     350        }
     351        else
     352                return SString("'") + name(prop) + "' in '" + getLongName() + "': " + name_dot_prop;
    353353}
    354354
     
    394394        // t+=SString(getName()); t+=':';
    395395        for (i = 0; p = id(i); i++)
    396                 if (!((fl = flags(i))&PARAM_DONTSAVE))
     396                if (!((fl = flags(i)) & PARAM_DONTSAVE))
    397397                {
    398398                        if (defdata && isequal(i, defdata))
     
    469469                        nameDotPropertyForMessages(i).c_str(),
    470470                        ::sstringDelimitAndShorten(svaluetoset, 30, show_length, quote, quote).c_str(),
    471                         (setflags&PSET_HITMAX) ? (s_type ? "long" : "big") : "small", s_type ? "Truncated" : "Adjusted",
     471                        (setflags & PSET_HITMAX) ? (s_type ? "long" : "big") : "small", s_type ? "Truncated" : "Adjusted",
    472472                        ::sstringDelimitAndShorten(actual, 30, show_length, quote, quote).c_str()
    473473                );
     
    583583                        else
    584584                                seen[i] = true;
    585                         if (!(flags(i)&PARAM_DONTLOAD))
     585                        if (!(flags(i) & PARAM_DONTLOAD))
    586586                        {
    587587                                if (p0[p_len + 1] == '~')
     
    600600                                        int ch; while ((ch = f->Vgetc()) != EOF) if (ch == '\n') break;
    601601                                        unquoteTilde(s);
    602                                         if (options.linenum && (flags(i)&PARAM_LINECOMMENT))
     602                                        if (options.linenum && (flags(i) & PARAM_LINECOMMENT))
    603603                                                s = SString::sprintf("@file %s\n@line %d\n", f->VgetPath(), *options.linenum + 1) + s;
    604604                                        setFromString(i, s.c_str(), false);
     
    943943        if (err != NULL)
    944944                logPrintf("SimpleAbstractParam", "sanityCheck", LOG_ERROR,
    945                           "Invalid ParamEntry for %s (%s)", nameDotPropertyForMessages(i).c_str(), err);
     945                        "Invalid ParamEntry for %s (%s)", nameDotPropertyForMessages(i).c_str(), err);
    946946}
    947947#endif
     
    10541054        ExtValue v;
    10551055        ParamEntry *pe = entry(i);
    1056         if (pe->flags&PARAM_READONLY) return PSET_RONLY;
     1056        if (pe->flags & PARAM_READONLY) return PSET_RONLY;
    10571057        paInt xcopy = x; //only needed for messageOnExceedRange(): retain original, requested value of x because it may be changed below
    10581058        paInt mn = 0, mx = 0, de = 0;
     
    10881088        ExtValue v;
    10891089        ParamEntry *pe = entry(i);
    1090         if (pe->flags&PARAM_READONLY) return PSET_RONLY;
     1090        if (pe->flags & PARAM_READONLY) return PSET_RONLY;
    10911091        double xcopy = x; //only needed for messageOnExceedRange(): retain original, requested value of x because it may be changed below
    10921092        double mn = 0, mx = 0, de = 0;
     
    11241124        const SString *xx = &x;
    11251125        ParamEntry *pe = entry(i);
    1126         if (pe->flags&PARAM_READONLY) return PSET_RONLY;
     1126        if (pe->flags & PARAM_READONLY) return PSET_RONLY;
    11271127        SString xcopy = x; //only needed for messageOnExceedRange(): retain original, requested value of x because it may be changed below
    11281128        const char* t = pe->type + 1;
     
    11321132        if (sscanf(t, "%d %d", &mn, &mx) == 2) //using getMinMax would also get default value, which is not needed here
    11331133        {
    1134                 if ((x.len() > mx) && (mx > 0))
     1134                if ((x.length() > mx) && (mx > 0))
    11351135                {
    11361136                        vs = x.substr(0, mx);
     
    11631163        ExtValue v;
    11641164        ParamEntry *pe = entry(i);
    1165         if (pe->flags&PARAM_READONLY) return PSET_RONLY;
    1166         if (pe->flags&PARAM_OBJECTSET)
     1165        if (pe->flags & PARAM_READONLY) return PSET_RONLY;
     1166        if (pe->flags & PARAM_OBJECTSET)
    11671167        {
    11681168                ExtObject o = getObject(i);
     
    12001200        SANITY_CHECK(i);
    12011201        ParamEntry *pe = entry(i);
    1202         if (pe->flags&PARAM_READONLY) return PSET_RONLY;
     1202        if (pe->flags & PARAM_READONLY) return PSET_RONLY;
    12031203        ExtValue xcopy = x; //only needed for messageOnExceedRange(): retain original, requested value of x because it may be changed below
    12041204        if (pe->fun2)
     
    12551255{
    12561256        const char *beg = s.c_str() + poz;
    1257         if (poz >= s.len()) { poz = s.len(); len = 0; return s.c_str() + s.len(); }
     1257        if (poz >= s.length()) { poz = s.length(); len = 0; return s.c_str() + s.length(); }
    12581258        const char *lf = strchr(beg, '\n');
    1259         if (!lf) { lf = s.c_str() + s.len() - 1; poz = s.len(); }
    1260         else { poz = (int)(lf - s.c_str()) + 1; if (poz > s.len()) poz = s.len(); }
     1259        if (!lf) { lf = s.c_str() + s.length() - 1; poz = s.length(); }
     1260        else { poz = (int)(lf - s.c_str()) + 1; if (poz > s.length()) poz = s.length(); }
    12611261        while (lf >= beg) if ((*lf == '\n') || (*lf == '\r')) lf--; else break;
    12621262        len = (int)(lf - beg) + 1;
     
    12781278        SString tmpvalue;
    12791279        bool parse_failed = false;
    1280         if (options.offset >= s.len()) return fields_loaded;
     1280        if (options.offset >= s.length()) return fields_loaded;
    12811281        t = s.c_str() + options.offset;
    12821282
     
    13161316                if (field_end == t)     // skip empty value
    13171317                {
    1318                         t++; if (i>=0) i++;
     1318                        t++; if (i >= 0) i++;
    13191319                        continue;
    13201320                }
     
    13321332#ifdef WARN_MISSING_NAME
    13331333                else // no parameter name
    1334                         {
     1334                {
    13351335#ifdef SAVE_SELECTED_NAMES
    13361336                        if ((i < 0) // field after unknown field
    1337                             || (i >= getPropCount()) // field after last field
    1338                             || !(flags(i)&PARAM_CANOMITNAME)) // valid field but it can't be skipped
     1337                                || (i >= getPropCount()) // field after last field
     1338                                || !(flags(i) & PARAM_CANOMITNAME)) // valid field but it can't be skipped
    13391339#endif
    13401340                        {
     
    13441344                                        logPrintf("Param", "loadSingleLine", LOG_WARN, "Value after the last property of '%s'", getName());
    13451345                        }
    1346                         }
     1346                }
    13471347                //else skipping a skippable field
    13481348#endif
     
    13641364                        ret = setFromString(i, value, true);
    13651365                        fields_loaded++;
    1366                         if (ret&PSET_PARSEFAILED)
     1366                        if (ret & PSET_PARSEFAILED)
    13671367                                parse_failed = true;
    13681368                        *(char*)valstop = remember;
  • cpp/frams/util/extvalue.cpp

    r940 r973  
    326326                {
    327327                        SString tmp = getString();
    328                         if (tmp.len() > 30) tmp = tmp.substr(0, 30) + "...";
     328                        if (tmp.length() > 30) tmp = tmp.substr(0, 30) + "...";
    329329                        if (type == TString) tmp = SString("\"") + tmp + SString("\"");
    330330                        logPrintf("ExtValue", "getObjectTarget", LOG_WARN, "%s object expected, %s found", classname, tmp.c_str());
     
    614614                        return;
    615615                case TDouble:
    616                         setDouble(double(getInt())*src.getDouble());
     616                        setDouble(double(getInt()) * src.getDouble());
    617617                        return;
    618618                default:;
     
    790790        //            ^-cur     ^-next
    791791        //            ^^^^^^^^^^___sub
    792         const char* begin = fmt.c_str(), *end = begin + fmt.len(), *curr = begin;
     792        const char* begin = fmt.c_str(), *end = begin + fmt.length(), *curr = begin;
    793793        int type = 0;
    794794
     
    14011401        err->message = args[0].getString();
    14021402        if (err->message.startsWith(TO_STRING_PREFIX.c_str()))
    1403                 err->message = err->message.substr(TO_STRING_PREFIX.len());
     1403                err->message = err->message.substr(TO_STRING_PREFIX.length());
    14041404        *ret = makeDynamicObject(err);
    14051405}
  • cpp/frams/util/sstring-simple.cpp

    r970 r973  
    88void SString::initEmpty()
    99{
    10         txt = NULL; used = 0; size = 0;
     10        txt = NULL; used = 0; allocated = 0;
    1111}
    1212
     
    1818SString::~SString()
    1919{
    20         resize(0);
     20        reallocate(0);
    2121}
    2222
     
    3636SString::SString(SString&& from)
    3737{
    38         txt = from.txt; size = from.size; used = from.used;
    39         from.txt = NULL; from.size = 0; from.used = 0;
     38        txt = from.txt; allocated = from.allocated; used = from.used;
     39        from.txt = NULL; from.allocated = 0; from.used = 0;
    4040}
    4141
     
    4646}
    4747
    48 void SString::resize(int newsize)
    49 {
    50         if (newsize == size) return;
     48void SString::reallocate(int newsize)
     49{
     50        if (newsize == allocated) return;
    5151        txt = (char*)realloc(txt, newsize);
    52         size = newsize;
    53 }
    54 
    55 void SString::ensureSize(int needed)
    56 {
    57         if (size > needed) return;
    58         resize((size > 0) ? (needed + needed / 2 + 1) : (needed + 1));
     52        allocated = newsize;
     53}
     54
     55void SString::ensureAllocated(int needed)
     56{
     57        if (allocated > needed) return;
     58        reallocate((allocated > 0) ? (needed + needed / 2 + 1) : (needed + 1));
    5959}
    6060
    6161char *SString::directWrite(int ensuresize)
    6262{
    63         ensureSize(ensuresize);
     63        ensureAllocated(ensuresize);
    6464        appending = used;
    6565        return txt;
     
    6868char *SString::directAppend(int maxappend)
    6969{
    70         ensureSize(used + maxappend);
     70        ensureAllocated(used + maxappend);
    7171        appending = used;
    7272        return txt + appending;
     
    7878        else txt[newlength] = 0;
    7979        used = newlength;
    80         assert(used < size);
     80        assert(used < allocated);
    8181}
    8282
     
    8686        else txt[appending + newappend] = 0;
    8787        used = appending + newappend;
    88         assert(used < size);
     88        assert(used < allocated);
    8989}
    9090
     
    102102{
    103103        if (!n) return;
    104         ensureSize(used + n);
     104        ensureAllocated(used + n);
    105105        memmove(txt + used, t, n);
    106106        used += n;
     
    110110void SString::operator+=(const SString&s)
    111111{
    112         append(s.c_str(), s.len());
     112        append(s.c_str(), s.length());
    113113}
    114114
     
    116116{
    117117        SString ret;
    118         ret.reserve(len() + s.len());
     118        ret.reserve(length() + s.length());
    119119        ret = *this;
    120120        ret += s;
     
    130130        if (chlen)
    131131        {
    132                 ensureSize(chlen);
     132                ensureAllocated(chlen);
    133133                memmove(txt, ch, chlen);
    134134                txt[chlen] = 0;
     
    153153{
    154154        if (&s == this) return;
    155         copyFrom(s.c_str(), s.len());
     155        copyFrom(s.c_str(), s.length());
    156156}
    157157
    158158///////////////////////////////////////
    159159
    160 SString SString::substr(int begin, int length) const
    161 {
    162         if (begin < 0) { length += begin; begin = 0; }
    163         if (length >= (len() - begin)) length = len() - begin;
    164         if (length <= 0) return SString();
    165         if (length == len()) return *this;
    166         return SString((*this)(begin), length);
     160SString SString::substr(int begin, int numchars) const
     161{
     162        if (begin < 0) { numchars += begin; begin = 0; }
     163        if (numchars >= (length() - begin)) numchars = length() - begin;
     164        if (numchars <= 0) return SString();
     165        if (numchars == length()) return *this;
     166        return SString((*this)(begin), numchars);
    167167}
    168168
     
    172172{
    173173        if (this == &s) return true;
    174         if (len() != s.len()) return false;
     174        if (length() != s.length()) return false;
    175175        return strcmp(getPtr(), s.getPtr()) == 0;
    176176}
     
    198198bool SString::getNextToken(int& pos, SString &token, char separator) const
    199199{
    200         if (pos >= len()) { token = 0; return false; }
     200        if (pos >= length()) { token = 0; return false; }
    201201        int p1 = pos, p2;
    202202        const char *t1 = getPtr() + pos;
    203203        const char *t2 = strchr(t1, separator);
    204         if (t2) pos = (p2 = (t2 - getPtr())) + 1; else p2 = pos = len();
     204        if (t2) pos = (p2 = (t2 - getPtr())) + 1; else p2 = pos = length();
    205205        strncpy(token.directWrite(p2 - p1), t1, p2 - p1);
    206206        token.endWrite(p2 - p1);
     
    254254                char* p = ret.directWrite(size);
    255255                assert(p != NULL);
    256                 size = ret.directMaxLen() + 1;
     256                size = ret.capacity() + 1;
    257257                /* Try to print in the allocated space. */
    258258                va_start(ap, format);
  • cpp/frams/util/sstring-simple.h

    r955 r973  
    1414private:
    1515        char *txt;      ///< string buffer or NULL for empty string
    16         int size;       ///< allocated memory (including \0)
     16        int allocated;       ///< allocated memory (including \0)
    1717        int used;       ///< string length
    1818        int appending;  ///< append mode, changes can occur after character # 'appending'
     
    2020        void initEmpty();
    2121        void copyFrom(SString &from); ///< copy from SString
    22         void resize(int newsize);
    23         void ensureSize(int needed);
     22        void reallocate(int newsize);
     23        void ensureAllocated(int needed);
    2424        const char* getPtr() const { return txt ? txt : ""; }
    2525
     
    3434
    3535        void copyFrom(const char* ch, int chlen = -1); ///< copy string, length of -1 == unknown
    36        
    37         void* operator new(size_t s, void* mem){ return mem; }
     36
     37        void* operator new(size_t s, void* mem) { return mem; }
    3838#ifdef _MSC_VER
    39                 void operator delete(void* mem, void* t) {}
     39        void operator delete(void* mem, void* t) {}
    4040#endif
    41         void* operator new(size_t s){ return malloc(sizeof(SString)); }
     41        void* operator new(size_t s) { return malloc(sizeof(SString)); }
    4242        void operator delete(void* mem) { free(mem); }
    4343
    44         int len() const { return used; } ///< get string length
     44        int length() const { return used; } ///< get string length
     45        int size() const { return length(); } ///< get string length
    4546        void shrink(); ///< free unnecessary buffer
    46         void reserve(int needed) { ensureSize(needed); } ///< like in std::string
     47        void reserve(int cap) { ensureAllocated(cap + 1); } ///< like in std::string
    4748
    4849        /// after this call, you can modify sstring directly.
     
    8788        void endAppend(int appendlength = -1);
    8889
    89         void memoryHint(int howbig) { ensureSize(howbig); }
    90         int directMaxLen() { return size - 1; } ///< when called after directWrite: max number of characters allowed (can be more than requested)
     90        int capacity() { return (allocated > 0) ? (allocated - 1) : allocated; } ///< std::string.capacity()
    9191
    9292        /// find a character in SString.
  • cpp/frams/util/sstring.cpp

    r970 r973  
    163163}
    164164
    165 void SString::memoryHint(int howbig)
    166 {
    167         detachCopy(howbig);
    168 }
    169 
    170165void SString::detachEmpty(int ensuresize)
    171166{
     
    201196char *SString::directWrite(int ensuresize)
    202197{
    203         if (ensuresize < 0) ensuresize = len();
     198        if (ensuresize < 0) ensuresize = length();
    204199        REF_LOCK;
    205200        detachCopy(ensuresize);
     
    259254void SString::operator+=(const SString&s)
    260255{
    261         append(s.c_str(), s.len());
     256        append(s.c_str(), s.length());
    262257}
    263258
     
    298293///////////////////////////////////////
    299294
    300 SString SString::substr(int begin, int length) const
    301 {
    302         if (begin < 0) { length += begin; begin = 0; }
    303         if (length >= (len() - begin)) length = len() - begin;
    304         if (length <= 0) return SString();
    305         if (length == len()) return *this;
    306         return SString((*this)(begin), length);
     295SString SString::substr(int begin, int numchars) const
     296{
     297        if (begin < 0) { numchars += begin; begin = 0; }
     298        if (numchars >= (length() - begin)) numchars = length() - begin;
     299        if (numchars <= 0) return SString();
     300        if (numchars == length()) return *this;
     301        return SString((*this)(begin), numchars);
    307302}
    308303
     
    337332bool SString::getNextToken(int& pos, SString &token, char separator) const
    338333{
    339         if (pos >= len()) { token = 0; return false; }
     334        if (pos >= length()) { token = 0; return false; }
    340335        int p1 = pos, p2;
    341336        const char *t1 = buf->txt + pos;
    342337        const char *t2 = strchr(t1, separator);
    343         if (t2) pos = (p2 = (t2 - buf->txt)) + 1; else p2 = pos = len();
     338        if (t2) pos = (p2 = (t2 - buf->txt)) + 1; else p2 = pos = length();
    344339        strncpy(token.directWrite(p2 - p1), t1, p2 - p1);
    345340        token.endWrite(p2 - p1);
     
    401396                char* p = ret.directWrite(size);
    402397                assert(p != NULL);
    403                 size = ret.directMaxLen() + 1;
     398                size = ret.capacity() + 1;
    404399                /* Try to print in the allocated space. */
    405400                va_start(ap, format);
  • cpp/frams/util/sstring.h

    r955 r973  
    11// This file is a part of Framsticks SDK.  http://www.framsticks.com/
    2 // Copyright (C) 1999-2015  Maciej Komosinski and Szymon Ulatowski.
     2// Copyright (C) 1999-2020  Maciej Komosinski and Szymon Ulatowski.
    33// See LICENSE.txt for details.
    44
     
    8585        void operator delete(void* mem) { free(mem); }
    8686
    87         int len() const { return buf->used; } ///< get string length
     87        int size() const { return buf->used; } ///< get string length
     88        int length() const { return buf->used; } ///< get string length
    8889        void shrink(); ///< free unnecessary buffer
    89         void reserve(int needed) { ensureSize(needed); } ///< like in std::string
     90        void reserve(int needed) { detachCopy(needed); } ///< like in std::string
    9091
    9192        /// after this call, you can modify sstring directly.
     
    129130        /// t.endAppend(bytecount);</CODE>
    130131        void endAppend(int appendlength = -1);
    131         /// argument is the amount of memory, that will be probably used
    132         /// by this string instance. string can use this value
    133         /// to optimize memory allocation (bigger chunks will be allocated).
    134         void memoryHint(int howbig);
    135         int directMaxLen() { return buf->size; } ///< when called after directWrite: max number of characters allowed (can be more than requested)
     132        int capacity() { return buf->size; } ///< std::string.capacity()
    136133
    137134        /// find a character in SString.
  • cpp/frams/util/sstringutils.cpp

    r904 r973  
    11// This file is a part of Framsticks SDK.  http://www.framsticks.com/
    2 // Copyright (C) 1999-2015  Maciej Komosinski and Szymon Ulatowski.
     2// Copyright (C) 1999-2020  Maciej Komosinski and Szymon Ulatowski.
    33// See LICENSE.txt for details.
    44
     
    7979                else
    8080                {
    81                         if (tmp.len() == 0) return 0; // nothing was changed!
     81                        if (tmp.length() == 0) return 0; // nothing was changed!
    8282                        tmp += x;
    8383                        target = tmp;
     
    112112                else
    113113                {
    114                         if (tmp.len() == 0) return 0; // nothing was changed!
     114                        if (tmp.length() == 0) return 0; // nothing was changed!
    115115                        tmp += x;
    116116                        target = tmp;
     
    139139        bool changed = 0;
    140140        SString tmp;
    141         tmp.memoryHint(target.len());
     141        tmp.reserve(target.length());
    142142        while (*x)
    143143        {
     
    160160{
    161161        SString out;
    162         if (in.len() > maxlen)
    163                 out = in.substr(0, maxlen / 2) + "..." + in.substr(in.len() - maxlen + maxlen / 2);
     162        if (in.length() > maxlen)
     163                out = in.substr(0, maxlen / 2) + "..." + in.substr(in.length() - maxlen + maxlen / 2);
    164164        else
    165165        {
     
    169169        out = before + out + after;
    170170        if (show_length)
    171                 out += SString::sprintf(" (length %d)", in.len());
     171                out += SString::sprintf(" (length %d)", in.length());
    172172        return out;
    173173}
     
    208208                else
    209209                {
    210                         if (tmp.len() == 0) return 0; // nothing was changed!
     210                        if (tmp.length() == 0) return 0; // nothing was changed!
    211211                        tmp += x;
    212212                        target = tmp;
     
    223223        {
    224224                n = strchr(t + pos, ',');
    225                 if ((!strncmp(t + pos, name.c_str(), name.len())) && (t[pos + name.len()] == '='))
    226                 {
    227                         if (n) end = n - t; else end = txt.len();
     225                if ((!strncmp(t + pos, name.c_str(), name.length())) && (t[pos + name.length()] == '='))
     226                {
     227                        if (n) end = n - t; else end = txt.length();
    228228                        return pos;
    229229                }
     
    238238        p = strFindField(txt, name, e);
    239239        if (p < 0) return SString();
    240         p += name.len() + 1;
     240        p += name.length() + 1;
    241241        return SString(txt.substr(p, e - p));
    242242}
     
    248248        if (p < 0)
    249249        {
    250                 if (!value.len()) return;
    251                 char *t = txt.directAppend(1 + name.len() + value.len());
     250                if (!value.length()) return;
     251                char *t = txt.directAppend(1 + name.length() + value.length());
    252252                char *b = t;
    253                 if (txt.len()) *(t++) = ',';
    254                 strcpy(t, name.c_str()); t += name.len();
     253                if (txt.length()) *(t++) = ',';
     254                strcpy(t, name.c_str()); t += name.length();
    255255                *(t++) = '=';
    256                 strcpy(t, value.c_str()); t += value.len();
     256                strcpy(t, value.c_str()); t += value.length();
    257257                txt.endAppend(t - b);
    258258        }
    259259        else
    260260        {
    261                 if (!value.len())
    262                 {
    263                         if (p > 0) p--; else if (e < txt.len()) e++;
     261                if (!value.length())
     262                {
     263                        if (p > 0) p--; else if (e < txt.length()) e++;
    264264                        char *t = txt.directWrite(0);
    265                         memmove(t + p, t + e, txt.len() - e);
    266                         txt.endWrite(txt.len() + value.len() - (e - p));
    267                 }
    268                 else
    269                 {
    270                         p += name.len() + 1;
    271                         char *t = txt.directWrite(txt.len() + value.len() - (e - p));
    272                         memmove(t + p + value.len(), t + e, txt.len() - e);
    273                         memmove(t + p, value.c_str(), value.len());
    274                         txt.endWrite(txt.len() + value.len() - (e - p));
     265                        memmove(t + p, t + e, txt.length() - e);
     266                        txt.endWrite(txt.length() + value.length() - (e - p));
     267                }
     268                else
     269                {
     270                        p += name.length() + 1;
     271                        char *t = txt.directWrite(txt.length() + value.length() - (e - p));
     272                        memmove(t + p + value.length(), t + e, txt.length() - e);
     273                        memmove(t + p, value.c_str(), value.length());
     274                        txt.endWrite(txt.length() + value.length() - (e - p));
    275275                }
    276276        }
     
    280280{
    281281        const unsigned char*b = (const unsigned char*)s.c_str();
    282         const unsigned char*e = b + s.len();
     282        const unsigned char*e = b + s.length();
    283283        while ((b < e) && (*b <= ' ')) b++;
    284284        while ((b < e) && (e[-1] <= ' ')) e--;
    285         if ((e - b) == s.len()) return s;
     285        if ((e - b) == s.length()) return s;
    286286        SString newstring;
    287287        char* t = newstring.directWrite(e - b);
     
    291291}
    292292
    293 SString concatPath(const SString& in1,const SString& in2)
    294 {
    295         SString out=in1;
    296         if (out.len()>0 && out[out.len()-1]!=PATH_SEPARATOR_CHAR)
    297                 out+=PATH_SEPARATOR_CHAR;
    298         out+=in2;
     293SString concatPath(const SString& in1, const SString& in2)
     294{
     295        SString out = in1;
     296        if (out.length() > 0 && out[out.length() - 1] != PATH_SEPARATOR_CHAR)
     297                out += PATH_SEPARATOR_CHAR;
     298        out += in2;
    299299        return out;
    300300}
     
    318318bool matchWildcard(const SString& word, const SString& pattern)
    319319{
    320         if (pattern.len() == 0)
    321                 return word.len() == 0;
     320        if (pattern.length() == 0)
     321                return word.length() == 0;
    322322        int aster = pattern.indexOf('*');
    323323        if (aster >= 0)
     
    325325                SString before = pattern.substr(0, aster);
    326326                SString after = pattern.substr(aster + 1);
    327                 if (!word.len()) return false;
    328                 if (before.len()) if (!word.startsWith(before.c_str())) return false;
    329                 if (after.len())
    330                         if ((word.len() < after.len())
    331                                 || (strcmp(after.c_str(), word.c_str() + word.len() - after.len())))
     327                if (!word.length()) return false;
     328                if (before.length()) if (!word.startsWith(before.c_str())) return false;
     329                if (after.length())
     330                        if ((word.length() < after.length())
     331                                || (strcmp(after.c_str(), word.c_str() + word.length() - after.length())))
    332332                                return false;
    333333                return true;
     
    339339bool matchWildcardList(const SString& word, const SString& patterns)
    340340{
    341         if (patterns.len() == 0)
    342                 return word.len() == 0;
     341        if (patterns.length() == 0)
     342                return word.length() == 0;
    343343        int pos = 0;
    344344        SString pattern;
  • cpp/frams/util/sstringutils.h

    r929 r973  
    4040        int i, next = 0;
    4141        bool first = true;
    42         if (!separator.len()) { result.push_back(text); return; }
     42        if (!separator.length()) { result.push_back(text); return; }
    4343        while (1)
    4444        {
     
    4646                if (i < 0)
    4747                {
    48                         if ((next <= text.len()) || first)
     48                        if ((next <= text.length()) || first)
    4949                                result.push_back(text.substr(next));
    5050                        return;
     
    5555                        first = false;
    5656                }
    57                 next = i + separator.len();
     57                next = i + separator.length();
    5858        }
    5959}
  • cpp/frams/vm/framscript.l

    r955 r973  
    116116static SString quoteMultiline(const SString &src)
    117117{
    118 int len=src.len();
     118int len=src.length();
    119119SString ret;
    120120ret.reserve((len*11)/10+10);
  • cpp/frams/vm/framscript.y

    r955 r973  
    15131513        return val.getString();
    15141514SString s=val.getString();
    1515 int len=s.len();
     1515int len=s.length();
    15161516SString ret;
    15171517ret.reserve((len*11)/10+10);
Note: See TracChangeset for help on using the changeset viewer.