Changeset 973 for cpp/frams/model


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/model
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • 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}
Note: See TracChangeset for help on using the changeset viewer.