Changeset 46
- Timestamp:
- 06/25/08 01:50:06 (4 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/doost/util/serializer/archive/JsonArchive.d
r45 r46 96 96 STORAGETYPE rest = STORAGETYPE.init; 97 97 uint indent = 0; 98 bool line_begin = true; 98 99 99 100 //fields of specific class with values: content[name of fields] … … 153 154 154 155 /*************************************************************************** 156 Return the indentation string for the current indentation level. 157 Does not use or modify the line_begin flag. 158 **************************************************************************/ 159 STORAGETYPE indentString() { 160 STORAGETYPE indent_str = STORAGETYPE.init; 161 for(int i=0; i<indent; i++) { 162 indent_str ~= Skip.indent; 163 } 164 return indent_str; 165 } 166 167 /*************************************************************************** 168 Write the current indentation string to the storage. 169 Postcondition: line_begin flag set to false. 170 **************************************************************************/ 171 bool dumpIndent() { 172 line_begin = false; 173 storage.put(indentString()); 174 return true; 175 } 176 177 /*************************************************************************** 155 178 **************************************************************************/ 156 179 bool loadString(VALUE)(ref VALUE value) { … … 176 199 **************************************************************************/ 177 200 bool dumpString(VALUE)(ref VALUE value) { 201 if (line_begin) dumpIndent(); 178 202 storage.put( String.sdelimiter ~ 179 203 to!(STORAGETYPE)(escape(value)) ~ … … 220 244 **************************************************************************/ 221 245 bool dumpBool(VALUE)(ref VALUE value) { 246 if (line_begin) dumpIndent(); 222 247 storage.put((value == true) ? Bool.positive 223 248 : Bool.negative); … … 239 264 **************************************************************************/ 240 265 bool dumpNumber(VALUE)(ref VALUE value) { 266 if (line_begin) dumpIndent(); 241 267 storage.put(to!(STORAGETYPE)(value)); 242 268 return true; … … 258 284 **************************************************************************/ 259 285 bool dumpChar(VALUE)(ref VALUE value) { 286 if (line_begin) dumpIndent(); 260 287 storage.put("" ~ String.cdelimiter ~ value ~ String.cdelimiter); 261 288 return true; … … 277 304 **************************************************************************/ 278 305 bool dumpElement(VALUE, SEP)(ref VALUE value, SEP sep) { 306 if (line_begin) dumpIndent(); 279 307 storage.put(rest); 280 308 bool res = traverse(value); … … 308 336 **************************************************************************/ 309 337 bool dumpArray(VALUE)(ref VALUE value) { 338 if (line_begin) dumpIndent(); 310 339 storage.put(Array.begin); 311 340 … … 342 371 storage.put(rest); 343 372 traverse(key); 373 if (line_begin) dumpIndent(); 344 374 storage.put(Skip.space ~ kvsep ~ Skip.space); 345 375 traverse(value); 346 rest = esep ~ Skip.newline; 376 rest = esep ~ Skip.newline ~ indentString(); 377 347 378 return true; 348 379 } … … 383 414 ValueType val; 384 415 385 storage.put(Udt.begin); 416 if (line_begin) dumpIndent(); 417 storage.put(Udt.begin ~ Skip.newline); 418 line_begin = true; 419 indent++; 386 420 387 421 rest = STORAGETYPE.init; 388 foreach(k, v; value) 422 foreach(k, v; value) { 389 423 dumpAssociativeElement(k, v, Udt.kvseparator, Udt.separator); 390 424 } 425 indent--; 426 storage.put(Skip.newline); 427 line_begin = true; 428 if (line_begin) dumpIndent(); 391 429 storage.put(Udt.end); 392 430 … … 441 479 bool dumpRef(VALUE)(ref VALUE value) { 442 480 if (value is null) { 481 if (line_begin) dumpIndent(); 443 482 storage.put(Reference.defnull); 444 483 return true; … … 448 487 uint symbol = registry.get!(TypeDescription, VALUE).symbol(value); 449 488 if (symbol > 0) { 489 if (line_begin) dumpIndent(); 450 490 storage.put(Reference.defref ~ to!(STORAGETYPE)(symbol)); 451 491 return true; … … 454 494 455 495 static if (!is(VALUE == class)) { 496 if (line_begin) dumpIndent(); 456 497 storage.put(Reference.pointer); 457 498 } … … 528 569 **************************************************************************/ 529 570 bool dumpFields(VALUE)(ref VALUE value) { 530 storage.put( String.sdelimiter 571 if (line_begin) dumpIndent(); 572 storage.put(String.sdelimiter 531 573 ~ VALUE.stringof 532 574 ~ String.sdelimiter … … 536 578 ~ Udt.begin 537 579 ~ Skip.newline); 580 line_begin = true; 581 indent++; 538 582 539 583 if (Udt.ver in memberStructFields) { 540 541 storage.put( String.sdelimiter584 if (line_begin) dumpIndent(); 585 storage.put(String.sdelimiter 542 586 ~ Udt.ver 543 587 ~ String.sdelimiter … … 548 592 ~ Udt.separator 549 593 ~ Skip.newline); 594 line_begin = true; 550 595 } 551 596 … … 553 598 processMemberStructFields(value); 554 599 555 storage.put(Skip.newline 556 ~ Udt.end 557 ~ Skip.newline); 600 indent--; 601 storage.put(Skip.newline); 602 line_begin = true; 603 if (line_begin) dumpIndent(); 604 storage.put(Udt.end ~ Skip.newline); 605 line_begin = true; 558 606 return true; 559 607 } … … 683 731 **************************************************************************/ 684 732 bool dumpUdt(VALUE)(ref VALUE value) { 733 if (line_begin) dumpIndent(); 685 734 storage.put( Udt.begin ~ Skip.newline); 735 indent++; 736 line_begin = true; 686 737 687 738 processMemberStruct(value); … … 690 741 foreach(i, BASE; BaseTypeTuple!(VALUE)) { 691 742 if (is (BASE == interface) || BASE.tupleof.length == 0) continue; 743 if (line_begin) dumpIndent(); 692 744 storage.put(Udt.separator ~ Skip.newline); 745 line_begin = true; 693 746 BASE val = cast(BASE)value; 694 747 processMemberStruct(val); … … 696 749 } 697 750 751 indent--; 752 if (line_begin) dumpIndent(); 698 753 storage.put(Udt.end); 699 754
