C++ (Qt)out << obj;in >> obj;
C++ (Qt)QVector<MyClass> vector;out << vector; QVector<YourClass> vector;for (auto & elem : vector){ elem.write(out);}
C++ (Qt)QVector<MyClass> vector;out << vector;...
C++ (Qt)template < typename _Archive, typename _Value, int _version >struct Serializer;template < typename _Archive, typename _Value, int _version >struct Loader;template < typename _Archive, typename _Value, int _version >struct Saver;
C++ (Qt)template < typename _Archive, typename _Value >struct Serializer{ static void invoke ( _Archive & archive, _Value & value ) { archive.corrupt( value ); }}; template < typename _Archive, typename _Value >struct Loader{ static void invoke ( _Archive & archive, _Value & value ) { Serializer< _Archive, _Value >::invoke( archive, value ); }}; template < typename _Archive, typename _Value >struct Saver{ static void invoke ( _Archive & archive, const _Value & value ) { Serializer< _Archive, _Value >::invoke( archive, const_cast< _Value & > ( value ) ); }};
C++ (Qt)struct SimpleStruct{ int m_int; double m_double1; double m_double2;};
C++ (Qt)template < typename _Archive >struct Serializer< _Archive, SimpleStruct >{ static void invoke ( _Archive& archive, SimpleStruct & value ) { archive .serialize( value.m_int ) .serialize( value.m_double1 ) .serialize( value.m_double2 ); }};
C++ (Qt)class OutputArchive{public: template < typename _Value > Archive & serialize ( const _Value & value ); template < typename _Value > void corrupt ( const _Value & value, int version );};
C++ (Qt)class InputArchive{public: template < typename _Value > Archive & serialize ( _Value & value ); template < typename _Value > void corrupt ( _Value & value );};
C++ (Qt) class XmlOArchive{private: QTextStream m_stream; public XmlOArchive ( QIODevice * device ) : m_stream( device ) { m_stream.setCodec( "utf-8" ); // ... } public: template < typename _Value > Archive & serialize ( _Value & value ) { QByteArray open_tag = "<Value>" QByteArray close_tag = "</Value>"; m_stream << open_tag; Loader< _Value >::invoke( *this, value ); m_stream << close_tag; return *this; } // Specialize for all POD types, for example. Archive & serialize ( int value ) { QByteArray open_tag = "<Int>" QByteArray close_tag = "</Int>"; m_stream << open_tag << value << close_tag; return *this; } template < typename _Value > void corrupt ( _Value & value ) { qWarning() << "Archive corrupted"; }}
C++ (Qt)stream << a << b << c;
C++ (Qt)template < typename _Archive, typename _Key , typename _Value >struct Parametrizer{ static void invoke ( _Archive & archive, const _Key & key, _Value & value ) { archive.parametrize( key, value ); }};
C++ (Qt)// version enumeratorSERIALIZE_VERSIONS_BEGIN( SimpleStruct ) SERIALIZE_VERSION( Version_0 )SERIALIZE_VERSIONS_END // serialize & deserializeSERIALIZE_BEGIN( SimpleStruct, Version_0 ){ archive .serialize( value.m_int ) .serialize( value.m_double1 ) .serialize( value.m_double2 );}SERIALIZE_END
C++ (Qt)stream >> a >> b >> c; // было так (версия 1.0)stream >> a >> a1 >> b >> c; // появилась новая структура (версия 1.1)stream >> a >> b >> x >> c; // неизвестная структура "x" (версия 1.0 читает данные записанные в 2.0)
C++ (Qt)template <class T>struct MyTemplateClass { T * Get( size_t ); void Set( T *, size_t ); void Read( MyStream & ); void Write( MyStream & ) const;};