@@ -372,76 +372,117 @@ class LIBSCRATCHCPP_EXPORT Value
372
372
373
373
const Value &operator =(float v)
374
374
{
375
+ if (m_type == Type::String)
376
+ m_stringValue.~basic_string ();
377
+
375
378
m_type = Type::Double;
376
379
m_doubleValue = v;
377
380
return *this ;
378
381
}
379
382
380
383
const Value &operator =(double v)
381
384
{
385
+ if (m_type == Type::String)
386
+ m_stringValue.~basic_string ();
387
+
382
388
m_type = Type::Double;
383
389
m_doubleValue = v;
384
390
return *this ;
385
391
}
386
392
387
393
const Value &operator =(int v)
388
394
{
395
+ if (m_type == Type::String)
396
+ m_stringValue.~basic_string ();
397
+
389
398
m_type = Type::Integer;
390
399
m_intValue = v;
391
400
return *this ;
392
401
}
393
402
394
403
const Value &operator =(long v)
395
404
{
405
+ if (m_type == Type::String)
406
+ m_stringValue.~basic_string ();
407
+
396
408
m_type = Type::Integer;
397
409
m_intValue = v;
398
410
return *this ;
399
411
}
400
412
401
413
const Value &operator =(bool v)
402
414
{
415
+ if (m_type == Type::String)
416
+ m_stringValue.~basic_string ();
417
+
403
418
m_type = Type::Bool;
404
419
m_boolValue = v;
405
420
return *this ;
406
421
}
407
422
408
423
const Value &operator =(const std::string &v)
409
424
{
410
- m_type = Type::String;
411
- new (&m_stringValue) std::string (v);
425
+ if (m_type == Type::String)
426
+ m_stringValue = v;
427
+ else {
428
+ new (&m_stringValue) std::string (v);
429
+ m_type = Type::String;
430
+ }
431
+
412
432
initString (v);
413
433
return *this ;
414
434
}
415
435
416
436
const Value &operator =(const char *v)
417
437
{
418
- m_type = Type::String;
419
- new (&m_stringValue) std::string (v);
438
+ if (m_type == Type::String)
439
+ m_stringValue = v;
440
+ else {
441
+ new (&m_stringValue) std::string (v);
442
+ m_type = Type::String;
443
+ }
444
+
420
445
initString (v);
421
446
return *this ;
422
447
}
423
448
424
449
const Value &operator =(const Value &v)
425
450
{
426
- m_type = v.m_type ;
427
-
428
- switch (m_type) {
451
+ switch (v.m_type ) {
429
452
case Type::Integer:
453
+ if (m_type == Type::String)
454
+ m_stringValue.~basic_string ();
455
+
430
456
m_intValue = v.m_intValue ;
431
457
break ;
458
+
432
459
case Type::Double:
460
+ if (m_type == Type::String)
461
+ m_stringValue.~basic_string ();
462
+
433
463
m_doubleValue = v.m_doubleValue ;
434
464
break ;
465
+
435
466
case Type::Bool:
467
+ if (m_type == Type::String)
468
+ m_stringValue.~basic_string ();
469
+
436
470
m_boolValue = v.m_boolValue ;
437
471
break ;
472
+
438
473
case Type::String:
439
- new (&m_stringValue) std::string (v.m_stringValue );
474
+ if (m_type == Type::String)
475
+ m_stringValue = v.m_stringValue ;
476
+ else
477
+ new (&m_stringValue) std::string (v.m_stringValue );
440
478
break ;
479
+
441
480
default :
442
481
break ;
443
482
}
444
483
484
+ m_type = v.m_type ;
485
+
445
486
return *this ;
446
487
}
447
488
0 commit comments