Changeset 973
- Timestamp:
- 07/03/20 00:37:13 (4 years ago)
- Location:
- cpp/frams
- Files:
-
- 34 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/frams/_demos/genooper_test.cpp
r955 r973 1 1 // This file is a part of Framsticks SDK. http://www.framsticks.com/ 2 // Copyright (C) 1999-20 15Maciej Komosinski and Szymon Ulatowski.2 // Copyright (C) 1999-2020 Maciej Komosinski and Szymon Ulatowski. 3 3 // See LICENSE.txt for details. 4 4 … … 9 9 { 10 10 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()); 12 12 } 13 13 -
cpp/frams/_demos/loader_test_geno.cpp
r732 r973 1 1 // This file is a part of Framsticks SDK. http://www.framsticks.com/ 2 // Copyright (C) 1999-20 15Maciej Komosinski and Szymon Ulatowski.2 // Copyright (C) 1999-2020 Maciej Komosinski and Szymon Ulatowski. 3 3 // See LICENSE.txt for details. 4 4 … … 20 20 "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" 21 21 "Example: loader_test walking.gen \"Basic Quadruped\" | theater -g -\n" 22 22 ); 23 23 return 1; 24 24 } … … 29 29 const char* selected = (argc < 3) ? NULL : argv[2]; 30 30 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; 32 32 // using char* constructor (passing the file name to open) 33 33 GenotypeMini *loaded; … … 36 36 // loaded into MiniGenotype object 37 37 count++; 38 totalsize += loaded->genotype.len ();38 totalsize += loaded->genotype.length(); 39 39 if (selected) 40 40 { … … 65 65 return 0; 66 66 } 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()); 68 68 } 69 69 // the loop repeats until loaded==NULL, which could be beacause of error -
cpp/frams/_demos/paramtree_stdin_test.cpp
r744 r973 45 45 while (group_names.getNextToken(pos, line, '\n')) 46 46 { 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 lines47 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 50 50 param.addGroup(line.c_str()); 51 51 } -
cpp/frams/_demos/printconvmap.cpp
r739 r973 1 1 // This file is a part of Framsticks SDK. http://www.framsticks.com/ 2 // Copyright (C) 1999-20 18Maciej Komosinski and Szymon Ulatowski.2 // Copyright (C) 1999-2020 Maciej Komosinski and Szymon Ulatowski. 3 3 // See LICENSE.txt for details. 4 4 … … 48 48 return; 49 49 } 50 len1 = gen1.len ();50 len1 = gen1.length(); 51 51 SString g1 = gen1; 52 52 stripstring(g1); … … 73 73 y2 = len1; 74 74 } 75 else 75 else { 76 76 id = map.findMappingId(y); 77 77 mr = &map.getMapping(id)->to; … … 80 80 if ((y2 - y) > left_column_padding) y2 = y + left_column_padding; 81 81 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); 83 83 y = y2; 84 84 } -
cpp/frams/_demos/simil_test.cpp
r895 r973 1 1 // This file is a part of Framsticks SDK. http://www.framsticks.com/ 2 // Copyright (C) 1999-20 16Maciej Komosinski and Szymon Ulatowski.2 // Copyright (C) 1999-2020 Maciej Komosinski and Szymon Ulatowski. 3 3 // See LICENSE.txt for details. 4 4 … … 78 78 M.m_adFactors[i] = -1.0; 79 79 } 80 80 81 81 iCurrParam++; 82 82 szCurrParam = argv[iCurrParam]; 83 int measure_type = -1; 83 int measure_type = -1; 84 84 nResult = sscanf(szCurrParam, "%d", &measure_type); 85 85 if (nResult != 1) … … 88 88 return -1; 89 89 } 90 90 91 91 if (measure_type != 0 && measure_type != 1) 92 92 { 93 93 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 97 97 M.matching_method = measure_type; 98 98 … … 150 150 // while a valid genotype was loaded 151 151 count++; 152 totalsize += loaded->genotype.len ();152 totalsize += loaded->genotype.length(); 153 153 // create a Geno object based on the MiniGenotype 154 154 Geno *pNextGenotype = new Geno(loaded->genotype); … … 156 156 { 157 157 pvGenos.push_back(pNextGenotype); 158 char *szNewName = new char[loaded->name.len () + 1];158 char *szNewName = new char[loaded->name.length() + 1]; 159 159 strcpy(szNewName, loaded->name.c_str()); 160 160 pvNames.push_back(szNewName); -
cpp/frams/canvas/neurodiagram.cpp
r838 r973 1 1 // This file is a part of Framsticks SDK. http://www.framsticks.com/ 2 // Copyright (C) 1999-20 17Maciej Komosinski and Szymon Ulatowski.2 // Copyright (C) 1999-2020 Maciej Komosinski and Szymon Ulatowski. 3 3 // See LICENSE.txt for details. 4 4 … … 136 136 int *xywh = GetXYWH(el); 137 137 XY[0] = 0; 138 XY[1] = ((1 + i) *xywh[3]) / (GetInputs(el) + 1);138 XY[1] = ((1 + i) * xywh[3]) / (GetInputs(el) + 1); 139 139 return XY; 140 140 } … … 230 230 if (i >= countNeurons()) return; 231 231 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)); 234 234 probes += (void*)probe; 235 235 add(probe); … … 255 255 addNeuroDescription(tooltip, n); 256 256 label += n->getClassName(); 257 if (n->getClassParams().len ())257 if (n->getClassParams().length()) 258 258 { 259 259 tooltip += "\n"; tooltip += n->getClassParams(); … … 319 319 */ 320 320 321 // NeuroSymbol is also responsible for drawing connection lines from its inputs to other NeuroSymbols' outputs321 // NeuroSymbol is also responsible for drawing connection lines from its inputs to other NeuroSymbols' outputs 322 322 NeuroSymbol *ns2; 323 323 if (!diagram.isLive()) … … 350 350 { 351 351 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; 353 353 } 354 354 // note: "diagram" uses global coordinate system, so we add "pos" or "ns2->pos" to get NeuroSymbol's global positions … … 413 413 int NeuroSymbol::inputY(int i) 414 414 { 415 return (1 + i) *size.y / ((n->getInputCount()) + 1);415 return (1 + i) * size.y / ((n->getInputCount()) + 1); 416 416 } 417 417 … … 421 421 if (x < size.x / 4) 422 422 { // 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) 429 424 { 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) 435 429 { 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; 438 440 } 439 return t;440 441 } 441 }442 442 } 443 443 return CanvasWindow::hint(x, y); … … 448 448 NeuroProbe::NeuroProbe(NeuroSymbol* ns) 449 449 :DCanvasWindow(DCanvasWindow::Title + DCanvasWindow::Border + DCanvasWindow::Close + DCanvasWindow::Size, 450 ns->getLabel().c_str(), &neurochart, &neurochart)450 ns->getLabel().c_str(), &neurochart, &neurochart) 451 451 { 452 452 holdismine = 0; … … 515 515 while (*dr != NeuroImpl::ENDDRAWING) 516 516 { 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; 519 519 if (first) { moveTo(x, y); first = 0; } 520 520 else lineTo(x, y); … … 577 577 { 578 578 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; 580 580 if (chsel == 0) 581 581 link->n->state = st; … … 602 602 int sy = size.y; 603 603 if (chsel >= 0) sy -= textHeight(); 604 return ((y <sy) && (y>(sy - textHeight())));604 return ((y < sy) && (y > (sy - textHeight()))); 605 605 } 606 606 return 0; … … 635 635 { 636 636 link->n->flags ^= Neuro::HoldState; 637 holdismine = ((link->n->flags &Neuro::HoldState) != 0);637 holdismine = ((link->n->flags & Neuro::HoldState) != 0); 638 638 requestPaint(); 639 639 return LeftButton; … … 645 645 SString NeuroProbe::hint(int x, int y) 646 646 { 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"); 649 649 else if (insideChSelector(x, y)) 650 650 return SString::sprintf("channel %d of %d (click and drag to switch channels)", chsel, chnum); -
cpp/frams/genetics/f4/f4_general.cpp
r955 r973 1 1 // This file is a part of Framsticks SDK. http://www.framsticks.com/ 2 // Copyright (C) 1999-20 19Maciej Komosinski and Szymon Ulatowski.2 // Copyright (C) 1999-2020 Maciej Komosinski and Szymon Ulatowski. 3 3 // See LICENSE.txt for details. 4 4 … … 1293 1293 if (2 == childCount()) 1294 1294 if (0 == out[0]) out += ">"; else 1295 if ('>' != out[out.len () - 1]) out += ">";1295 if ('>' != out[out.length() - 1]) out += ">"; 1296 1296 if (NULL != child2) child2->sprint(out); 1297 1297 // make sure last char is a '>' 1298 1298 if (0 == out[0]) out += ">"; else 1299 if ('>' != out[out.len () - 1]) out += ">";1299 if ('>' != out[out.length() - 1]) out += ">"; 1300 1300 } 1301 1301 … … 1310 1310 1311 1311 // very last '>' can be omitted 1312 len = out.len ();1312 len = out.length(); 1313 1313 if (len > 1) 1314 1314 if ('>' == out[len - 1]) { (out.directWrite())[len - 1] = 0; out.endWrite(); }; -
cpp/frams/genetics/f9/f9_conv.cpp
r779 r973 1 1 // This file is a part of Framsticks SDK. http://www.framsticks.com/ 2 // Copyright (C) 1999-20 18Maciej Komosinski and Szymon Ulatowski.2 // Copyright (C) 1999-2020 Maciej Komosinski and Szymon Ulatowski. 3 3 // See LICENSE.txt for details. 4 4 … … 32 32 m.open(using_checkpoints); 33 33 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++) 35 35 { 36 36 char command = in[i]; … … 119 119 double d1 = ind - indpre; 120 120 double d2 = indpost - ind; 121 double v = indpre == indpost ? v1 : d2 *v1 + d1*v2; //d1+d2==1121 double v = indpre == indpost ? v1 : d2 * v1 + d1 * v2; //d1+d2==1 122 122 return v; 123 123 } … … 136 136 Joint *j = m.getJoint(i); 137 137 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; 139 139 j->vcolor.x = mix(r, maxind, ind); 140 140 j->vcolor.y = mix(g, maxind, ind); … … 153 153 averagecolor += j->vcolor; 154 154 p->vcolor = averagecolor / count; 155 if (count >5) count = 5; //avoid too fat...155 if (count > 5) count = 5; //avoid too fat... 156 156 p->vsize = 0.3 + count / 15.0; //the more Joints is attached to a Part, the fatter it is 157 157 } … … 169 169 ((3 * i + 5) % 10) - 4.5, 170 170 ((7 * i + 2) % 10) - 4.5 171 171 ); //-4.5 .. 4.5 in each axis 172 172 p->p += noise / 1000; 173 173 } -
cpp/frams/genetics/fB/fB_conv.cpp
r954 r973 1 1 // This file is a part of Framsticks SDK. http://www.framsticks.com/ 2 // Copyright (C) 1999-20 18Maciej Komosinski and Szymon Ulatowski.2 // Copyright (C) 1999-2020 Maciej Komosinski and Szymon Ulatowski. 3 3 // See LICENSE.txt for details. 4 4 … … 80 80 int endoffset = 0; 81 81 if (gene.indexOf("zz", 0) != -1) endoffset = 2; 82 if (gene.len () - endoffset < 3)82 if (gene.length() - endoffset < 3) 83 83 { 84 84 fH_StickHandle *handle = new fH_StickHandle(dims, start, end); … … 124 124 if (gene.indexOf("zz", 0) != -1) endoffset = 2; 125 125 int nclassdefcount = 1; 126 while (z < gene.len () - endoffset)126 while (z < gene.length() - endoffset) 127 127 { 128 128 if (processNextLetter(creature, handle, par, gene, propindex, z, ranges, nclassdefcount) == -1) … … 185 185 } 186 186 nextid++; 187 } 188 while (genotype[nextid] == '"'); 187 } while (genotype[nextid] == '"'); 189 188 i = nextid; 190 189 } -
cpp/frams/genetics/fB/fB_general.h
r802 r973 1 1 // This file is a part of Framsticks SDK. http://www.framsticks.com/ 2 // Copyright (C) 1999-20 18Maciej Komosinski and Szymon Ulatowski.2 // Copyright (C) 1999-2020 Maciej Komosinski and Szymon Ulatowski. 3 3 // See LICENSE.txt for details. 4 4 … … 35 35 do { 36 36 count++; 37 if (start < genotype.len ())37 if (start < genotype.length()) 38 38 result = getNextGene(start, genotype, tmp, start); 39 39 else … … 52 52 do { 53 53 count++; 54 if (start < geno.len ())54 if (start < geno.length()) 55 55 getNextGene(start, geno, tmp, start); 56 56 else … … 89 89 } while (quotecount % 2 != 0 && end != -1); 90 90 91 if (end == -1) end = genotype.len ();91 if (end == -1) end = genotype.length(); 92 92 else end += 2; 93 93 start -= 1; … … 124 124 } while (quotecount % 2 != 0 && end != -1); 125 125 126 if (end == -1) end = genotype.len ();126 if (end == -1) end = genotype.length(); 127 127 else end += 2; 128 128 start -= 1; -
cpp/frams/genetics/fB/fB_oper.cpp
r961 r973 47 47 int endoffset = 0; 48 48 if (gene.indexOf("zz", 0) != -1) endoffset = 2; 49 if (gene.len () - endoffset < 3)49 if (gene.length() - endoffset < 3) 50 50 { 51 51 return true; // genes with length < 3 are always sticks … … 83 83 } 84 84 // 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++) 86 86 { 87 87 if (!islower(genotype[i])) … … 144 144 fix = true; 145 145 } 146 for (int i = pos; i < genotype.len (); i++)146 for (int i = pos; i < genotype.length(); i++) 147 147 { 148 148 // if character is not alphabetic - error … … 208 208 std::list<SString> res; 209 209 int i = 0; 210 while (i < genotype.len ())210 while (i < genotype.length()) 211 211 { 212 212 // if character is not alphabetic - error … … 252 252 std::advance(it, rndid); 253 253 SString t = (*it); 254 if ((*it).len () == 1)254 if ((*it).length() == 1) 255 255 { 256 256 if (rndUint(2) == 0) … … 264 264 else (*it).directWrite()[0] = (*it)[0] + 1; 265 265 } 266 chg = 1.0 / line.len ();266 chg = 1.0 / line.length(); 267 267 } 268 268 else … … 270 270 // first method needs to extract quotes 271 271 SString def = (*it); 272 def = def.substr(1, def.len () - 2);272 def = def.substr(1, def.length() - 2); 273 273 Geno_fH::mutateNeuronProperties(def); 274 274 SString res = "\""; … … 276 276 res += "\""; 277 277 (*it) = res; 278 chg = (double)def.len () / line.len();278 chg = (double)def.length() / line.length(); 279 279 } 280 280 line = detokenizeSequence(&tokenized); … … 296 296 res += "\""; 297 297 tokenized.insert(it, res); 298 chg = (double)classdef.len () / line.len();298 chg = (double)classdef.length() / line.length(); 299 299 line = detokenizeSequence(&tokenized); 300 300 break; … … 304 304 case FB_INSERTION: 305 305 { 306 chg = 1.0 / line.len ();306 chg = 1.0 / line.length(); 307 307 std::list<SString> tokenized = tokenizeSequence(line); 308 308 int rndid = rndUint(tokenized.size()); // select random insertion point … … 317 317 case FB_DELETION: 318 318 { 319 chg = 1.0 / line.len ();319 chg = 1.0 / line.length(); 320 320 std::list<SString> tokenized = tokenizeSequence(line); 321 321 std::list<SString>::iterator it = tokenized.begin(); … … 332 332 SString gene = fB_GenoHelpers::getGene(rndgene, line, start, end); 333 333 if (gene.indexOf("zz", 0) == -1) gene += "zz"; 334 chg = (float)gene.len () / line.len();334 chg = (float)gene.length() / line.length(); 335 335 line = gene + line; 336 336 break; … … 364 364 // line.substr(cuts[1], cuts[2] - cuts[1]) + first + line.substr(cuts[3]); 365 365 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(); 367 367 break; 368 368 } … … 412 412 // add this gene to the beginning of the second parent genotype 413 413 child2 = gene + parent2; 414 chg2 = (float)parent2.len () / (float)child2.len();414 chg2 = (float)parent2.length() / (float)child2.length(); 415 415 // do the same for second parent 416 416 choice = rndUint(fB_GenoHelpers::geneCount(parent2)); 417 417 gene = fB_GenoHelpers::getGene(choice, parent2, start, end); 418 418 child1 = gene + parent1; 419 chg1 = (float)parent1.len () / (float)child1.len();419 chg1 = (float)parent1.length() / (float)child1.length(); 420 420 break; 421 421 } … … 523 523 free(g1); 524 524 free(g2); 525 if (child1.len () > 0 && child2.len() == 0)525 if (child1.length() > 0 && child2.length() == 0) 526 526 { 527 527 child1 = strdims + "\n" + child1; … … 529 529 g2 = strdup(""); 530 530 } 531 else if (child2.len () > 0 && child1.len() == 0)531 else if (child2.length() > 0 && child1.length() == 0) 532 532 { 533 533 child2 = strdims + "\n" + child2; -
cpp/frams/genetics/fF/fF_genotype.h
r841 r973 1 1 // This file is a part of Framsticks SDK. http://www.framsticks.com/ 2 // Copyright (C) 1999-20 17Maciej Komosinski and Szymon Ulatowski.2 // Copyright (C) 1999-2020 Maciej Komosinski and Szymon Ulatowski. 3 3 // See LICENSE.txt for details. 4 4 … … 36 36 SString s = serialized; 37 37 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())); 39 39 } 40 40 -
cpp/frams/genetics/fH/fH_general.cpp
r966 r973 214 214 while (genotype.getNextToken(pos, line, '\n')) 215 215 { 216 if (line.len () > 0)216 if (line.length() > 0) 217 217 { 218 218 int res = processLine(line, linenumber, lastpos, pos - 1); -
cpp/frams/genetics/fL/fL_general.cpp
r857 r973 1 1 // This file is a part of Framsticks SDK. http://www.framsticks.com/ 2 // Copyright (C) 1999-20 18Maciej Komosinski and Szymon Ulatowski.2 // Copyright (C) 1999-2020 Maciej Komosinski and Szymon Ulatowski. 3 3 // See LICENSE.txt for details. 4 4 … … 76 76 { 77 77 // if position exceeds length then return false 78 if (pos >= src.len ()) return false;78 if (pos >= src.length()) return false; 79 79 int opencount = -1; 80 80 int i = pos; 81 for (; i < src.len (); i++)81 for (; i < src.length(); i++) 82 82 { 83 83 // token cannot contain branching parenthesis … … 169 169 SString temp; 170 170 temp = token.substr(tokpos); 171 temp = temp.substr(0, temp.len () - 1);171 temp = temp.substr(0, temp.length() - 1); 172 172 173 173 // if word has parameters … … 199 199 // if string is empty, then evaluate this with 0 200 200 // if sequence could not be evaluated, then return error 201 if (seq.len () > 0)201 if (seq.length() > 0) 202 202 { 203 203 eval = new MathEvaluation(numparams); … … 217 217 } 218 218 } 219 else if (word->npar == 0 && temp.len () > 0)219 else if (word->npar == 0 && temp.length() > 0) 220 220 { 221 221 SString message = "Too many parameters for word: "; … … 351 351 { 352 352 // if word already exist, then return error 353 if (this->name.len () == 0)353 if (this->name.length() == 0) 354 354 { 355 355 logMessage("fL_Word", "processDefinition", LOG_ERROR, "Axiom name is empty"); … … 456 456 switch (type) 457 457 { 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 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; 480 480 } 481 481 Param par(tab); … … 573 573 while (genotype.getNextToken(pos, line, '\n')) 574 574 { 575 if (line.len () > 0)575 if (line.length() > 0) 576 576 { 577 577 // words can be defined in the beginning of genotype … … 851 851 { 852 852 SString t = par.getString(q); 853 if (t.len () > 0)853 if (t.length() > 0) 854 854 { 855 855 fL_Word *attrword = NULL; … … 957 957 } 958 958 double partprop = (ppar.getDoubleById(fL_part_names[i]) * alterationcount + 959 959 currval) / (alterationcount + 1.0); 960 960 ppar.setDoubleById(fL_part_names[i], partprop); 961 961 } … … 1097 1097 delete newpart; 1098 1098 logMessage("fL_Builder", "developModel", LOG_ERROR, 1099 1099 "Error parsing word parameter"); 1100 1100 return 1; 1101 1101 } … … 1124 1124 { 1125 1125 logMessage("fL_Builder", "developModel", LOG_ERROR, 1126 1126 "Error parsing word parameter"); 1127 1127 delete newjoint; 1128 1128 return 1; … … 1162 1162 else if (word->name == "C") 1163 1163 { 1164 connsbuffer.push_back({ w, currstate.currneuron});1164 connsbuffer.push_back({ w, currstate.currneuron }); 1165 1165 } 1166 1166 else if (word->name.startsWith("rot")) … … 1182 1182 if (word->name == "rotX") 1183 1183 { 1184 rotmatrix.rotate(Pt3D(rot, 0,0));1184 rotmatrix.rotate(Pt3D(rot, 0, 0)); 1185 1185 } 1186 1186 else if (word->name == "rotY") 1187 1187 { 1188 rotmatrix.rotate(Pt3D(0, rot,0));1188 rotmatrix.rotate(Pt3D(0, rot, 0)); 1189 1189 } 1190 1190 else if (word->name == "rotZ") 1191 1191 { 1192 rotmatrix.rotate(Pt3D(0, 0,rot));1192 rotmatrix.rotate(Pt3D(0, 0, rot)); 1193 1193 } 1194 1194 currstate.direction = rotmatrix.transform(currstate.direction); … … 1212 1212 { 1213 1213 if (connsbuffer[i].second == NULL || 1214 1214 (connsbuffer[i].second->getClass()->getPreferredInputs() != -1 && 1215 1215 connsbuffer[i].second->getInputCount() >= 1216 1216 connsbuffer[i].second->getClass()->getPreferredInputs())) … … 1225 1225 SString attr = par.getStringById(FL_PE_CONN_ATTR); 1226 1226 fL_Word *attractor = NULL; 1227 if (attr.len () > 0)1227 if (attr.length() > 0) 1228 1228 { 1229 1229 createWord(attr, attractor, 0, (*connsbuffer[i].first)->begin, (*connsbuffer[i].first)->end); … … 1236 1236 { 1237 1237 logMessage("fL_Builder", "developModel", LOG_ERROR, 1238 1238 "Error parsing word parameter"); 1239 1239 delete attractor; 1240 1240 return 1; … … 1245 1245 connsbuffer[i].second->addInput(neu, weight); 1246 1246 if (using_mapping) neu->addMapping( 1247 1248 1247 IRange((*connsbuffer[i].first)->begin, 1248 (*connsbuffer[i].first)->end)); 1249 1249 } 1250 1250 else … … 1252 1252 connsbuffer[i].second->addInput(connsbuffer[i].second, weight); 1253 1253 if (using_mapping) neu->addMapping( 1254 1255 1254 IRange((*connsbuffer[i].first)->begin, 1255 (*connsbuffer[i].first)->end)); 1256 1256 } 1257 1257 delete attractor; … … 1286 1286 m->open(using_checkpoints); 1287 1287 bool wordsexceeded = false; 1288 for (; t <= time; t += timestamp)1288 for (; t <= time; t += timestamp) 1289 1289 { 1290 1290 alterTimedProperties(t); // always alter timed properties in the beginning … … 1293 1293 { 1294 1294 iterate(t); 1295 curriter +=1.0;1295 curriter += 1.0; 1296 1296 } 1297 1297 if (using_checkpoints) … … 1362 1362 { 1363 1363 int count = genotype.size(); 1364 for (fL_Rule *rul : rules)1364 for (fL_Rule *rul : rules) 1365 1365 { 1366 1366 count += rul->objsucc.size(); … … 1373 1373 { 1374 1374 for (std::vector<fL_Rule *>::iterator it = rules.begin(); 1375 1375 it != rules.end(); it++) 1376 1376 { 1377 1377 std::vector<fL_Rule *>::iterator it2 = it; … … 1393 1393 { 1394 1394 if ((*it)->condeval->getStringifiedRPN() == 1395 1395 (*it2)->condeval->getStringifiedRPN()) 1396 1396 { 1397 1397 todelete = true; -
cpp/frams/genetics/fL/fL_oper.cpp
r935 r973 285 285 switch (method) 286 286 { 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(); 299 311 break; 300 312 } 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); 376 370 } 377 371 else … … 380 374 newrule->condeval->mutateConditional(); 381 375 } 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 416 545 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 else445 {446 delete (*it);447 list->erase(it);448 }449 break;450 }451 // else add word452 }453 // else add word454 }455 else456 {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 else465 {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 word477 }478 [[fallthrough]];479 case FL_ADD_WORD:480 {481 int numpars = 0;482 int tmp = 0;483 546 std::list<fL_Word *> *list = selectRandomSequence(creature, numpars, tmp); 484 547 int rndid = rndUint(list->size()); 485 548 std::list<fL_Word *>::iterator it = list->begin(); 486 549 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); 509 563 } 510 564 else 511 565 { 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 558 583 { 559 584 delete (*selectedword); … … 562 587 addWord(list, worddef, selectedword); 563 588 } 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) 573 615 { 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); 575 622 } 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; 581 626 } 582 627 else 583 628 { 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()) 610 630 { 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(); 614 638 if (w->npar > 0) 615 639 { 616 640 int rndattr = rndUint(w->npar); 617 if (!w->parevals[rndattr])641 for (int i = 0; i < w->npar; i++) 618 642 { 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 } 620 653 } 621 w->parevals[rndattr]->mutate(false, false); 654 622 655 } 623 strattractor = w->stringify( true);656 strattractor = w->stringify(false); 624 657 par.setStringById(FL_PE_CONN_ATTR, strattractor); 625 658 delete w; 626 659 } 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 } 674 674 } 675 675 … … 702 702 } 703 703 else if (to->words.find(fromword->name.c_str()) != to->words.end() && 704 704 to->words[fromword->name.c_str()]->npar == fromword->npar) // if there is already same word with same number of parameters 705 705 { 706 706 fL_Word *newword = new fL_Word(); … … 710 710 } 711 711 for (std::unordered_map<std::string, fL_Word *>::iterator it = to->words.begin(); 712 712 it != to->words.end(); it++) 713 713 { // find word with same number of parameters 714 714 if (fromword->npar == it->second->npar && map.find(fromword->name.c_str()) == map.end() && !it->second->builtin) … … 774 774 std::string form; 775 775 if (w->builtin && w->name == "N" 776 776 && strcmp(par.id(i), FL_PE_NEURO_DET) == 0) 777 777 { 778 778 SString res = origpar.getStringById(FL_PE_NEURO_DET); … … 781 781 } 782 782 else if (w->builtin && w->name == "C" 783 783 && strcmp(par.id(i), FL_PE_CONN_ATTR) == 0) 784 784 { 785 785 SString strattractor = origpar.getStringById(FL_PE_CONN_ATTR); 786 if (strattractor.len () > 0)786 if (strattractor.length() > 0) 787 787 { 788 788 fL_Word *tmp = NULL; -
cpp/frams/genetics/fS/fS_general.cpp
r969 r973 99 99 if (separatorIndex == -1) 100 100 { 101 keyLength = keyValue.len ();101 keyLength = keyValue.length(); 102 102 value = DEFAULT_NEURO_CONNECTION_WEIGHT; 103 103 } else 104 104 { 105 105 keyLength = separatorIndex; 106 size_t valueLength = keyValue.len () - (separatorIndex);106 size_t valueLength = keyValue.length() - (separatorIndex); 107 107 value = fS_stod(buffer + separatorIndex + 1, start, &valueLength); 108 108 } … … 859 859 { 860 860 SString geno; 861 geno. memoryHint(100); // Provide a small buffer from the start to improve performance861 geno.reserve(100); // Provide a small buffer from the start to improve performance 862 862 startNode->getGeno(geno); 863 863 return geno; -
cpp/frams/model/autoname.cpp
r534 r973 1 1 // This file is a part of Framsticks SDK. http://www.framsticks.com/ 2 // Copyright (C) 1999-20 15Maciej Komosinski and Szymon Ulatowski.2 // Copyright (C) 1999-2020 Maciej Komosinski and Szymon Ulatowski. 3 3 // See LICENSE.txt for details. 4 4 … … 11 11 SString t; 12 12 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 { 16 16 t += ' '; 17 17 t += last; 18 18 } 19 19 return t; 20 20 } … … 42 42 unsigned int s1 = 0, s2 = 0, s3 = 0; 43 43 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; } 46 46 char* t = buf; 47 47 t = cat_syl(t, s1); … … 71 71 for (i = 0; i <= pp; i++) 72 72 { 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++); 75 75 } 76 76 *out = 0; … … 100 100 if (model.getPartCount() > 0) 101 101 { 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); 103 103 poz = 0; 104 104 for (i = 0; i <= cialo; i++) // budowanie "opisu" ciala 105 105 { 106 nextpoz = ((model.getPartCount()) *(i + 1)) / (cialo + 1) - 1;106 nextpoz = ((model.getPartCount()) * (i + 1)) / (cialo + 1) - 1; 107 107 w = 1.0; 108 108 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)]; 110 110 } 111 111 tmpc[i] = 0; … … 117 117 if (model.getNeuroCount() > 0) 118 118 { 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); 120 120 poz = 0; 121 121 for (i = 0; i <= mozg; i++) // budowanie "opisu" mozgu 122 122 { 123 nextpoz = (model.getNeuroCount() *(i + 1)) / (mozg + 1) - 1;123 nextpoz = (model.getNeuroCount() * (i + 1)) / (mozg + 1) - 1; 124 124 wint = 0; 125 125 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)]; 127 127 } 128 128 tmpm[i] = 0; -
cpp/frams/model/modelparts.cpp
r952 r973 149 149 SString t; 150 150 t = getDescription(); 151 if (t.len ()) t += "\n\n";151 if (t.length()) t += "\n\n"; 152 152 t += "Characteristics:\n"; 153 153 if (getPreferredInputs()) … … 171 171 if (p.getPropCount()) 172 172 { 173 if (t.len ()) t += "\n\n";173 if (t.length()) t += "\n\n"; 174 174 t += "Properties:\n"; 175 175 const char *h; … … 341 341 { 342 342 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; } 344 344 return ret; 345 345 } … … 372 372 int Neuro::addInput(Neuro *child, double weight, const SString *info) 373 373 { 374 inputs += NInput(child, weight, (info && (info->len ())) ? new SString(*info) : 0);374 inputs += NInput(child, weight, (info && (info->length())) ? new SString(*info) : 0); 375 375 child->parentcount++; 376 376 if (child->parentcount == 1) { child->parent = this; } … … 759 759 ParamEntry entries[] = { 760 760 { "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) } }; 762 762 #undef FIELDSTRUCT 763 for (auto& e : entries) add(&e);763 for (auto& e : entries) add(&e); 764 764 765 765 #define FIELDSTRUCT Neuro … … 804 804 { 805 805 #ifndef SDK_WITHOUT_FRAMS 806 NeuroNetImpl::getLiveNeuroObject(this, ret);806 NeuroNetImpl::getLiveNeuroObject(this, ret); 807 807 #endif 808 808 } -
cpp/frams/neuro/impl/neuroimpl-fuzzy-f0.cpp
r827 r973 1 1 // This file is a part of Framsticks SDK. http://www.framsticks.com/ 2 // Copyright (C) 1999-20 15Maciej Komosinski and Szymon Ulatowski.2 // Copyright (C) 1999-2020 Maciej Komosinski and Szymon Ulatowski. 3 3 // See LICENSE.txt for details. 4 4 … … 83 83 int FuzzyF0String::convertStrToRules(const SString& str, const int ruledef[], int **rules, int setsNr, int rulesNr, int &maxOutputNr) 84 84 { 85 int pos = 0, j, k, len = str.len ();85 int pos = 0, j, k, len = str.length(); 86 86 int dNr = 0, sNr = 0; 87 87 int inNr, outNr; //number of inputs/outputs and corresponding fuzzy sets -
cpp/frams/neuro/impl/neuroimpl-fuzzy.cpp
r907 r973 1 1 // This file is a part of Framsticks SDK. http://www.framsticks.com/ 2 // Copyright (C) 1999-20 15Maciej Komosinski and Szymon Ulatowski.2 // Copyright (C) 1999-2020 Maciej Komosinski and Szymon Ulatowski. 3 3 // See LICENSE.txt for details. 4 4 … … 21 21 22 22 //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)) 24 24 return 0; //error 25 25 -
cpp/frams/neuro/neurofactory.cpp
r935 r973 103 103 } 104 104 } 105 if (removed.len ())105 if (removed.length()) 106 106 logPrintf("NeuroFactory", "removeUninmplemented", LOG_INFO, 107 107 "Removed Neuro classes: %s", removed.c_str()); -
cpp/frams/neuro/neurolibparam.cpp
r790 r973 1 1 // This file is a part of Framsticks SDK. http://www.framsticks.com/ 2 // Copyright (C) 1999-20 15Maciej Komosinski and Szymon Ulatowski.2 // Copyright (C) 1999-2020 Maciej Komosinski and Szymon Ulatowski. 3 3 // See LICENSE.txt for details. 4 4 … … 33 33 static bool isGoodName(const SString& name) 34 34 { 35 for (int i = 0; i < name.len (); i++)35 for (int i = 0; i < name.length(); i++) 36 36 if (!isalnum(name[i])) return false; 37 37 return true; -
cpp/frams/param/multiparamload.cpp
r720 r973 1 1 // This file is a part of Framsticks SDK. http://www.framsticks.com/ 2 // Copyright (C) 1999-20 18Maciej Komosinski and Szymon Ulatowski.2 // Copyright (C) 1999-2020 Maciej Komosinski and Szymon Ulatowski. 3 3 // See LICENSE.txt for details. 4 4 … … 158 158 } 159 159 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] == ':')) 163 163 { 164 164 unexpected_line = 0; 165 165 lastunknown = 0; 166 lastunknown = buf.substr(0, buf.len () - 1);166 lastunknown = buf.substr(0, buf.length() - 1); 167 167 lastobject.setEmpty(); 168 168 FOREACH(ExtObject*, o, objects) … … 193 193 thisfilename ? SString::sprintf(" while reading '%s'", thisfilename).c_str() : ""); 194 194 } 195 195 break; 196 196 197 197 case 1: … … 293 293 if (stat == OnError) 294 294 { 295 abort();296 return 0;295 abort(); 296 return 0; 297 297 } 298 298 return 1; -
cpp/frams/param/mutableparam.cpp
r884 r973 1 1 // This file is a part of Framsticks SDK. http://www.framsticks.com/ 2 // Copyright (C) 1999-20 19Maciej Komosinski and Szymon Ulatowski.2 // Copyright (C) 1999-2020 Maciej Komosinski and Szymon Ulatowski. 3 3 // See LICENSE.txt for details. 4 4 … … 33 33 int MutableParam::findGroup(const SString name, int ignoreprefix) 34 34 { 35 int skipprefix = grprefix.len () ? grprefix.len() + 2 : 0;35 int skipprefix = grprefix.length() ? grprefix.length() + 2 : 0; 36 36 for (int i = 0; i < groups.size(); i++) 37 37 { … … 57 57 { 58 58 tmp = grprefix; 59 if (tmp.len ()) tmp += ": ";59 if (tmp.length()) tmp += ": "; 60 60 tmp += gname; 61 61 } -
cpp/frams/param/param.cpp
r950 r973 1 1 // This file is a part of Framsticks SDK. http://www.framsticks.com/ 2 // Copyright (C) 1999-20 19Maciej Komosinski and Szymon Ulatowski.2 // Copyright (C) 1999-2020 Maciej Komosinski and Szymon Ulatowski. 3 3 // See LICENSE.txt for details. 4 4 … … 56 56 int j; 57 57 for (int i = 0; i < n; i++) 58 if ((!(flags(i) &PARAM_READONLY))58 if ((!(flags(i) & PARAM_READONLY)) 59 59 && (*type(i) != 'p')) 60 60 { … … 71 71 ExtValue v; 72 72 for (int i = 0; i < n; i++) 73 if ((!(flags(i) &PARAM_READONLY))73 if ((!(flags(i) & PARAM_READONLY)) 74 74 && (*type(i) != 'p')) 75 75 { … … 178 178 else 179 179 { 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()); 181 181 } 182 182 } … … 303 303 int ParamInterface::saveprop(VirtFILE* f, int i, const char* p, bool force) 304 304 { 305 if ((flags(i) &PARAM_DONTSAVE) && (!force)) return 0;305 if ((flags(i) & PARAM_DONTSAVE) && (!force)) return 0; 306 306 const char *typ = type(i); 307 307 if (*typ == 'p') return 0; … … 323 323 quoteTilde(ws); 324 324 w = ws.c_str(); 325 if (ws.len () > 50) cr = 1;325 if (ws.length() > 50) cr = 1; 326 326 else for (t = w; *t; t++) if ((*t == 10) || (*t == 13)) { cr = 1; break; } 327 327 if (cr) f->Vputs("~\n"); … … 334 334 { 335 335 SString ret = getName(); 336 ret +=".";337 ret +=id(prop);336 ret += "."; 337 ret += id(prop); 338 338 return ret; 339 339 } … … 342 342 { 343 343 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) 347 347 return name_dot_prop; 348 348 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; 353 353 } 354 354 … … 394 394 // t+=SString(getName()); t+=':'; 395 395 for (i = 0; p = id(i); i++) 396 if (!((fl = flags(i)) &PARAM_DONTSAVE))396 if (!((fl = flags(i)) & PARAM_DONTSAVE)) 397 397 { 398 398 if (defdata && isequal(i, defdata)) … … 469 469 nameDotPropertyForMessages(i).c_str(), 470 470 ::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", 472 472 ::sstringDelimitAndShorten(actual, 30, show_length, quote, quote).c_str() 473 473 ); … … 583 583 else 584 584 seen[i] = true; 585 if (!(flags(i) &PARAM_DONTLOAD))585 if (!(flags(i) & PARAM_DONTLOAD)) 586 586 { 587 587 if (p0[p_len + 1] == '~') … … 600 600 int ch; while ((ch = f->Vgetc()) != EOF) if (ch == '\n') break; 601 601 unquoteTilde(s); 602 if (options.linenum && (flags(i) &PARAM_LINECOMMENT))602 if (options.linenum && (flags(i) & PARAM_LINECOMMENT)) 603 603 s = SString::sprintf("@file %s\n@line %d\n", f->VgetPath(), *options.linenum + 1) + s; 604 604 setFromString(i, s.c_str(), false); … … 943 943 if (err != NULL) 944 944 logPrintf("SimpleAbstractParam", "sanityCheck", LOG_ERROR, 945 945 "Invalid ParamEntry for %s (%s)", nameDotPropertyForMessages(i).c_str(), err); 946 946 } 947 947 #endif … … 1054 1054 ExtValue v; 1055 1055 ParamEntry *pe = entry(i); 1056 if (pe->flags &PARAM_READONLY) return PSET_RONLY;1056 if (pe->flags & PARAM_READONLY) return PSET_RONLY; 1057 1057 paInt xcopy = x; //only needed for messageOnExceedRange(): retain original, requested value of x because it may be changed below 1058 1058 paInt mn = 0, mx = 0, de = 0; … … 1088 1088 ExtValue v; 1089 1089 ParamEntry *pe = entry(i); 1090 if (pe->flags &PARAM_READONLY) return PSET_RONLY;1090 if (pe->flags & PARAM_READONLY) return PSET_RONLY; 1091 1091 double xcopy = x; //only needed for messageOnExceedRange(): retain original, requested value of x because it may be changed below 1092 1092 double mn = 0, mx = 0, de = 0; … … 1124 1124 const SString *xx = &x; 1125 1125 ParamEntry *pe = entry(i); 1126 if (pe->flags &PARAM_READONLY) return PSET_RONLY;1126 if (pe->flags & PARAM_READONLY) return PSET_RONLY; 1127 1127 SString xcopy = x; //only needed for messageOnExceedRange(): retain original, requested value of x because it may be changed below 1128 1128 const char* t = pe->type + 1; … … 1132 1132 if (sscanf(t, "%d %d", &mn, &mx) == 2) //using getMinMax would also get default value, which is not needed here 1133 1133 { 1134 if ((x.len () > mx) && (mx > 0))1134 if ((x.length() > mx) && (mx > 0)) 1135 1135 { 1136 1136 vs = x.substr(0, mx); … … 1163 1163 ExtValue v; 1164 1164 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) 1167 1167 { 1168 1168 ExtObject o = getObject(i); … … 1200 1200 SANITY_CHECK(i); 1201 1201 ParamEntry *pe = entry(i); 1202 if (pe->flags &PARAM_READONLY) return PSET_RONLY;1202 if (pe->flags & PARAM_READONLY) return PSET_RONLY; 1203 1203 ExtValue xcopy = x; //only needed for messageOnExceedRange(): retain original, requested value of x because it may be changed below 1204 1204 if (pe->fun2) … … 1255 1255 { 1256 1256 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(); } 1258 1258 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(); } 1261 1261 while (lf >= beg) if ((*lf == '\n') || (*lf == '\r')) lf--; else break; 1262 1262 len = (int)(lf - beg) + 1; … … 1278 1278 SString tmpvalue; 1279 1279 bool parse_failed = false; 1280 if (options.offset >= s.len ()) return fields_loaded;1280 if (options.offset >= s.length()) return fields_loaded; 1281 1281 t = s.c_str() + options.offset; 1282 1282 … … 1316 1316 if (field_end == t) // skip empty value 1317 1317 { 1318 t++; if (i >=0) i++;1318 t++; if (i >= 0) i++; 1319 1319 continue; 1320 1320 } … … 1332 1332 #ifdef WARN_MISSING_NAME 1333 1333 else // no parameter name 1334 1334 { 1335 1335 #ifdef SAVE_SELECTED_NAMES 1336 1336 if ((i < 0) // field after unknown field 1337 1338 || !(flags(i)&PARAM_CANOMITNAME)) // valid field but it can't be skipped1337 || (i >= getPropCount()) // field after last field 1338 || !(flags(i) & PARAM_CANOMITNAME)) // valid field but it can't be skipped 1339 1339 #endif 1340 1340 { … … 1344 1344 logPrintf("Param", "loadSingleLine", LOG_WARN, "Value after the last property of '%s'", getName()); 1345 1345 } 1346 1346 } 1347 1347 //else skipping a skippable field 1348 1348 #endif … … 1364 1364 ret = setFromString(i, value, true); 1365 1365 fields_loaded++; 1366 if (ret &PSET_PARSEFAILED)1366 if (ret & PSET_PARSEFAILED) 1367 1367 parse_failed = true; 1368 1368 *(char*)valstop = remember; -
cpp/frams/util/extvalue.cpp
r940 r973 326 326 { 327 327 SString tmp = getString(); 328 if (tmp.len () > 30) tmp = tmp.substr(0, 30) + "...";328 if (tmp.length() > 30) tmp = tmp.substr(0, 30) + "..."; 329 329 if (type == TString) tmp = SString("\"") + tmp + SString("\""); 330 330 logPrintf("ExtValue", "getObjectTarget", LOG_WARN, "%s object expected, %s found", classname, tmp.c_str()); … … 614 614 return; 615 615 case TDouble: 616 setDouble(double(getInt()) *src.getDouble());616 setDouble(double(getInt()) * src.getDouble()); 617 617 return; 618 618 default:; … … 790 790 // ^-cur ^-next 791 791 // ^^^^^^^^^^___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; 793 793 int type = 0; 794 794 … … 1401 1401 err->message = args[0].getString(); 1402 1402 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()); 1404 1404 *ret = makeDynamicObject(err); 1405 1405 } -
cpp/frams/util/sstring-simple.cpp
r970 r973 8 8 void SString::initEmpty() 9 9 { 10 txt = NULL; used = 0; size= 0;10 txt = NULL; used = 0; allocated = 0; 11 11 } 12 12 … … 18 18 SString::~SString() 19 19 { 20 re size(0);20 reallocate(0); 21 21 } 22 22 … … 36 36 SString::SString(SString&& from) 37 37 { 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; 40 40 } 41 41 … … 46 46 } 47 47 48 void SString::re size(int newsize)49 { 50 if (newsize == size) return;48 void SString::reallocate(int newsize) 49 { 50 if (newsize == allocated) return; 51 51 txt = (char*)realloc(txt, newsize); 52 size= newsize;53 } 54 55 void SString::ensure Size(int needed)56 { 57 if ( size> needed) return;58 re size((size> 0) ? (needed + needed / 2 + 1) : (needed + 1));52 allocated = newsize; 53 } 54 55 void SString::ensureAllocated(int needed) 56 { 57 if (allocated > needed) return; 58 reallocate((allocated > 0) ? (needed + needed / 2 + 1) : (needed + 1)); 59 59 } 60 60 61 61 char *SString::directWrite(int ensuresize) 62 62 { 63 ensure Size(ensuresize);63 ensureAllocated(ensuresize); 64 64 appending = used; 65 65 return txt; … … 68 68 char *SString::directAppend(int maxappend) 69 69 { 70 ensure Size(used + maxappend);70 ensureAllocated(used + maxappend); 71 71 appending = used; 72 72 return txt + appending; … … 78 78 else txt[newlength] = 0; 79 79 used = newlength; 80 assert(used < size);80 assert(used < allocated); 81 81 } 82 82 … … 86 86 else txt[appending + newappend] = 0; 87 87 used = appending + newappend; 88 assert(used < size);88 assert(used < allocated); 89 89 } 90 90 … … 102 102 { 103 103 if (!n) return; 104 ensure Size(used + n);104 ensureAllocated(used + n); 105 105 memmove(txt + used, t, n); 106 106 used += n; … … 110 110 void SString::operator+=(const SString&s) 111 111 { 112 append(s.c_str(), s.len ());112 append(s.c_str(), s.length()); 113 113 } 114 114 … … 116 116 { 117 117 SString ret; 118 ret.reserve(len () + s.len());118 ret.reserve(length() + s.length()); 119 119 ret = *this; 120 120 ret += s; … … 130 130 if (chlen) 131 131 { 132 ensure Size(chlen);132 ensureAllocated(chlen); 133 133 memmove(txt, ch, chlen); 134 134 txt[chlen] = 0; … … 153 153 { 154 154 if (&s == this) return; 155 copyFrom(s.c_str(), s.len ());155 copyFrom(s.c_str(), s.length()); 156 156 } 157 157 158 158 /////////////////////////////////////// 159 159 160 SString SString::substr(int begin, int length) const161 { 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);160 SString 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); 167 167 } 168 168 … … 172 172 { 173 173 if (this == &s) return true; 174 if (len () != s.len()) return false;174 if (length() != s.length()) return false; 175 175 return strcmp(getPtr(), s.getPtr()) == 0; 176 176 } … … 198 198 bool SString::getNextToken(int& pos, SString &token, char separator) const 199 199 { 200 if (pos >= len ()) { token = 0; return false; }200 if (pos >= length()) { token = 0; return false; } 201 201 int p1 = pos, p2; 202 202 const char *t1 = getPtr() + pos; 203 203 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(); 205 205 strncpy(token.directWrite(p2 - p1), t1, p2 - p1); 206 206 token.endWrite(p2 - p1); … … 254 254 char* p = ret.directWrite(size); 255 255 assert(p != NULL); 256 size = ret. directMaxLen() + 1;256 size = ret.capacity() + 1; 257 257 /* Try to print in the allocated space. */ 258 258 va_start(ap, format); -
cpp/frams/util/sstring-simple.h
r955 r973 14 14 private: 15 15 char *txt; ///< string buffer or NULL for empty string 16 int size; ///< allocated memory (including \0)16 int allocated; ///< allocated memory (including \0) 17 17 int used; ///< string length 18 18 int appending; ///< append mode, changes can occur after character # 'appending' … … 20 20 void initEmpty(); 21 21 void copyFrom(SString &from); ///< copy from SString 22 void re size(int newsize);23 void ensure Size(int needed);22 void reallocate(int newsize); 23 void ensureAllocated(int needed); 24 24 const char* getPtr() const { return txt ? txt : ""; } 25 25 … … 34 34 35 35 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; } 38 38 #ifdef _MSC_VER 39 39 void operator delete(void* mem, void* t) {} 40 40 #endif 41 void* operator new(size_t s) { return malloc(sizeof(SString)); }41 void* operator new(size_t s) { return malloc(sizeof(SString)); } 42 42 void operator delete(void* mem) { free(mem); } 43 43 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 45 46 void shrink(); ///< free unnecessary buffer 46 void reserve(int needed) { ensureSize(needed); } ///< like in std::string47 void reserve(int cap) { ensureAllocated(cap + 1); } ///< like in std::string 47 48 48 49 /// after this call, you can modify sstring directly. … … 87 88 void endAppend(int appendlength = -1); 88 89 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() 91 91 92 92 /// find a character in SString. -
cpp/frams/util/sstring.cpp
r970 r973 163 163 } 164 164 165 void SString::memoryHint(int howbig)166 {167 detachCopy(howbig);168 }169 170 165 void SString::detachEmpty(int ensuresize) 171 166 { … … 201 196 char *SString::directWrite(int ensuresize) 202 197 { 203 if (ensuresize < 0) ensuresize = len ();198 if (ensuresize < 0) ensuresize = length(); 204 199 REF_LOCK; 205 200 detachCopy(ensuresize); … … 259 254 void SString::operator+=(const SString&s) 260 255 { 261 append(s.c_str(), s.len ());256 append(s.c_str(), s.length()); 262 257 } 263 258 … … 298 293 /////////////////////////////////////// 299 294 300 SString SString::substr(int begin, int length) const301 { 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);295 SString 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); 307 302 } 308 303 … … 337 332 bool SString::getNextToken(int& pos, SString &token, char separator) const 338 333 { 339 if (pos >= len ()) { token = 0; return false; }334 if (pos >= length()) { token = 0; return false; } 340 335 int p1 = pos, p2; 341 336 const char *t1 = buf->txt + pos; 342 337 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(); 344 339 strncpy(token.directWrite(p2 - p1), t1, p2 - p1); 345 340 token.endWrite(p2 - p1); … … 401 396 char* p = ret.directWrite(size); 402 397 assert(p != NULL); 403 size = ret. directMaxLen() + 1;398 size = ret.capacity() + 1; 404 399 /* Try to print in the allocated space. */ 405 400 va_start(ap, format); -
cpp/frams/util/sstring.h
r955 r973 1 1 // This file is a part of Framsticks SDK. http://www.framsticks.com/ 2 // Copyright (C) 1999-20 15Maciej Komosinski and Szymon Ulatowski.2 // Copyright (C) 1999-2020 Maciej Komosinski and Szymon Ulatowski. 3 3 // See LICENSE.txt for details. 4 4 … … 85 85 void operator delete(void* mem) { free(mem); } 86 86 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 88 89 void shrink(); ///< free unnecessary buffer 89 void reserve(int needed) { ensureSize(needed); } ///< like in std::string90 void reserve(int needed) { detachCopy(needed); } ///< like in std::string 90 91 91 92 /// after this call, you can modify sstring directly. … … 129 130 /// t.endAppend(bytecount);</CODE> 130 131 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() 136 133 137 134 /// find a character in SString. -
cpp/frams/util/sstringutils.cpp
r904 r973 1 1 // This file is a part of Framsticks SDK. http://www.framsticks.com/ 2 // Copyright (C) 1999-20 15Maciej Komosinski and Szymon Ulatowski.2 // Copyright (C) 1999-2020 Maciej Komosinski and Szymon Ulatowski. 3 3 // See LICENSE.txt for details. 4 4 … … 79 79 else 80 80 { 81 if (tmp.len () == 0) return 0; // nothing was changed!81 if (tmp.length() == 0) return 0; // nothing was changed! 82 82 tmp += x; 83 83 target = tmp; … … 112 112 else 113 113 { 114 if (tmp.len () == 0) return 0; // nothing was changed!114 if (tmp.length() == 0) return 0; // nothing was changed! 115 115 tmp += x; 116 116 target = tmp; … … 139 139 bool changed = 0; 140 140 SString tmp; 141 tmp. memoryHint(target.len());141 tmp.reserve(target.length()); 142 142 while (*x) 143 143 { … … 160 160 { 161 161 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); 164 164 else 165 165 { … … 169 169 out = before + out + after; 170 170 if (show_length) 171 out += SString::sprintf(" (length %d)", in.len ());171 out += SString::sprintf(" (length %d)", in.length()); 172 172 return out; 173 173 } … … 208 208 else 209 209 { 210 if (tmp.len () == 0) return 0; // nothing was changed!210 if (tmp.length() == 0) return 0; // nothing was changed! 211 211 tmp += x; 212 212 target = tmp; … … 223 223 { 224 224 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(); 228 228 return pos; 229 229 } … … 238 238 p = strFindField(txt, name, e); 239 239 if (p < 0) return SString(); 240 p += name.len () + 1;240 p += name.length() + 1; 241 241 return SString(txt.substr(p, e - p)); 242 242 } … … 248 248 if (p < 0) 249 249 { 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()); 252 252 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(); 255 255 *(t++) = '='; 256 strcpy(t, value.c_str()); t += value.len ();256 strcpy(t, value.c_str()); t += value.length(); 257 257 txt.endAppend(t - b); 258 258 } 259 259 else 260 260 { 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++; 264 264 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)); 275 275 } 276 276 } … … 280 280 { 281 281 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(); 283 283 while ((b < e) && (*b <= ' ')) b++; 284 284 while ((b < e) && (e[-1] <= ' ')) e--; 285 if ((e - b) == s.len ()) return s;285 if ((e - b) == s.length()) return s; 286 286 SString newstring; 287 287 char* t = newstring.directWrite(e - b); … … 291 291 } 292 292 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;293 SString 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; 299 299 return out; 300 300 } … … 318 318 bool matchWildcard(const SString& word, const SString& pattern) 319 319 { 320 if (pattern.len () == 0)321 return word.len () == 0;320 if (pattern.length() == 0) 321 return word.length() == 0; 322 322 int aster = pattern.indexOf('*'); 323 323 if (aster >= 0) … … 325 325 SString before = pattern.substr(0, aster); 326 326 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()))) 332 332 return false; 333 333 return true; … … 339 339 bool matchWildcardList(const SString& word, const SString& patterns) 340 340 { 341 if (patterns.len () == 0)342 return word.len () == 0;341 if (patterns.length() == 0) 342 return word.length() == 0; 343 343 int pos = 0; 344 344 SString pattern; -
cpp/frams/util/sstringutils.h
r929 r973 40 40 int i, next = 0; 41 41 bool first = true; 42 if (!separator.len ()) { result.push_back(text); return; }42 if (!separator.length()) { result.push_back(text); return; } 43 43 while (1) 44 44 { … … 46 46 if (i < 0) 47 47 { 48 if ((next <= text.len ()) || first)48 if ((next <= text.length()) || first) 49 49 result.push_back(text.substr(next)); 50 50 return; … … 55 55 first = false; 56 56 } 57 next = i + separator.len ();57 next = i + separator.length(); 58 58 } 59 59 } -
cpp/frams/vm/framscript.l
r955 r973 116 116 static SString quoteMultiline(const SString &src) 117 117 { 118 int len=src.len ();118 int len=src.length(); 119 119 SString ret; 120 120 ret.reserve((len*11)/10+10); -
cpp/frams/vm/framscript.y
r955 r973 1513 1513 return val.getString(); 1514 1514 SString s=val.getString(); 1515 int len=s.len ();1515 int len=s.length(); 1516 1516 SString ret; 1517 1517 ret.reserve((len*11)/10+10);
Note: See TracChangeset
for help on using the changeset viewer.