@@ -56,6 +56,9 @@ Class: serializert
56
56
\*******************************************************************/
57
57
class serializert
58
58
{
59
+ // ///////////////////////////////////////////////////////////////////////////
60
+ // Section: Data used in this class
61
+
59
62
private:
60
63
// The serializer for a containing object, if any
61
64
serializert *parent;
@@ -64,6 +67,9 @@ class serializert
64
67
// Traits attached to this serializer
65
68
serializer_traitst *traits;
66
69
70
+ // ///////////////////////////////////////////////////////////////////////////
71
+ // Section: Constructors/destructors
72
+
67
73
protected:
68
74
/* ******************************************************************\
69
75
@@ -108,6 +114,9 @@ class serializert
108
114
// The virtual destructor ensures sub-classes are disposed correctly.
109
115
virtual ~serializert ()=default ;
110
116
117
+ // ///////////////////////////////////////////////////////////////////////////
118
+ // Section: Accessors
119
+
111
120
public:
112
121
/* ******************************************************************\
113
122
@@ -185,6 +194,9 @@ class serializert
185
194
traits=&serializer_traits;
186
195
}
187
196
197
+ // ///////////////////////////////////////////////////////////////////////////
198
+ // Section: Serialization of basic data types
199
+
188
200
public:
189
201
/* ******************************************************************\
190
202
@@ -298,7 +310,9 @@ class serializert
298
310
\*******************************************************************/
299
311
virtual void serialize (const char *name, float &field)=0;
300
312
301
- // Serializing objects that implement a serialize method
313
+ // ///////////////////////////////////////////////////////////////////////////
314
+ // Section: Serializing objects that implement a serialize method
315
+
302
316
protected:
303
317
// This is a non-templated function so that it can be virtual
304
318
// It therefore can't take an object of the type to be serialized
@@ -339,29 +353,28 @@ class serializert
339
353
340
354
/* ******************************************************************\
341
355
342
- Function: serializert::serialize
356
+ Function: serializert::read_object
343
357
344
358
Template parameters:
345
359
T:
346
- The type of the field to serialize. Must be serializable.
360
+ The type of the field to read.
361
+ Must implement a serialize method and have a default constructor.
347
362
348
363
Inputs:
349
- name: The name of the field to serialize.
350
- field: An rvalue reference to the field to serialize.
351
364
352
365
Outputs:
366
+ An object of the type T read from the serializer.
353
367
354
368
Purpose:
355
369
Serializes a field.
356
- Since the field is an rvalue reference this override is useful for writing
357
- temporary objects or reading into temporary objects that store their
358
- values in a non-temporary.
359
370
360
371
\*******************************************************************/
361
372
template <typename T>
362
- void serialize ( const char *name, T &&field )
373
+ T read_object ( )
363
374
{
364
- serialize (name, static_cast <T &>(field));
375
+ T result;
376
+ result.serialize (*this );
377
+ return result;
365
378
}
366
379
367
380
/* ******************************************************************\
@@ -371,53 +384,60 @@ class serializert
371
384
Template parameters:
372
385
T:
373
386
The type of the field to read.
374
- Must implement a serialize method and have a default constructor.
387
+ Must be serializable and have a default constructor.
375
388
376
389
Inputs:
390
+ name: The name of the field to serialize.
377
391
378
392
Outputs:
379
- An object of the type T read from the serializer.
393
+ An object of the type T read from the field serializer.
380
394
381
395
Purpose:
382
396
Serializes a field.
383
397
384
398
\*******************************************************************/
385
399
template <typename T>
386
- T read_object ()
400
+ T read_object (const char *name )
387
401
{
388
402
T result;
389
- result. serialize (* this );
403
+ serialize (name, result );
390
404
return result;
391
405
}
392
406
407
+ // ///////////////////////////////////////////////////////////////////////////
408
+ // Section: Serializing rvalue references
409
+
410
+ public:
393
411
/* ******************************************************************\
394
412
395
- Function: serializert::read_object
413
+ Function: serializert::serialize
396
414
397
415
Template parameters:
398
416
T:
399
- The type of the field to read.
400
- Must be serializable and have a default constructor.
417
+ The type of the field to serialize. Must be serializable.
401
418
402
419
Inputs:
403
420
name: The name of the field to serialize.
421
+ field: An rvalue reference to the field to serialize.
404
422
405
423
Outputs:
406
- An object of the type T read from the field serializer.
407
424
408
425
Purpose:
409
426
Serializes a field.
427
+ Since the field is an rvalue reference this override is useful for writing
428
+ temporary objects or reading into temporary objects that store their
429
+ values in a non-temporary.
410
430
411
431
\*******************************************************************/
412
432
template <typename T>
413
- T read_object (const char *name)
433
+ void serialize (const char *name, T &&field )
414
434
{
415
- T result;
416
- serialize (name, result);
417
- return result;
435
+ serialize (name, static_cast <T &>(field));
418
436
}
419
437
420
- // Serializing pairs of serializable values
438
+ // ///////////////////////////////////////////////////////////////////////////
439
+ // Section: Serializing pairs of serializable values
440
+
421
441
private:
422
442
/* ******************************************************************\
423
443
@@ -490,21 +510,30 @@ class serializert
490
510
serialize (name, serializable_pairt<std::pair<firstt, secondt>>(field));
491
511
}
492
512
513
+ // ///////////////////////////////////////////////////////////////////////////
514
+ // Section: Serializing vectors
515
+
493
516
public:
494
- // A helper class for writing vectors
517
+ // A helper base class for writing vectors
495
518
class collection_writert
496
519
{
497
520
public:
498
521
virtual bool is_end () const =0;
499
522
virtual void write (serializert &serializer)=0;
500
523
};
501
524
525
+ // Virtual function that must be implemented to support reading vectors
502
526
virtual void read_array (
503
527
const char *name,
504
528
std::function<void (serializert &serializer)> read_elt)=0;
529
+
530
+ // Virtual function that must be implemented to support writing vectors
505
531
virtual void write_array (
506
532
const char *name, collection_writert &collection_writer)=0;
507
533
534
+ // ///////////////////////////////////////////////////////////////////////////
535
+ // Section: Serializing vectors of objects that implement a serialize method
536
+
508
537
public:
509
538
// A helper class for writing vectors of objects that implement a serialize
510
539
// method
@@ -581,6 +610,9 @@ class serializert
581
610
}
582
611
}
583
612
613
+ // ///////////////////////////////////////////////////////////////////////////
614
+ // Section: Serializing vectors of serializable values
615
+
584
616
protected:
585
617
// A helper class for writing vectors of serializable objects (wrapped in a
586
618
// value field)
@@ -655,6 +687,9 @@ class serializert
655
687
}
656
688
}
657
689
690
+ // ///////////////////////////////////////////////////////////////////////////
691
+ // Section: Serializing sets of serializable values
692
+
658
693
public:
659
694
/* ******************************************************************\
660
695
@@ -754,7 +789,9 @@ class serializert
754
789
serialize_set (name, field);
755
790
}
756
791
757
- // Serializing maps of serializable values
792
+ // ///////////////////////////////////////////////////////////////////////////
793
+ // Section: Serializing maps of serializable values
794
+
758
795
private:
759
796
// This helper function can serialize any type of map (mapt) that has member
760
797
// types key_type, mapped_type, value_type and reference, an insert method
0 commit comments