Changeset 348 for cpp/frams/util
- Timestamp:
- 04/09/15 23:51:28 (10 years ago)
- Location:
- cpp/frams/util
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/frams/util/extvalue.cpp
r337 r348 269 269 if (tmp.len() > 30) tmp = tmp.substr(0, 30) + "..."; 270 270 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()); 272 272 } 273 273 return NULL; … … 329 329 static ExtValue::CompareResult compareString(const SString &a, const SString &b) 330 330 { 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(); 333 333 return longsign(strcmp(s1, s2)); 334 334 } … … 415 415 if (context->v1 && context->v2) 416 416 msg += SString::sprintf(": %s %s %s", 417 (const char*)context->v1->typeAndValue(),417 context->v1->typeAndValue().c_str(), 418 418 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()); 422 422 ret = -1; 423 423 } … … 448 448 { 449 449 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()); 451 451 setDouble(double(getInt()) + src.getDouble()); 452 452 return; … … 487 487 default:; 488 488 } 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()); 490 490 } 491 491 … … 502 502 return; 503 503 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()); 505 505 setDouble(double(getInt()) - src.getDouble()); 506 506 return; … … 520 520 default:; 521 521 } 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()); 523 523 } 524 524 … … 535 535 return; 536 536 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()); 538 538 setDouble(double(getInt())*src.getDouble()); 539 539 return; … … 591 591 default:; 592 592 } 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()); 594 594 } 595 595 … … 621 621 if (a == 0.0) 622 622 { 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()); 624 624 setInvalid(); 625 625 } … … 630 630 if (!finite(tmp)) 631 631 { 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(); 633 633 } 634 634 else … … 652 652 return; 653 653 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()); 655 655 divDouble(src.ddata()); 656 656 return; … … 674 674 default:; 675 675 } 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()); 677 677 } 678 678 … … 687 687 // ^-cur ^-next 688 688 // ^^^^^^^^^^___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; 690 690 int type = 0; 691 691 … … 733 733 switch (type) 734 734 { 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; 738 738 case 't': case 'T': 739 739 { … … 779 779 780 780 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()); 782 782 783 783 default:; … … 835 835 case TInt: return idata(); 836 836 case TDouble: return (int)ddata(); 837 case TString: return getInt( (const char*)sdata());837 case TString: return getInt(sdata().c_str()); 838 838 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()); 840 840 return (paInt)(intptr_t)odata().param; 841 841 default:; … … 850 850 case TDouble: return ddata(); 851 851 case TInt: return (double)idata(); 852 case TString: return getDouble( (const char*)sdata());852 case TString: return getDouble(sdata().c_str()); 853 853 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()); 855 855 return (double)(intptr_t)odata().param; 856 856 default:; … … 1095 1095 ExtValue tmp; 1096 1096 ret = tmp.deserialize(ret); 1097 ParamInterface *cls = findDeserializableClass(clsname );1097 ParamInterface *cls = findDeserializableClass(clsname.c_str()); 1098 1098 if (cls && (tmp.getType() != TUnknown) && (tmp.getType() != TInvalid)) 1099 1099 { … … 1134 1134 } 1135 1135 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()); 1137 1137 return ret; 1138 1138 } -
cpp/frams/util/hashtable.cpp
r286 r348 161 161 printf(" %d:",n); 162 162 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); 164 164 printf("\n"); 165 165 } -
cpp/frams/util/sstring.cpp
r347 r348 251 251 void SString::operator+=(const SString&s) 252 252 { 253 append( (const char*)s,s.len());253 append(s.c_str(),s.len()); 254 254 } 255 255 … … 323 323 int SString::indexOf(const SString & substring,int start) const 324 324 { 325 char *found=strstr(buf->txt+start, ((const char*)substring));325 char *found=strstr(buf->txt+start,substring.c_str()); 326 326 return found?found-buf->txt:-1; 327 327 } … … 341 341 int SString::startsWith(const char *pattern) const 342 342 { 343 const char *t= (const char*)(*this);343 const char *t=this->c_str(); 344 344 for (;*pattern;pattern++,t++) 345 345 if (*t != *pattern) return 0; … … 358 358 { 359 359 SString tmp=SString::sprintf("%.15g",d); 360 if ((!strchr(tmp ,'.'))&&(!strchr(tmp,'e'))) tmp+=".0";360 if ((!strchr(tmp.c_str(),'.'))&&(!strchr(tmp.c_str(),'e'))) tmp+=".0"; 361 361 return tmp; 362 362 } -
cpp/frams/util/sstring.h
r286 r348 144 144 int indexOf(const SString & substring,int start=0) const; 145 145 146 operator const char*() const {return buf->txt;} ///< get SString's readonly buffer146 const char* c_str() const {return buf->txt;} ///< get SString's readonly buffer 147 147 //operator char*() {detachCopy(len()); return buf->txt;} ///< get SString's writable buffer 148 148 void operator=(const char*t); ///< assign from const char* -
cpp/frams/util/sstringutils.cpp
r319 r348 63 63 int quoteTilde(SString &target) 64 64 { 65 const char* x = target ;65 const char* x = target.c_str(); 66 66 SString tmp; 67 67 char *f; … … 88 88 int unquoteTilde(SString &target) 89 89 { 90 const char* x = target ;90 const char* x = target.c_str(); 91 91 SString tmp; 92 92 char *f; … … 134 134 bool sstringQuote(SString& target) 135 135 { 136 const char* x = target ;136 const char* x = target.c_str(); 137 137 bool changed = 0; 138 138 SString tmp; … … 169 169 int sstringUnquote(SString &target) 170 170 { 171 const char* x = target ;171 const char* x = target.c_str(); 172 172 SString tmp; 173 173 char *f; … … 200 200 int strFindField(const SString& txt, const SString& name, int &end) 201 201 { 202 const char* t = txt , *n;202 const char* t = txt.c_str(), *n; 203 203 int pos = 0; 204 204 while (1) 205 205 { 206 206 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()] == '=')) 208 208 { 209 209 if (n) end = n - t; else end = txt.len(); … … 234 234 char *b = t; 235 235 if (txt.len()) *(t++) = ','; 236 strcpy(t, name ); t += name.len();236 strcpy(t, name.c_str()); t += name.len(); 237 237 *(t++) = '='; 238 strcpy(t, value ); t += value.len();238 strcpy(t, value.c_str()); t += value.len(); 239 239 txt.endAppend(t - b); 240 240 } … … 253 253 char *t = txt.directWrite(txt.len() + value.len() - (e - p)); 254 254 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()); 256 256 txt.endWrite(txt.len() + value.len() - (e - p)); 257 257 } … … 261 261 SString trim(SString& s) 262 262 { 263 const unsigned char*b = (const unsigned char*) (const char*)s;263 const unsigned char*b = (const unsigned char*)s.c_str(); 264 264 const unsigned char*e = b + s.len(); 265 265 while ((b < e) && (*b <= ' ')) b++; … … 275 275 bool removeCR(SString& s) 276 276 { 277 const char* p = (const char*)s;277 const char* p = s.c_str(); 278 278 const char* cr = strchr(p, '\r'); 279 279 if (!cr) return false; … … 299 299 SString after = pattern.substr(aster + 1); 300 300 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; 302 302 if (after.len()) 303 303 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()))) 305 305 return false; 306 306 return true;
Note: See TracChangeset
for help on using the changeset viewer.