-rw-r--r-- | qmake/tools/qdatastream.cpp | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/qmake/tools/qdatastream.cpp b/qmake/tools/qdatastream.cpp index 9c573c7..51a1448 100644 --- a/qmake/tools/qdatastream.cpp +++ b/qmake/tools/qdatastream.cpp | |||
@@ -705,98 +705,106 @@ QDataStream &QDataStream::operator>>( char *&s ) | |||
705 | Reads the buffer \a s from the stream and returns a reference to | 705 | Reads the buffer \a s from the stream and returns a reference to |
706 | the stream. | 706 | the stream. |
707 | 707 | ||
708 | The buffer \a s is allocated using \c new. Destroy it with the \c | 708 | The buffer \a s is allocated using \c new. Destroy it with the \c |
709 | delete[] operator. If the length is zero or \a s cannot be | 709 | delete[] operator. If the length is zero or \a s cannot be |
710 | allocated, \a s is set to 0. | 710 | allocated, \a s is set to 0. |
711 | 711 | ||
712 | The \a l parameter will be set to the length of the buffer. | 712 | The \a l parameter will be set to the length of the buffer. |
713 | 713 | ||
714 | The serialization format is a Q_UINT32 length specifier first, | 714 | The serialization format is a Q_UINT32 length specifier first, |
715 | then \a l bytes of data. Note that the data is \e not encoded. | 715 | then \a l bytes of data. Note that the data is \e not encoded. |
716 | 716 | ||
717 | \sa readRawBytes(), writeBytes() | 717 | \sa readRawBytes(), writeBytes() |
718 | */ | 718 | */ |
719 | 719 | ||
720 | QDataStream &QDataStream::readBytes( char *&s, uint &l ) | 720 | QDataStream &QDataStream::readBytes( char *&s, uint &l ) |
721 | { | 721 | { |
722 | CHECK_STREAM_PRECOND | 722 | CHECK_STREAM_PRECOND |
723 | Q_UINT32 len; | 723 | Q_UINT32 len; |
724 | *this >> len; // first read length spec | 724 | *this >> len; // first read length spec |
725 | l = (uint)len; | 725 | l = (uint)len; |
726 | if ( len == 0 || eof() ) { | 726 | if ( len == 0 || eof() ) { |
727 | s = 0; | 727 | s = 0; |
728 | return *this; | 728 | return *this; |
729 | } else { | 729 | } else { |
730 | s = new char[len]; // create char array | 730 | s = new char[len]; // create char array |
731 | Q_CHECK_PTR( s ); | 731 | Q_CHECK_PTR( s ); |
732 | if ( !s ) // no memory | 732 | if ( !s ) // no memory |
733 | return *this; | 733 | return *this; |
734 | return readRawBytes( s, (uint)len ); | 734 | return readRawBytes( s, (uint)len ); |
735 | } | 735 | } |
736 | } | 736 | } |
737 | 737 | ||
738 | 738 | ||
739 | /*! | 739 | /*! |
740 | Reads \a len bytes from the stream into \a s and returns a | 740 | Reads \a len bytes from the stream into \a s and returns a |
741 | reference to the stream. | 741 | reference to the stream. |
742 | 742 | ||
743 | The buffer \a s must be preallocated. The data is \e not encoded. | 743 | The buffer \a s must be preallocated. The data is \e not encoded. |
744 | 744 | ||
745 | \sa readBytes(), QIODevice::readBlock(), writeRawBytes() | 745 | \sa readBytes(), QIODevice::readBlock(), writeRawBytes() |
746 | */ | 746 | */ |
747 | 747 | ||
748 | QDataStream &QDataStream::readRawBytes( char *s, uint len ) | 748 | QDataStream &QDataStream::readRawBytes( char *s, uint len ) |
749 | { | 749 | { |
750 | CHECK_STREAM_PRECOND | 750 | CHECK_STREAM_PRECOND |
751 | if ( printable ) { // printable data | 751 | if ( printable ) { // printable data |
752 | register Q_INT8 *p = (Q_INT8*)s; | 752 | register Q_INT8 *p = (Q_INT8*)s; |
753 | while ( len-- ) | 753 | if ( version() < 4 ) { |
754 | *this >> *p++; | 754 | while ( len-- ) { |
755 | Q_INT32 tmp; | ||
756 | *this >> tmp; | ||
757 | *p++ = tmp; | ||
758 | } | ||
759 | } else { | ||
760 | while ( len-- ) | ||
761 | *this >> *p++; | ||
762 | } | ||
755 | } else { // read data char array | 763 | } else { // read data char array |
756 | dev->readBlock( s, len ); | 764 | dev->readBlock( s, len ); |
757 | } | 765 | } |
758 | return *this; | 766 | return *this; |
759 | } | 767 | } |
760 | 768 | ||
761 | 769 | ||
762 | /***************************************************************************** | 770 | /***************************************************************************** |
763 | QDataStream write functions | 771 | QDataStream write functions |
764 | *****************************************************************************/ | 772 | *****************************************************************************/ |
765 | 773 | ||
766 | 774 | ||
767 | /*! | 775 | /*! |
768 | \overload QDataStream &QDataStream::operator<<( Q_UINT8 i ) | 776 | \overload QDataStream &QDataStream::operator<<( Q_UINT8 i ) |
769 | 777 | ||
770 | Writes an unsigned byte, \a i, to the stream and returns a | 778 | Writes an unsigned byte, \a i, to the stream and returns a |
771 | reference to the stream. | 779 | reference to the stream. |
772 | */ | 780 | */ |
773 | 781 | ||
774 | /*! | 782 | /*! |
775 | Writes a signed byte, \a i, to the stream and returns a reference | 783 | Writes a signed byte, \a i, to the stream and returns a reference |
776 | to the stream. | 784 | to the stream. |
777 | */ | 785 | */ |
778 | 786 | ||
779 | QDataStream &QDataStream::operator<<( Q_INT8 i ) | 787 | QDataStream &QDataStream::operator<<( Q_INT8 i ) |
780 | { | 788 | { |
781 | CHECK_STREAM_PRECOND | 789 | CHECK_STREAM_PRECOND |
782 | if ( printable && (i == '\\' || !isprint((uchar) i)) ) { | 790 | if ( printable && (i == '\\' || !isprint((uchar) i)) ) { |
783 | char buf[6]; // write octal code | 791 | char buf[6]; // write octal code |
784 | buf[0] = '\\'; | 792 | buf[0] = '\\'; |
785 | buf[1] = '0' + ((i >> 6) & 0x07); | 793 | buf[1] = '0' + ((i >> 6) & 0x07); |
786 | buf[2] = '0' + ((i >> 3) & 0x07); | 794 | buf[2] = '0' + ((i >> 3) & 0x07); |
787 | buf[3] = '0' + (i & 0x07); | 795 | buf[3] = '0' + (i & 0x07); |
788 | buf[4] = '\0'; | 796 | buf[4] = '\0'; |
789 | dev->writeBlock( buf, 4 ); | 797 | dev->writeBlock( buf, 4 ); |
790 | } else { | 798 | } else { |
791 | dev->putch( i ); | 799 | dev->putch( i ); |
792 | } | 800 | } |
793 | return *this; | 801 | return *this; |
794 | } | 802 | } |
795 | 803 | ||
796 | 804 | ||
797 | /*! | 805 | /*! |
798 | \overload QDataStream &QDataStream::operator<<( Q_UINT16 i ) | 806 | \overload QDataStream &QDataStream::operator<<( Q_UINT16 i ) |
799 | 807 | ||
800 | Writes an unsigned 16-bit integer, \a i, to the stream and returns | 808 | Writes an unsigned 16-bit integer, \a i, to the stream and returns |
801 | a reference to the stream. | 809 | a reference to the stream. |
802 | */ | 810 | */ |
@@ -967,58 +975,64 @@ QDataStream &QDataStream::operator<<( double f ) | |||
967 | reference to the stream. | 975 | reference to the stream. |
968 | 976 | ||
969 | The string is serialized using writeBytes(). | 977 | The string is serialized using writeBytes(). |
970 | */ | 978 | */ |
971 | 979 | ||
972 | QDataStream &QDataStream::operator<<( const char *s ) | 980 | QDataStream &QDataStream::operator<<( const char *s ) |
973 | { | 981 | { |
974 | if ( !s ) { | 982 | if ( !s ) { |
975 | *this << (Q_UINT32)0; | 983 | *this << (Q_UINT32)0; |
976 | return *this; | 984 | return *this; |
977 | } | 985 | } |
978 | uint len = qstrlen( s ) + 1; // also write null terminator | 986 | uint len = qstrlen( s ) + 1; // also write null terminator |
979 | *this << (Q_UINT32)len; // write length specifier | 987 | *this << (Q_UINT32)len; // write length specifier |
980 | return writeRawBytes( s, len ); | 988 | return writeRawBytes( s, len ); |
981 | } | 989 | } |
982 | 990 | ||
983 | 991 | ||
984 | /*! | 992 | /*! |
985 | Writes the length specifier \a len and the buffer \a s to the | 993 | Writes the length specifier \a len and the buffer \a s to the |
986 | stream and returns a reference to the stream. | 994 | stream and returns a reference to the stream. |
987 | 995 | ||
988 | The \a len is serialized as a Q_UINT32, followed by \a len bytes | 996 | The \a len is serialized as a Q_UINT32, followed by \a len bytes |
989 | from \a s. Note that the data is \e not encoded. | 997 | from \a s. Note that the data is \e not encoded. |
990 | 998 | ||
991 | \sa writeRawBytes(), readBytes() | 999 | \sa writeRawBytes(), readBytes() |
992 | */ | 1000 | */ |
993 | 1001 | ||
994 | QDataStream &QDataStream::writeBytes(const char *s, uint len) | 1002 | QDataStream &QDataStream::writeBytes(const char *s, uint len) |
995 | { | 1003 | { |
996 | CHECK_STREAM_PRECOND | 1004 | CHECK_STREAM_PRECOND |
997 | *this << (Q_UINT32)len; // write length specifier | 1005 | *this << (Q_UINT32)len; // write length specifier |
998 | if ( len ) | 1006 | if ( len ) |
999 | writeRawBytes( s, len ); | 1007 | writeRawBytes( s, len ); |
1000 | return *this; | 1008 | return *this; |
1001 | } | 1009 | } |
1002 | 1010 | ||
1003 | 1011 | ||
1004 | /*! | 1012 | /*! |
1005 | Writes \a len bytes from \a s to the stream and returns a | 1013 | Writes \a len bytes from \a s to the stream and returns a |
1006 | reference to the stream. The data is \e not encoded. | 1014 | reference to the stream. The data is \e not encoded. |
1007 | 1015 | ||
1008 | \sa writeBytes(), QIODevice::writeBlock(), readRawBytes() | 1016 | \sa writeBytes(), QIODevice::writeBlock(), readRawBytes() |
1009 | */ | 1017 | */ |
1010 | 1018 | ||
1011 | QDataStream &QDataStream::writeRawBytes( const char *s, uint len ) | 1019 | QDataStream &QDataStream::writeRawBytes( const char *s, uint len ) |
1012 | { | 1020 | { |
1013 | CHECK_STREAM_PRECOND | 1021 | CHECK_STREAM_PRECOND |
1014 | if ( printable ) { // write printable | 1022 | if ( printable ) { // write printable |
1015 | register Q_INT8 *p = (Q_INT8*)s; | 1023 | if ( version() < 4 ) { |
1016 | while ( len-- ) | 1024 | register char *p = (char *)s; |
1017 | *this << *p++; | 1025 | while ( len-- ) |
1026 | *this << *p++; | ||
1027 | } else { | ||
1028 | register Q_INT8 *p = (Q_INT8*)s; | ||
1029 | while ( len-- ) | ||
1030 | *this << *p++; | ||
1031 | } | ||
1018 | } else { // write data char array | 1032 | } else { // write data char array |
1019 | dev->writeBlock( s, len ); | 1033 | dev->writeBlock( s, len ); |
1020 | } | 1034 | } |
1021 | return *this; | 1035 | return *this; |
1022 | } | 1036 | } |
1023 | 1037 | ||
1024 | #endif // QT_NO_DATASTREAM | 1038 | #endif // QT_NO_DATASTREAM |