Ignore:
Timestamp:
04/09/15 23:51:28 (9 years ago)
Author:
Maciej Komosinski
Message:
  • explicit c_str() in SString instead of (const char*) cast
  • genetic converters and GenMan? are now thread-local which enables multi-threaded simulator separation
File:
1 edited

Legend:

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

    r291 r348  
    3434        const char* type=pi.type(i);
    3535        if (*type=='p') continue;
    36         printf("%2d. %8s = %-20s %-3s %-10s  %-10s\n",i,pi.id(i),(const char*)pi.get(i),pi.type(i),pi.name(i),pi.grname(pi.group(i)));
     36        printf("%2d. %8s = %-20s %-3s %-10s  %-10s\n",i,pi.id(i),pi.get(i).c_str(),pi.type(i),pi.name(i),pi.grname(pi.group(i)));
    3737        }
    3838}
     
    4747pi.getMinMax(i,minprop,maxprop,def);
    4848printf("      Change property #%d to random value from range [%g..%g]\n",i,minprop,maxprop);
    49 printf("      Current value of '%s' (%s) is '%s'\n",pi.id(i),pi.name(i),(const char*)pi.get(i));
     49printf("      Current value of '%s' (%s) is '%s'\n",pi.id(i),pi.name(i),pi.get(i).c_str());
    5050char t[100];
    5151sprintf(t,"%g",minprop+(rnd01)*(maxprop-minprop));
    5252printf("      Setting new value... [ using ParamInterface::set() ]\n");
    5353pi.set(i,t);
    54 printf("      The value is now '%s'\n",(const char*)pi.get(i));
     54printf("      The value is now '%s'\n",pi.get(i).c_str());
    5555}
    5656
     
    7979CHANGE_ONE_PROPERTY(p->extraProperties());
    8080p->getModel().close();
    81 printf("\nLet's see f0... (check out part #%d !)\n\n%s\n", p->refno, (const char*)p->getModel().getF0Geno().getGene());
     81printf("\nLet's see f0... (check out part #%d !)\n\n%s\n", p->refno, p->getModel().getF0Geno().getGene().c_str());
    8282}
    8383
     
    9191j->getModel().close();
    9292printf("The Part's position is changed, but everything else stays intact:\n\n%s\n",
    93        (const char*)j->getModel().getF0Geno().getGene());
     93       j->getModel().getF0Geno().getGene().c_str());
    9494}
    9595
     
    104104j->getModel().close();
    105105printf("Position of the second Part referenced by this joint (part #%d) is now changed:\n\n%s\n",
    106        j->part2->refno, (const char*)j->getModel().getF0Geno().getGene());
     106       j->part2->refno, j->getModel().getF0Geno().getGene().c_str());
    107107printf("If no delta fields are defined, they will be computed automatically.\n"
    108108       "You can always delete existing delta values by using Joint::resetDelta().\n"
     
    112112j->resetDelta();
    113113j->getModel().close();
    114 printf("As you can see, Joint's delta fields have altered:\n\n%s\n", (const char*)j->getModel().getF0Geno().getGene());
     114printf("As you can see, Joint's delta fields have altered:\n\n%s\n", j->getModel().getF0Geno().getGene().c_str());
    115115}
    116116
     
    123123j->getModel().close();
    124124printf("f0 is now:\n\n%s\n...so this is %s joint.\n",
    125        (const char*)j->getModel().getF0Geno().getGene(), option?"a delta":"an absolute");
     125       j->getModel().getF0Geno().getGene().c_str(), option?"a delta":"an absolute");
    126126
    127127}
     
    155155CHANGE_ONE_PROPERTY(j->extraProperties());
    156156j->getModel().close();
    157 printf("And after that we have this genotype:\n\n%s\n", (const char*)j->getModel().getF0Geno().getGene());
     157printf("And after that we have this genotype:\n\n%s\n", j->getModel().getF0Geno().getGene().c_str());
    158158}
    159159
     
    178178printf("\nThe most unusual thing is 'details' field (d).\n"
    179179       "It is something like separate object with its own set of properties.\n"
    180        "Currently the value of 'd' is '%s'.\n",(const char*)n->getDetails());
     180       "Currently the value of 'd' is '%s'.\n",n->getDetails().c_str());
    181181
    182182{
    183183NeuroClass* cl=n->getClass();
    184184if (!cl)
    185         printf("It should contain the class name but the meaning of '%s' is unknown\n",(const char*)n->getDetails());
     185        printf("It should contain the class name but the meaning of '%s' is unknown\n",n->getDetails().c_str());
    186186else
    187187{
    188188
    189189printf("'%s' is the class name (Neuro::getClassName() == '%s') and means '%s'.\n",
    190        (const char*)cl->getName(),(const char*)cl->getName(),(const char*)cl->getLongName());
     190       cl->getName().c_str(),cl->getName().c_str(),cl->getLongName().c_str());
    191191printf("Neuro::getClass() gives you information about basic characteristic\n"
    192192       "of the class, that can be analyzed automatically.\n");
     
    208208        p.update();
    209209        n->getModel().close();
    210         printf("After that, 'details' contains the new object: '%s'.\n",(const char*)n->getDetails());
     210        printf("After that, 'details' contains the new object: '%s'.\n",n->getDetails().c_str());
    211211        }
    212212else
     
    224224        NeuroClass* cl=n->getClass(i);
    225225        Param p=cl->getProperties();
    226         printf("%2d.%6s  %-20s  %2d\n",i,(const char*)cl->getName(),(const char*)cl->getLongName(),p.getPropCount());
     226        printf("%2d.%6s  %-20s  %2d\n",i,cl->getName().c_str(),cl->getLongName().c_str(),p.getPropCount());
    227227        }
    228228int cl=rand() % n->getClassCount();
    229 printf("\nLet's change the Neuro's class to '%s'...\n",(const char*)n->getClassName(cl));
     229printf("\nLet's change the Neuro's class to '%s'...\n",n->getClassName(cl).c_str());
    230230n->getModel().open();
    231231n->setClass(n->getClass(cl));
     
    242242if (n->getInputCount()>0)
    243243{
    244         printf("Info for input #0 = \"%s\"\n",(const char*)n->getInputInfo(0));
    245         printf("Info for input #0, field \"%s\" = \"%s\"\n", "abc", (const char*)n->getInputInfo(0,"abc"));
     244        printf("Info for input #0 = \"%s\"\n",n->getInputInfo(0).c_str());
     245        printf("Info for input #0, field \"%s\" = \"%s\"\n", "abc", n->getInputInfo(0,"abc").c_str());
    246246        n->setInputInfo(0,"test",44);
    247247        n->setInputInfo(0,"abc","yeah");
     
    250250n->getModel().close();
    251251printf("The final object description will be then: '%s'\nAnd the full f0 genotype:\n\n%s\n",
    252        (const char*)n->getDetails(), (const char*)n->getModel().getF0Geno().getGene());
     252       n->getDetails().c_str(), n->getModel().getF0Geno().getGene().c_str());
    253253
    254254
     
    257257void findingConverters()
    258258{
    259 GenoConverter *gc=Geno::getConverters().findConverters(0,'1');
     259GenoConverter *gc=Geno::getConverters()->findConverters(0,'1');
    260260if (gc) printf("found converter accepting f1: \"%s\"\n",gc->name);
    261261SListTempl<GenoConverter*> found;
    262 Geno::getConverters().findConverters(&found,-1,'0');
     262Geno::getConverters()->findConverters(&found,-1,'0');
    263263printf("found %d converter(s) producing f0\n",found.size());
    264264}
     
    274274
    275275SString gen(argc>1?argv[1]:"X[|G:1.23]");
    276 if (!strcmp(gen,"-"))
     276if (!strcmp(gen.c_str(),"-"))
    277277        {
    278278        gen=0;
     
    281281        }
    282282Geno g(gen);
    283 printf("\nSource genotype: '%s'\n",(const char*)g.getGene());
     283printf("\nSource genotype: '%s'\n",g.getGene().c_str());
    284284printf("                  ( format %c %s)\n",
    285        g.getFormat(), (const char*)g.getComment());
     285       g.getFormat(), g.getComment().c_str());
    286286
    287287Model m(g);//.getConverted('0'));
     
    292292        return 2;       
    293293        }
    294 printf("Converted to f0:\n%s\n",(const char*)m.getF0Geno().getGene());
     294printf("Converted to f0:\n%s\n",m.getF0Geno().getGene().c_str());
    295295
    296296printf("Model contains: %d part(s)\n"
     
    340340                NeuroItem *ni=n->getNeuroItem(j);
    341341                printf("        item #%d - '%s', conn=%d, weight=%g\n",
    342                        j,(const char*)ni->getDetails(),ni->conn_refno,ni->weight);
     342                       j,ni->getDetails().c_str(),ni->conn_refno,ni->weight);
    343343                }
    344344        }
Note: See TracChangeset for help on using the changeset viewer.