@@ -56,6 +56,9 @@ Class: serializert
5656\*******************************************************************/
5757class serializert
5858{
59+ // ///////////////////////////////////////////////////////////////////////////
60+ // Section: Data used in this class
61+
5962private:
6063 // The serializer for a containing object, if any
6164 serializert *parent;
@@ -64,6 +67,9 @@ class serializert
6467 // Traits attached to this serializer
6568 serializer_traitst *traits;
6669
70+ // ///////////////////////////////////////////////////////////////////////////
71+ // Section: Constructors/destructors
72+
6773protected:
6874 /* ******************************************************************\
6975
@@ -108,6 +114,9 @@ class serializert
108114 // The virtual destructor ensures sub-classes are disposed correctly.
109115 virtual ~serializert ()=default ;
110116
117+ // ///////////////////////////////////////////////////////////////////////////
118+ // Section: Accessors
119+
111120public:
112121 /* ******************************************************************\
113122
@@ -185,6 +194,9 @@ class serializert
185194 traits=&serializer_traits;
186195 }
187196
197+ // ///////////////////////////////////////////////////////////////////////////
198+ // Section: Serialization of basic data types
199+
188200public:
189201 /* ******************************************************************\
190202
@@ -298,7 +310,9 @@ class serializert
298310 \*******************************************************************/
299311 virtual void serialize (const char *name, float &field)=0;
300312
301- // Serializing objects that implement a serialize method
313+ // ///////////////////////////////////////////////////////////////////////////
314+ // Section: Serializing objects that implement a serialize method
315+
302316protected:
303317 // This is a non-templated function so that it can be virtual
304318 // It therefore can't take an object of the type to be serialized
@@ -339,29 +353,28 @@ class serializert
339353
340354 /* ******************************************************************\
341355
342- Function: serializert::serialize
356+ Function: serializert::read_object
343357
344358 Template parameters:
345359 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.
347362
348363 Inputs:
349- name: The name of the field to serialize.
350- field: An rvalue reference to the field to serialize.
351364
352365 Outputs:
366+ An object of the type T read from the serializer.
353367
354368 Purpose:
355369 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.
359370
360371 \*******************************************************************/
361372 template <typename T>
362- void serialize ( const char *name, T &&field )
373+ T read_object ( )
363374 {
364- serialize (name, static_cast <T &>(field));
375+ T result;
376+ result.serialize (*this );
377+ return result;
365378 }
366379
367380 /* ******************************************************************\
@@ -371,53 +384,60 @@ class serializert
371384 Template parameters:
372385 T:
373386 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.
375388
376389 Inputs:
390+ name: The name of the field to serialize.
377391
378392 Outputs:
379- An object of the type T read from the serializer.
393+ An object of the type T read from the field serializer.
380394
381395 Purpose:
382396 Serializes a field.
383397
384398 \*******************************************************************/
385399 template <typename T>
386- T read_object ()
400+ T read_object (const char *name )
387401 {
388402 T result;
389- result. serialize (* this );
403+ serialize (name, result );
390404 return result;
391405 }
392406
407+ // ///////////////////////////////////////////////////////////////////////////
408+ // Section: Serializing rvalue references
409+
410+ public:
393411 /* ******************************************************************\
394412
395- Function: serializert::read_object
413+ Function: serializert::serialize
396414
397415 Template parameters:
398416 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.
401418
402419 Inputs:
403420 name: The name of the field to serialize.
421+ field: An rvalue reference to the field to serialize.
404422
405423 Outputs:
406- An object of the type T read from the field serializer.
407424
408425 Purpose:
409426 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.
410430
411431 \*******************************************************************/
412432 template <typename T>
413- T read_object (const char *name)
433+ void serialize (const char *name, T &&field )
414434 {
415- T result;
416- serialize (name, result);
417- return result;
435+ serialize (name, static_cast <T &>(field));
418436 }
419437
420- // Serializing pairs of serializable values
438+ // ///////////////////////////////////////////////////////////////////////////
439+ // Section: Serializing pairs of serializable values
440+
421441private:
422442 /* ******************************************************************\
423443
@@ -490,21 +510,30 @@ class serializert
490510 serialize (name, serializable_pairt<std::pair<firstt, secondt>>(field));
491511 }
492512
513+ // ///////////////////////////////////////////////////////////////////////////
514+ // Section: Serializing vectors
515+
493516public:
494- // A helper class for writing vectors
517+ // A helper base class for writing vectors
495518 class collection_writert
496519 {
497520 public:
498521 virtual bool is_end () const =0;
499522 virtual void write (serializert &serializer)=0;
500523 };
501524
525+ // Virtual function that must be implemented to support reading vectors
502526 virtual void read_array (
503527 const char *name,
504528 std::function<void (serializert &serializer)> read_elt)=0;
529+
530+ // Virtual function that must be implemented to support writing vectors
505531 virtual void write_array (
506532 const char *name, collection_writert &collection_writer)=0;
507533
534+ // ///////////////////////////////////////////////////////////////////////////
535+ // Section: Serializing vectors of objects that implement a serialize method
536+
508537public:
509538 // A helper class for writing vectors of objects that implement a serialize
510539 // method
@@ -581,6 +610,9 @@ class serializert
581610 }
582611 }
583612
613+ // ///////////////////////////////////////////////////////////////////////////
614+ // Section: Serializing vectors of serializable values
615+
584616protected:
585617 // A helper class for writing vectors of serializable objects (wrapped in a
586618 // value field)
@@ -655,6 +687,9 @@ class serializert
655687 }
656688 }
657689
690+ // ///////////////////////////////////////////////////////////////////////////
691+ // Section: Serializing sets of serializable values
692+
658693public:
659694 /* ******************************************************************\
660695
@@ -754,7 +789,9 @@ class serializert
754789 serialize_set (name, field);
755790 }
756791
757- // Serializing maps of serializable values
792+ // ///////////////////////////////////////////////////////////////////////////
793+ // Section: Serializing maps of serializable values
794+
758795private:
759796 // This helper function can serialize any type of map (mapt) that has member
760797 // types key_type, mapped_type, value_type and reference, an insert method
0 commit comments