Changeset 348 for cpp/frams/util


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
Location:
cpp/frams/util
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/util/extvalue.cpp

    r337 r348  
    269269                        if (tmp.len() > 30) tmp = tmp.substr(0, 30) + "...";
    270270                        if (type == TString) tmp = SString("\"") + tmp + SString("\"");
    271                         FMprintf("ExtValue", "getObjectTarget", FMLV_WARN, "%s object expected, %s found", classname, (const char*)tmp);
     271                        FMprintf("ExtValue", "getObjectTarget", FMLV_WARN, "%s object expected, %s found", classname, tmp.c_str());
    272272                }
    273273                return NULL;
     
    329329static ExtValue::CompareResult compareString(const SString &a, const SString &b)
    330330{
    331         const char* s1 = (const char*)a;
    332         const char* s2 = (const char*)b;
     331        const char* s1 = a.c_str();
     332        const char* s2 = b.c_str();
    333333        return longsign(strcmp(s1, s2));
    334334}
     
    415415                        if (context->v1 && context->v2)
    416416                                msg += SString::sprintf(": %s %s %s",
    417                                 (const char*)context->v1->typeAndValue(),
     417                                context->v1->typeAndValue().c_str(),
    418418                                cmp_op_names[op - CmpFIRST],
    419                                 (const char*)context->v2->typeAndValue());
    420                 }
    421                 FMprintf("ExtValue", "interpretCompare", FMLV_ERROR, "%s", (const char*)msg);
     419                                context->v2->typeAndValue().c_str());
     420                }
     421                FMprintf("ExtValue", "interpretCompare", FMLV_ERROR, "%s", msg.c_str());
    422422                ret = -1;
    423423        }
     
    448448                {
    449449                case TDouble:
    450                         FMprintf("ExtValue", "add", FMLV_WARN, "Adding %s to %s", (const char*)src.typeAndValue(), (const char*)typeAndValue());
     450                        FMprintf("ExtValue", "add", FMLV_WARN, "Adding %s to %s", src.typeAndValue().c_str(), typeAndValue().c_str());
    451451                        setDouble(double(getInt()) + src.getDouble());
    452452                        return;
     
    487487        default:;
    488488        }
    489         FMprintf("ExtValue", "add", FMLV_ERROR, "Can't add %s to %s", (const char*)src.typeAndValue(), (const char*)typeAndValue());
     489        FMprintf("ExtValue", "add", FMLV_ERROR, "Can't add %s to %s", src.typeAndValue().c_str(), typeAndValue().c_str());
    490490}
    491491
     
    502502                        return;
    503503                case TDouble:
    504                         FMprintf("ExtValue", "subtract", FMLV_WARN, "Subtracting %s from %s", (const char*)src.typeAndValue(), (const char*)typeAndValue());
     504                        FMprintf("ExtValue", "subtract", FMLV_WARN, "Subtracting %s from %s", src.typeAndValue().c_str(), typeAndValue().c_str());
    505505                        setDouble(double(getInt()) - src.getDouble());
    506506                        return;
     
    520520        default:;
    521521        }
    522         FMprintf("ExtValue", "subtract", FMLV_ERROR, "Can't subtract %s from %s", (const char*)src.typeAndValue(), (const char*)typeAndValue());
     522        FMprintf("ExtValue", "subtract", FMLV_ERROR, "Can't subtract %s from %s", src.typeAndValue().c_str(), typeAndValue().c_str());
    523523}
    524524
     
    535535                        return;
    536536                case TDouble:
    537                         FMprintf("ExtValue", "multiply", FMLV_WARN, "Multiplying %s by %s", (const char*)typeAndValue(), (const char*)src.typeAndValue());
     537                        FMprintf("ExtValue", "multiply", FMLV_WARN, "Multiplying %s by %s", typeAndValue().c_str(), src.typeAndValue().c_str());
    538538                        setDouble(double(getInt())*src.getDouble());
    539539                        return;
     
    591591        default:;
    592592        }
    593         FMprintf("ExtValue", "multiply", FMLV_WARN, "Can't multiply %s by %s", (const char*)typeAndValue(), (const char*)src.typeAndValue());
     593        FMprintf("ExtValue", "multiply", FMLV_WARN, "Can't multiply %s by %s", typeAndValue().c_str(), src.typeAndValue().c_str());
    594594}
    595595
     
    621621        if (a == 0.0)
    622622        {
    623                 FMprintf("ExtValue", "divide", FMLV_CRITICAL, "Division by zero: %s/0.0", (const char*)getString());
     623                FMprintf("ExtValue", "divide", FMLV_CRITICAL, "Division by zero: %s/0.0", getString().c_str());
    624624                setInvalid();
    625625        }
     
    630630                if (!finite(tmp))
    631631                {
    632                         FMprintf("ExtValue", "divide", FMLV_CRITICAL, "Overflow %s/%g", (const char*)getString(), a); setInvalid();
     632                        FMprintf("ExtValue", "divide", FMLV_CRITICAL, "Overflow %s/%g", getString().c_str(), a); setInvalid();
    633633                }
    634634                else
     
    652652                        return;
    653653                case TDouble:
    654                         FMprintf("ExtValue", "divide", FMLV_WARN, "Dividing %s by %s", (const char*)typeAndValue(), (const char*)src.typeAndValue());
     654                        FMprintf("ExtValue", "divide", FMLV_WARN, "Dividing %s by %s", typeAndValue().c_str(), src.typeAndValue().c_str());
    655655                        divDouble(src.ddata());
    656656                        return;
     
    674674        default:;
    675675        }
    676         FMprintf("ExtValue", "divide", FMLV_ERROR, "Can't divide %s by %s", (const char*)typeAndValue(), (const char*)src.typeAndValue());
     676        FMprintf("ExtValue", "divide", FMLV_ERROR, "Can't divide %s by %s", typeAndValue().c_str(), src.typeAndValue().c_str());
    677677}
    678678
     
    687687        //            ^-cur     ^-next
    688688        //            ^^^^^^^^^^___sub
    689         const char* begin = (const char*)fmt, *end = begin + fmt.len(), *curr = begin;
     689        const char* begin = fmt.c_str(), *end = begin + fmt.len(), *curr = begin;
    690690        int type = 0;
    691691
     
    733733                switch (type)
    734734                {
    735                 case 'd': a = args.getNext(); ret += SString::sprintf((const char*)sub, a ? a->getInt() : 0); break;
    736                 case 'f': a = args.getNext(); ret += SString::sprintf((const char*)sub, a ? a->getDouble() : 0); break;
    737                 case 's': {a = args.getNext(); SString tmp; if (a) tmp = a->getString(); ret += SString::sprintf((const char*)sub, (const char*)tmp); } break;
     735                case 'd': a = args.getNext(); ret += SString::sprintf(sub.c_str(), a ? a->getInt() : 0); break;
     736                case 'f': a = args.getNext(); ret += SString::sprintf(sub.c_str(), a ? a->getDouble() : 0); break;
     737                case 's': {a = args.getNext(); SString tmp; if (a) tmp = a->getString(); ret += SString::sprintf(sub.c_str(), tmp.c_str()); } break;
    738738                case 't': case 'T':
    739739                {
     
    779779
    780780        case TObj: case TUnknown: case TInvalid:
    781                 FMprintf("ExtValue", "modulo", FMLV_WARN, "Can't apply modulo to %s", (const char*)typeDescription());
     781                FMprintf("ExtValue", "modulo", FMLV_WARN, "Can't apply modulo to %s", typeDescription().c_str());
    782782
    783783        default:;
     
    835835        case TInt: return idata();
    836836        case TDouble: return (int)ddata();
    837         case TString: return getInt((const char*)sdata());
     837        case TString: return getInt(sdata().c_str());
    838838        case TObj:
    839                 FMprintf("ExtValue", "getInt", FMLV_WARN, "Getting integer value from object reference (%s)", (const char*)getString());
     839                FMprintf("ExtValue", "getInt", FMLV_WARN, "Getting integer value from object reference (%s)", getString().c_str());
    840840                return (paInt)(intptr_t)odata().param;
    841841        default:;
     
    850850        case TDouble: return ddata();
    851851        case TInt: return (double)idata();
    852         case TString: return getDouble((const char*)sdata());
     852        case TString: return getDouble(sdata().c_str());
    853853        case TObj:
    854                 FMprintf("ExtValue", "getDouble", FMLV_WARN, "Getting floating point value from object reference (%s)", (const char*)getString());
     854                FMprintf("ExtValue", "getDouble", FMLV_WARN, "Getting floating point value from object reference (%s)", getString().c_str());
    855855                return (double)(intptr_t)odata().param;
    856856        default:;
     
    10951095                ExtValue tmp;
    10961096                ret = tmp.deserialize(ret);
    1097                 ParamInterface *cls = findDeserializableClass(clsname);
     1097                ParamInterface *cls = findDeserializableClass(clsname.c_str());
    10981098                if (cls && (tmp.getType() != TUnknown) && (tmp.getType() != TInvalid))
    10991099                {
     
    11341134                }
    11351135                setEmpty();
    1136                 FMprintf("ExtValue", "deserialize", FMLV_WARN, "object of class \"%s\" could not be deserialized", (const char*)clsname);
     1136                FMprintf("ExtValue", "deserialize", FMLV_WARN, "object of class \"%s\" could not be deserialized", clsname.c_str());
    11371137                return ret;
    11381138        }
  • cpp/frams/util/hashtable.cpp

    r286 r348  
    161161        printf(" %d:",n);
    162162        for (;e;e=e->next)
    163                 printf(" (%x)%s=%p",e->hash,(const char*)e->key,e->value);
     163                printf(" (%x)%s=%p",e->hash,e->key.c_str(),e->value);
    164164        printf("\n");
    165165        }
  • cpp/frams/util/sstring.cpp

    r347 r348  
    251251void SString::operator+=(const SString&s)
    252252{
    253 append((const char*)s,s.len());
     253append(s.c_str(),s.len());
    254254}
    255255
     
    323323int SString::indexOf(const SString & substring,int start) const
    324324{
    325 char *found=strstr(buf->txt+start,((const char*)substring));
     325char *found=strstr(buf->txt+start,substring.c_str());
    326326return found?found-buf->txt:-1;
    327327}
     
    341341int SString::startsWith(const char *pattern) const
    342342{
    343 const char *t=(const char*)(*this);
     343const char *t=this->c_str();
    344344for (;*pattern;pattern++,t++)
    345345        if (*t != *pattern) return 0;
     
    358358{
    359359SString tmp=SString::sprintf("%.15g",d);
    360 if ((!strchr(tmp,'.'))&&(!strchr(tmp,'e'))) tmp+=".0";
     360if ((!strchr(tmp.c_str(),'.'))&&(!strchr(tmp.c_str(),'e'))) tmp+=".0";
    361361return tmp;
    362362}
  • cpp/frams/util/sstring.h

    r286 r348  
    144144int indexOf(const SString & substring,int start=0) const;
    145145
    146 operator const char*() const {return buf->txt;} ///< get SString's readonly buffer
     146const char* c_str() const {return buf->txt;} ///< get SString's readonly buffer
    147147//operator char*() {detachCopy(len()); return buf->txt;} ///< get SString's writable buffer
    148148void operator=(const char*t); ///< assign from const char*
  • cpp/frams/util/sstringutils.cpp

    r319 r348  
    6363int quoteTilde(SString &target)
    6464{
    65         const char* x = target;
     65        const char* x = target.c_str();
    6666        SString tmp;
    6767        char *f;
     
    8888int unquoteTilde(SString &target)
    8989{
    90         const char* x = target;
     90        const char* x = target.c_str();
    9191        SString tmp;
    9292        char *f;
     
    134134bool sstringQuote(SString& target)
    135135{
    136         const char* x = target;
     136        const char* x = target.c_str();
    137137        bool changed = 0;
    138138        SString tmp;
     
    169169int sstringUnquote(SString &target)
    170170{
    171         const char* x = target;
     171        const char* x = target.c_str();
    172172        SString tmp;
    173173        char *f;
     
    200200int strFindField(const SString& txt, const SString& name, int &end)
    201201{
    202         const char* t = txt, *n;
     202        const char* t = txt.c_str(), *n;
    203203        int pos = 0;
    204204        while (1)
    205205        {
    206206                n = strchr(t + pos, ',');
    207                 if ((!strncmp(t + pos, name, name.len())) && (t[pos + name.len()] == '='))
     207                if ((!strncmp(t + pos, name.c_str(), name.len())) && (t[pos + name.len()] == '='))
    208208                {
    209209                        if (n) end = n - t; else end = txt.len();
     
    234234                char *b = t;
    235235                if (txt.len()) *(t++) = ',';
    236                 strcpy(t, name); t += name.len();
     236                strcpy(t, name.c_str()); t += name.len();
    237237                *(t++) = '=';
    238                 strcpy(t, value); t += value.len();
     238                strcpy(t, value.c_str()); t += value.len();
    239239                txt.endAppend(t - b);
    240240        }
     
    253253                        char *t = txt.directWrite(txt.len() + value.len() - (e - p));
    254254                        memmove(t + p + value.len(), t + e, txt.len() - e);
    255                         memmove(t + p, value, value.len());
     255                        memmove(t + p, value.c_str(), value.len());
    256256                        txt.endWrite(txt.len() + value.len() - (e - p));
    257257                }
     
    261261SString trim(SString& s)
    262262{
    263         const unsigned char*b = (const unsigned char*)(const char*)s;
     263        const unsigned char*b = (const unsigned char*)s.c_str();
    264264        const unsigned char*e = b + s.len();
    265265        while ((b < e) && (*b <= ' ')) b++;
     
    275275bool removeCR(SString& s)
    276276{
    277         const char* p = (const char*)s;
     277        const char* p = s.c_str();
    278278        const char* cr = strchr(p, '\r');
    279279        if (!cr) return false;
     
    299299                SString after = pattern.substr(aster + 1);
    300300                if (!word.len()) return false;
    301                 if (before.len()) if (!word.startsWith(before)) return false;
     301                if (before.len()) if (!word.startsWith(before.c_str())) return false;
    302302                if (after.len())
    303303                        if ((word.len() < after.len())
    304                                 || (strcmp((const char*)after, ((const char*)word) + word.len() - after.len())))
     304                                || (strcmp(after.c_str(), word.c_str() + word.len() - after.len())))
    305305                                return false;
    306306                return true;
Note: See TracChangeset for help on using the changeset viewer.