copy_stream

This commit is contained in:
David Rose 2009-09-01 22:45:07 +00:00
parent 6f42852497
commit b027447c0f
4 changed files with 68 additions and 0 deletions

View File

@ -14,6 +14,7 @@
circBuffer.h \
config_express.h \
compress_string.h \
copy_stream.h \
datagram.I datagram.h datagramGenerator.I \
datagramGenerator.h \
datagramIterator.I datagramIterator.h datagramSink.I datagramSink.h \
@ -74,6 +75,7 @@
buffer.cxx checksumHashGenerator.cxx \
config_express.cxx \
compress_string.cxx \
copy_stream.cxx \
datagram.cxx datagramGenerator.cxx \
datagramIterator.cxx \
datagramSink.cxx dcast.cxx \
@ -125,6 +127,7 @@
circBuffer.h \
config_express.h \
compress_string.h \
copy_stream.h \
datagram.I datagram.h datagramGenerator.I \
datagramGenerator.h \
datagramIterator.I datagramIterator.h datagramSink.I datagramSink.h \

View File

@ -0,0 +1,39 @@
// Filename: copy_stream.cxx
// Created by: drose (27Aug09)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) Carnegie Mellon University. All rights reserved.
//
// All use of this software is subject to the terms of the revised BSD
// license. You should have received a copy of this license along
// with this source code in a file named "LICENSE."
//
////////////////////////////////////////////////////////////////////
#include "copy_stream.h"
////////////////////////////////////////////////////////////////////
// Function: copy_stream
// Access: Published
// Description: Reads the source stream from its current position to
// the end of the stream, and writes that data to the
// dest stream at its current position. Returns true on
// success, false on failure.
////////////////////////////////////////////////////////////////////
bool
copy_stream(istream &source, ostream &dest) {
static const size_t buffer_size = 4096;
char buffer[buffer_size];
source.read(buffer, buffer_size);
size_t count = source.gcount();
while (count != 0) {
dest.write(buffer, count);
source.read(buffer, buffer_size);
count = source.gcount();
}
return (!source.fail() || source.eof()) && (!dest.fail());
}

25
panda/src/express/copy_stream.h Executable file
View File

@ -0,0 +1,25 @@
// Filename: copy_stream.h
// Created by: drose (27Aug09)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) Carnegie Mellon University. All rights reserved.
//
// All use of this software is subject to the terms of the revised BSD
// license. You should have received a copy of this license along
// with this source code in a file named "LICENSE."
//
////////////////////////////////////////////////////////////////////
#ifndef COPY_STREAM_H
#define COPY_STREAM_H
#include "pandabase.h"
BEGIN_PUBLISH
EXPCL_PANDAEXPRESS bool
copy_stream(istream &source, ostream &dest);
END_PUBLISH
#endif

View File

@ -2,6 +2,7 @@
#include "checksumHashGenerator.cxx"
#include "config_express.cxx"
#include "compress_string.cxx"
#include "copy_stream.cxx"
#include "datagram.cxx"
#include "datagramGenerator.cxx"
#include "datagramIterator.cxx"