StrBuf::operator <<( const StrPtr & )

Append a StrPtr to a StrBuf. The argument is passed as a reference of the StrPtr. The string pointed to by the StrPtr's buffer is logically appended to the string pointed to by the StrBuf's buffer.

Virtual?

No

 

Class

StrBuf

 

Arguments

const StrPtr &s

(implied) reference of the StrPtr instance

Returns

StrBuf &

reference of the StrBuf

Notes

Arguments are typically instances of classes derived from the StrPtr class, such as StrRef and StrBuf.

Exactly the number of bytes specified by the length of the StrPtr are appended to the StrBuf from the StrPtr. The length of the StrBuf is incremented by the length of the StrPtr.

If the memory for the StrBuf's buffer is not large enough, new contiguous memory is allocated to contain the results of appending the StrPtr. If new memory is allocated, the old memory is freed. Any memory allocated is separate from the memory for the StrPtr.

Example

#include <iostream>

#include <stdhdrs.h>
#include <strbuf.h>

int main( int argc, char **argv )
{
    StrRef sr( "zy" );
    StrPtr *sp = &sr;
    StrBuf sba;
    StrBuf sbb;

    sba.Set( "xyzzy" );
    sbb.Set( "xyz" );

    cout << "sba.Text() after sba.Set( \"xyzzy\" ) returns ";
    cout << "\"" << sba.Text() << "\"\n";
    cout << "sba.Length() after sba.Set( \"xyzzy\" ) returns ";
    cout << sba.Length() << "\n";
    cout << "sbb.Text() after sbb.Set( \"xyz\" ) returns ";
    cout << "\"" << sbb.Text() << "\"\n";
    cout << "sbb.Length() after sbb.Set( \"xyz\" ) returns ";
    cout << sbb.Length() << "\n";

    sbb << sr;   // append StrRef to StrBuf

    cout << "sbb.Text() after sbb << sr returns ";
    cout << "\"" << sbb.Text() << "\"\n";
    cout << "sbb.Length() after sbb << sr returns ";
    cout << sbb.Length() << "\n";

    sba << sbb;   // append StrBuf to StrBuf

    cout << "sba.Text() after sba << sbb returns ";
    cout << "\"" << sba.Text() << "\"\n";
    cout << "sba.Length() after sba << sbb returns ";
    cout << sba.Length() << "\n";
}

Executing the preceding code produces the following output:

sba.Text() after sba.Set( "xyzzy" ) returns "xyzzy"
sba.Length() after sba.Set( "xyzzy" ) returns 5
sbb.Text() after sbb.Set( "xyz" ) returns "xyz"
sbb.Length() after sbb.Set( "xyz" ) returns 3
sbb.Text() after sbb << sr returns "xyzzy"
sbb.Length() after sbb << sr returns 5
sba.Text() after sba << sbb returns "xyzzyxyzzy"
sba.Length() after sba << sbb returns 10