summaryrefslogtreecommitdiff
path: root/qmake/tools/qdatastream.cpp
Unidiff
Diffstat (limited to 'qmake/tools/qdatastream.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--qmake/tools/qdatastream.cpp24
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
@@ -561,464 +561,478 @@ QDataStream &QDataStream::operator>>( Q_INT16 &i )
561 561
562QDataStream &QDataStream::operator>>( Q_INT32 &i ) 562QDataStream &QDataStream::operator>>( Q_INT32 &i )
563{ 563{
564 CHECK_STREAM_PRECOND 564 CHECK_STREAM_PRECOND
565 if ( printable ) { // printable data 565 if ( printable ) { // printable data
566 i = read_int_ascii( this ); 566 i = read_int_ascii( this );
567 } else if ( noswap ) { // no conversion needed 567 } else if ( noswap ) { // no conversion needed
568 dev->readBlock( (char *)&i, sizeof(Q_INT32) ); 568 dev->readBlock( (char *)&i, sizeof(Q_INT32) );
569 } else { // swap bytes 569 } else { // swap bytes
570 uchar *p = (uchar *)(&i); 570 uchar *p = (uchar *)(&i);
571 char b[4]; 571 char b[4];
572 dev->readBlock( b, 4 ); 572 dev->readBlock( b, 4 );
573 *p++ = b[3]; 573 *p++ = b[3];
574 *p++ = b[2]; 574 *p++ = b[2];
575 *p++ = b[1]; 575 *p++ = b[1];
576 *p = b[0]; 576 *p = b[0];
577 } 577 }
578 return *this; 578 return *this;
579} 579}
580 580
581/*! 581/*!
582 \overload QDataStream &QDataStream::operator>>( Q_ULONG &i ) 582 \overload QDataStream &QDataStream::operator>>( Q_ULONG &i )
583 583
584 Reads an unsigned integer of the system's word length from the 584 Reads an unsigned integer of the system's word length from the
585 stream, into \a i, and returns a reference to the stream. 585 stream, into \a i, and returns a reference to the stream.
586*/ 586*/
587 587
588/*! 588/*!
589 \overload 589 \overload
590 590
591 Reads a signed integer of the system's word length from the stream 591 Reads a signed integer of the system's word length from the stream
592 into \a i, and returns a reference to the stream. 592 into \a i, and returns a reference to the stream.
593*/ 593*/
594 594
595QDataStream &QDataStream::operator>>( Q_LONG &i ) 595QDataStream &QDataStream::operator>>( Q_LONG &i )
596{ 596{
597 CHECK_STREAM_PRECOND 597 CHECK_STREAM_PRECOND
598 if ( printable ) { // printable data 598 if ( printable ) { // printable data
599 i = read_int_ascii( this ); 599 i = read_int_ascii( this );
600 } else if ( noswap ) { // no conversion needed 600 } else if ( noswap ) { // no conversion needed
601 dev->readBlock( (char *)&i, sizeof(Q_LONG) ); 601 dev->readBlock( (char *)&i, sizeof(Q_LONG) );
602 } else { // swap bytes 602 } else { // swap bytes
603 register uchar *p = (uchar *)(&i); 603 register uchar *p = (uchar *)(&i);
604 char b[sizeof(Q_LONG)]; 604 char b[sizeof(Q_LONG)];
605 dev->readBlock( b, sizeof(Q_LONG) ); 605 dev->readBlock( b, sizeof(Q_LONG) );
606 for ( int j = sizeof(Q_LONG); j; ) 606 for ( int j = sizeof(Q_LONG); j; )
607 *p++ = b[--j]; 607 *p++ = b[--j];
608 } 608 }
609 return *this; 609 return *this;
610} 610}
611 611
612static double read_double_ascii( QDataStream *s ) 612static double read_double_ascii( QDataStream *s )
613{ 613{
614 register int n = 0; 614 register int n = 0;
615 char buf[80]; 615 char buf[80];
616 for ( ;; ) { 616 for ( ;; ) {
617 buf[n] = s->device()->getch(); 617 buf[n] = s->device()->getch();
618 if ( buf[n] == '\n' || n > 78 ) // $-terminator 618 if ( buf[n] == '\n' || n > 78 ) // $-terminator
619 break; 619 break;
620 n++; 620 n++;
621 } 621 }
622 buf[n] = '\0'; 622 buf[n] = '\0';
623 return atof( buf ); 623 return atof( buf );
624} 624}
625 625
626 626
627/*! 627/*!
628 \overload 628 \overload
629 629
630 Reads a 32-bit floating point number from the stream into \a f, 630 Reads a 32-bit floating point number from the stream into \a f,
631 using the standard IEEE754 format. Returns a reference to the 631 using the standard IEEE754 format. Returns a reference to the
632 stream. 632 stream.
633*/ 633*/
634 634
635QDataStream &QDataStream::operator>>( float &f ) 635QDataStream &QDataStream::operator>>( float &f )
636{ 636{
637 CHECK_STREAM_PRECOND 637 CHECK_STREAM_PRECOND
638 if ( printable ) { // printable data 638 if ( printable ) { // printable data
639 f = (float)read_double_ascii( this ); 639 f = (float)read_double_ascii( this );
640 } else if ( noswap ) { // no conversion needed 640 } else if ( noswap ) { // no conversion needed
641 dev->readBlock( (char *)&f, sizeof(float) ); 641 dev->readBlock( (char *)&f, sizeof(float) );
642 } else { // swap bytes 642 } else { // swap bytes
643 uchar *p = (uchar *)(&f); 643 uchar *p = (uchar *)(&f);
644 char b[4]; 644 char b[4];
645 dev->readBlock( b, 4 ); 645 dev->readBlock( b, 4 );
646 *p++ = b[3]; 646 *p++ = b[3];
647 *p++ = b[2]; 647 *p++ = b[2];
648 *p++ = b[1]; 648 *p++ = b[1];
649 *p = b[0]; 649 *p = b[0];
650 } 650 }
651 return *this; 651 return *this;
652} 652}
653 653
654 654
655/*! 655/*!
656 \overload 656 \overload
657 657
658 Reads a 64-bit floating point number from the stream into \a f, 658 Reads a 64-bit floating point number from the stream into \a f,
659 using the standard IEEE754 format. Returns a reference to the 659 using the standard IEEE754 format. Returns a reference to the
660 stream. 660 stream.
661*/ 661*/
662 662
663QDataStream &QDataStream::operator>>( double &f ) 663QDataStream &QDataStream::operator>>( double &f )
664{ 664{
665 CHECK_STREAM_PRECOND 665 CHECK_STREAM_PRECOND
666 if ( printable ) { // printable data 666 if ( printable ) { // printable data
667 f = read_double_ascii( this ); 667 f = read_double_ascii( this );
668 } else if ( noswap ) { // no conversion needed 668 } else if ( noswap ) { // no conversion needed
669 dev->readBlock( (char *)&f, sizeof(double) ); 669 dev->readBlock( (char *)&f, sizeof(double) );
670 } else { // swap bytes 670 } else { // swap bytes
671 register uchar *p = (uchar *)(&f); 671 register uchar *p = (uchar *)(&f);
672 char b[8]; 672 char b[8];
673 dev->readBlock( b, 8 ); 673 dev->readBlock( b, 8 );
674 *p++ = b[7]; 674 *p++ = b[7];
675 *p++ = b[6]; 675 *p++ = b[6];
676 *p++ = b[5]; 676 *p++ = b[5];
677 *p++ = b[4]; 677 *p++ = b[4];
678 *p++ = b[3]; 678 *p++ = b[3];
679 *p++ = b[2]; 679 *p++ = b[2];
680 *p++ = b[1]; 680 *p++ = b[1];
681 *p = b[0]; 681 *p = b[0];
682 } 682 }
683 return *this; 683 return *this;
684} 684}
685 685
686 686
687/*! 687/*!
688 \overload 688 \overload
689 689
690 Reads the '\0'-terminated string \a s from the stream and returns 690 Reads the '\0'-terminated string \a s from the stream and returns
691 a reference to the stream. 691 a reference to the stream.
692 692
693 Space for the string is allocated using \c new -- the caller must 693 Space for the string is allocated using \c new -- the caller must
694 destroy it with delete[]. 694 destroy it with delete[].
695*/ 695*/
696 696
697QDataStream &QDataStream::operator>>( char *&s ) 697QDataStream &QDataStream::operator>>( char *&s )
698{ 698{
699 uint len = 0; 699 uint len = 0;
700 return readBytes( s, len ); 700 return readBytes( s, len );
701} 701}
702 702
703 703
704/*! 704/*!
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
720QDataStream &QDataStream::readBytes( char *&s, uint &l ) 720QDataStream &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
748QDataStream &QDataStream::readRawBytes( char *s, uint len ) 748QDataStream &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
779QDataStream &QDataStream::operator<<( Q_INT8 i ) 787QDataStream &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*/
803 811
804/*! 812/*!
805 \overload 813 \overload
806 814
807 Writes a signed 16-bit integer, \a i, to the stream and returns a 815 Writes a signed 16-bit integer, \a i, to the stream and returns a
808 reference to the stream. 816 reference to the stream.
809*/ 817*/
810 818
811QDataStream &QDataStream::operator<<( Q_INT16 i ) 819QDataStream &QDataStream::operator<<( Q_INT16 i )
812{ 820{
813 CHECK_STREAM_PRECOND 821 CHECK_STREAM_PRECOND
814 if ( printable ) { // printable data 822 if ( printable ) { // printable data
815 char buf[16]; 823 char buf[16];
816 sprintf( buf, "%d\n", i ); 824 sprintf( buf, "%d\n", i );
817 dev->writeBlock( buf, strlen(buf) ); 825 dev->writeBlock( buf, strlen(buf) );
818 } else if ( noswap ) { // no conversion needed 826 } else if ( noswap ) { // no conversion needed
819 dev->writeBlock( (char *)&i, sizeof(Q_INT16) ); 827 dev->writeBlock( (char *)&i, sizeof(Q_INT16) );
820 } else { // swap bytes 828 } else { // swap bytes
821 register uchar *p = (uchar *)(&i); 829 register uchar *p = (uchar *)(&i);
822 char b[2]; 830 char b[2];
823 b[1] = *p++; 831 b[1] = *p++;
824 b[0] = *p; 832 b[0] = *p;
825 dev->writeBlock( b, 2 ); 833 dev->writeBlock( b, 2 );
826 } 834 }
827 return *this; 835 return *this;
828} 836}
829 837
830/*! 838/*!
831 \overload 839 \overload
832 840
833 Writes a signed 32-bit integer, \a i, to the stream and returns a 841 Writes a signed 32-bit integer, \a i, to the stream and returns a
834 reference to the stream. 842 reference to the stream.
835*/ 843*/
836 844
837QDataStream &QDataStream::operator<<( Q_INT32 i ) 845QDataStream &QDataStream::operator<<( Q_INT32 i )
838{ 846{
839 CHECK_STREAM_PRECOND 847 CHECK_STREAM_PRECOND
840 if ( printable ) { // printable data 848 if ( printable ) { // printable data
841 char buf[16]; 849 char buf[16];
842 sprintf( buf, "%d\n", i ); 850 sprintf( buf, "%d\n", i );
843 dev->writeBlock( buf, strlen(buf) ); 851 dev->writeBlock( buf, strlen(buf) );
844 } else if ( noswap ) { // no conversion needed 852 } else if ( noswap ) { // no conversion needed
845 dev->writeBlock( (char *)&i, sizeof(Q_INT32) ); 853 dev->writeBlock( (char *)&i, sizeof(Q_INT32) );
846 } else { // swap bytes 854 } else { // swap bytes
847 register uchar *p = (uchar *)(&i); 855 register uchar *p = (uchar *)(&i);
848 char b[4]; 856 char b[4];
849 b[3] = *p++; 857 b[3] = *p++;
850 b[2] = *p++; 858 b[2] = *p++;
851 b[1] = *p++; 859 b[1] = *p++;
852 b[0] = *p; 860 b[0] = *p;
853 dev->writeBlock( b, 4 ); 861 dev->writeBlock( b, 4 );
854 } 862 }
855 return *this; 863 return *this;
856} 864}
857 865
858/*! 866/*!
859 \overload QDataStream &QDataStream::operator<<( Q_ULONG i ) 867 \overload QDataStream &QDataStream::operator<<( Q_ULONG i )
860 868
861 Writes an unsigned integer \a i, of the system's word length, to 869 Writes an unsigned integer \a i, of the system's word length, to
862 the stream and returns a reference to the stream. 870 the stream and returns a reference to the stream.
863*/ 871*/
864 872
865/*! 873/*!
866 \overload 874 \overload
867 875
868 Writes a signed integer \a i, of the system's word length, to the 876 Writes a signed integer \a i, of the system's word length, to the
869 stream and returns a reference to the stream. 877 stream and returns a reference to the stream.
870*/ 878*/
871 879
872QDataStream &QDataStream::operator<<( Q_LONG i ) 880QDataStream &QDataStream::operator<<( Q_LONG i )
873{ 881{
874 CHECK_STREAM_PRECOND 882 CHECK_STREAM_PRECOND
875 if ( printable ) { // printable data 883 if ( printable ) { // printable data
876 char buf[20]; 884 char buf[20];
877 sprintf( buf, "%ld\n", i ); 885 sprintf( buf, "%ld\n", i );
878 dev->writeBlock( buf, strlen(buf) ); 886 dev->writeBlock( buf, strlen(buf) );
879 } else if ( noswap ) { // no conversion needed 887 } else if ( noswap ) { // no conversion needed
880 dev->writeBlock( (char *)&i, sizeof(Q_LONG) ); 888 dev->writeBlock( (char *)&i, sizeof(Q_LONG) );
881 } else { // swap bytes 889 } else { // swap bytes
882 register uchar *p = (uchar *)(&i); 890 register uchar *p = (uchar *)(&i);
883 char b[sizeof(Q_LONG)]; 891 char b[sizeof(Q_LONG)];
884 for ( int j = sizeof(Q_LONG); j; ) 892 for ( int j = sizeof(Q_LONG); j; )
885 b[--j] = *p++; 893 b[--j] = *p++;
886 dev->writeBlock( b, sizeof(Q_LONG) ); 894 dev->writeBlock( b, sizeof(Q_LONG) );
887 } 895 }
888 return *this; 896 return *this;
889} 897}
890 898
891/*! 899/*!
892 \overload QDataStream &QDataStream::operator<<( Q_UINT32 i ) 900 \overload QDataStream &QDataStream::operator<<( Q_UINT32 i )
893 901
894 Writes an unsigned integer, \a i, to the stream as a 32-bit 902 Writes an unsigned integer, \a i, to the stream as a 32-bit
895 unsigned integer (Q_UINT32). Returns a reference to the stream. 903 unsigned integer (Q_UINT32). Returns a reference to the stream.
896*/ 904*/
897 905
898/*! 906/*!
899 \overload 907 \overload
900 908
901 Writes a 32-bit floating point number, \a f, to the stream using 909 Writes a 32-bit floating point number, \a f, to the stream using
902 the standard IEEE754 format. Returns a reference to the stream. 910 the standard IEEE754 format. Returns a reference to the stream.
903*/ 911*/
904 912
905QDataStream &QDataStream::operator<<( float f ) 913QDataStream &QDataStream::operator<<( float f )
906{ 914{
907 CHECK_STREAM_PRECOND 915 CHECK_STREAM_PRECOND
908 if ( printable ) { // printable data 916 if ( printable ) { // printable data
909 char buf[32]; 917 char buf[32];
910 sprintf( buf, "%g\n", (double)f ); 918 sprintf( buf, "%g\n", (double)f );
911 dev->writeBlock( buf, strlen(buf) ); 919 dev->writeBlock( buf, strlen(buf) );
912 } else { 920 } else {
913 float g = f; // fixes float-on-stack problem 921 float g = f; // fixes float-on-stack problem
914 if ( noswap ) { // no conversion needed 922 if ( noswap ) { // no conversion needed
915 dev->writeBlock( (char *)&g, sizeof(float) ); 923 dev->writeBlock( (char *)&g, sizeof(float) );
916 } else { // swap bytes 924 } else { // swap bytes
917 register uchar *p = (uchar *)(&g); 925 register uchar *p = (uchar *)(&g);
918 char b[4]; 926 char b[4];
919 b[3] = *p++; 927 b[3] = *p++;
920 b[2] = *p++; 928 b[2] = *p++;
921 b[1] = *p++; 929 b[1] = *p++;
922 b[0] = *p; 930 b[0] = *p;
923 dev->writeBlock( b, 4 ); 931 dev->writeBlock( b, 4 );
924 } 932 }
925 } 933 }
926 return *this; 934 return *this;
927} 935}
928 936
929 937
930/*! 938/*!
931 \overload 939 \overload
932 940
933 Writes a 64-bit floating point number, \a f, to the stream using 941 Writes a 64-bit floating point number, \a f, to the stream using
934 the standard IEEE754 format. Returns a reference to the stream. 942 the standard IEEE754 format. Returns a reference to the stream.
935*/ 943*/
936 944
937QDataStream &QDataStream::operator<<( double f ) 945QDataStream &QDataStream::operator<<( double f )
938{ 946{
939 CHECK_STREAM_PRECOND 947 CHECK_STREAM_PRECOND
940 if ( printable ) { // printable data 948 if ( printable ) { // printable data
941 char buf[32]; 949 char buf[32];
942 sprintf( buf, "%g\n", f ); 950 sprintf( buf, "%g\n", f );
943 dev->writeBlock( buf, strlen(buf) ); 951 dev->writeBlock( buf, strlen(buf) );
944 } else if ( noswap ) { // no conversion needed 952 } else if ( noswap ) { // no conversion needed
945 dev->writeBlock( (char *)&f, sizeof(double) ); 953 dev->writeBlock( (char *)&f, sizeof(double) );
946 } else { // swap bytes 954 } else { // swap bytes
947 register uchar *p = (uchar *)(&f); 955 register uchar *p = (uchar *)(&f);
948 char b[8]; 956 char b[8];
949 b[7] = *p++; 957 b[7] = *p++;
950 b[6] = *p++; 958 b[6] = *p++;
951 b[5] = *p++; 959 b[5] = *p++;
952 b[4] = *p++; 960 b[4] = *p++;
953 b[3] = *p++; 961 b[3] = *p++;
954 b[2] = *p++; 962 b[2] = *p++;
955 b[1] = *p++; 963 b[1] = *p++;
956 b[0] = *p; 964 b[0] = *p;
957 dev->writeBlock( b, 8 ); 965 dev->writeBlock( b, 8 );
958 } 966 }
959 return *this; 967 return *this;
960} 968}
961 969
962 970
963/*! 971/*!
964 \overload 972 \overload
965 973
966 Writes the '\0'-terminated string \a s to the stream and returns a 974 Writes the '\0'-terminated string \a s to the stream and returns a
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
972QDataStream &QDataStream::operator<<( const char *s ) 980QDataStream &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
994QDataStream &QDataStream::writeBytes(const char *s, uint len) 1002QDataStream &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
1011QDataStream &QDataStream::writeRawBytes( const char *s, uint len ) 1019QDataStream &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