! internal Default constructor initialization must be equivalent to: * memset( this, 0, sizeof(Value) ) * This optimization is used in ValueInternalMap fast allocator. */
| 345 | * This optimization is used in ValueInternalMap fast allocator. |
| 346 | */ |
| 347 | Value::Value(ValueType type) { |
| 348 | static char const emptyString[] = ""; |
| 349 | initBasic(type); |
| 350 | switch (type) { |
| 351 | case nullValue: |
| 352 | break; |
| 353 | case intValue: |
| 354 | case uintValue: |
| 355 | value_.int_ = 0; |
| 356 | break; |
| 357 | case realValue: |
| 358 | value_.real_ = 0.0; |
| 359 | break; |
| 360 | case stringValue: |
| 361 | // allocated_ == false, so this is safe. |
| 362 | value_.string_ = const_cast<char*>(static_cast<char const*>(emptyString)); |
| 363 | break; |
| 364 | case arrayValue: |
| 365 | case objectValue: |
| 366 | value_.map_ = new ObjectValues(); |
| 367 | break; |
| 368 | case booleanValue: |
| 369 | value_.bool_ = false; |
| 370 | break; |
| 371 | default: |
| 372 | JSON_ASSERT_UNREACHABLE; |
| 373 | } |
| 374 | } |
| 375 | |
| 376 | Value::Value(Int value) { |
| 377 | initBasic(intValue); |