本文整理汇总了C++中std::ifstream::gcount方法的典型用法代码示例。如果您正苦于以下问题:C++ ifstream::gcount方法的具体用法?C++ ifstream::gcount怎么用?C++ ifstream::gcount使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::ifstream
的用法示例。
在下文中一共展示了ifstream::gcount方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: fstreamReadBig
unsigned long long fstreamReadBig(std::ifstream &S, char* A, unsigned long long N) {
unsigned long long C=0;
for (unsigned long long ii=0; ii<N/fstream_Chunk_Max; ii++) {
S.read(A+C,fstream_Chunk_Max);
C+=S.gcount();
if (!S.good()) break;
};
S.read(A+C,N%fstream_Chunk_Max);
C+=S.gcount();
return C;
};
示例2: StreamFile
void AudioStreamingServer::StreamFile(const std::shared_ptr<ISocket>& clientSocket, std::ifstream& file, HttpContentType contentType) const {
file.seekg(0, file.end);
int fileLength = file.tellg();
HttpResponse response(HTTP_1_1, OK, contentType, fileLength);
SendResponseHeader(clientSocket, response);
file.seekg(0, file.beg);
char sendbuf[DEFAULT_BUFFER_SIZE] = { 0 };
file.read(sendbuf, DEFAULT_BUFFER_SIZE);
while(file.gcount() > 0) {
clientSocket->Send(sendbuf, file.gcount());
file.read(sendbuf, DEFAULT_BUFFER_SIZE);
}
}
示例3: CopyData
void CopyData ( std::ifstream &fin, std::ofstream &fout ) {
char line[704];
while (!fin.eof()) {
fin.read(line, 704);
fout.write(line, fin.gcount());
}
}
示例4: MatrixInput
MMFormatInput::MMFormatInput(std::ifstream &in, std::vector<uint32_t> &permIn) : MatrixInput(), in(in), curRow(0), curIndex(-1), already_read(false), perm(permIn) {
//read header only
char buf[500];
isBinary = false;
in.getline(buf, 500);
if ( strstr(buf, "pattern") != NULL ) {
isBinary = true; }
do {
in.getline(buf, 500);
if (in.gcount() >=500){
cerr << "FAILED FORMAT" << endl;
exit(1);
}
} while (buf[0] == '%');
uint32_t nr, nc, nnz;
sscanf( buf , "%d %d %d", &nr, &nc, &nnz);
this->nnz = nnz;
this->numRows = nr;
this->numCols = nc;
if (perm.size() == 0) {
perm.resize( max(numRows, numCols) );
for (int i=0; i<perm.size(); i++) {
perm[i] = i;
}
}
}
示例5: hash_file
std::string hash_file(HashFunc * hf, std::ifstream& file, std::streampos start)
{
size_t bs = 16384;
char * b = new char [bs];
file.seekg (start, std::ios::beg);
while (file)
{
file.read (b, bs);
if (file)
{
hf->process_bytes(b, bs);
}
else if (file.eof())
{
// file.gcount() returns an std::streamsize, which is the signed counterpart of std::size_t
// it only returns a negative value in the constructors of std::strstreambuf, so we can
// safely cast to size_t (taken from http://en.cppreference.com/w/cpp/io/streamsize)
hf->process_bytes(b, (size_t)file.gcount());
}
else
{
hf->reset();
}
}
delete[] b;
return hf->str();
}
示例6:
void Sha256File::getHash( std::ifstream& inFile, unsigned char* pHash )
{
SHA256Context sha256;
SHA256Init(&sha256);
uint8_t* pMovableBuffer = pBuffer;
// Ensure it is on a 64-bit boundary.
INTPTR offs;
if ((offs = reinterpret_cast<INTPTR>(pBuffer) & 7L))
pMovableBuffer += 8 - offs;
unsigned int len;
for (;;)
{
inFile.read( reinterpret_cast<char*>(pMovableBuffer), SHA_BUFFER_SIZE );
len = inFile.gcount();
if ( len == 0)
break;
SHA256Update (&sha256, pMovableBuffer, len);
}
SHA256Final (&sha256, pHash);
}
示例7: load
bool
load( std::ifstream& stream )
{
stream.seekg( 0 );
stream.read( reinterpret_cast<char*>( &header ), sizeof( header ) );
return (stream.gcount() == sizeof( header ) );
}
示例8: fillBuffer
inline void fillBuffer(std::ifstream& file, std::streamsize size, boost::uint8_t*& buffer) {
std::streamsize read_bytes = 0;
unsigned int i = 0;
while (read_bytes != size && ++i<100) {
file.read((char*) buffer, size);
read_bytes += file.gcount();
}
if (read_bytes != size)
throw PNMImageExcpetion("Unable to read pixel data properly");
}
示例9: restoreData
void TestDataInputHandler::restoreData( char* m_buffer, uint64_t m_size )
{
m_is.read( m_buffer, m_size );
uint64_t size = m_is.gcount();
if( size < m_size ) {
std::ostringstream ostr;
ostr << "TestDataInputHandler::restoreData("
<< m_size << "): no more data ! gcount = " << size;
std::cerr << ostr.str() << std::endl;
throw(AccessByStringNotInitialized(ostr.str()));
}
}
示例10: sizeof
bool
FileInputReader::isELFFile(std::ifstream& str)
{
char first_bytes[4];
str.read(first_bytes, sizeof(first_bytes));
if (str.gcount() != 4) // not enough characters for ELF magic
return false;
if ( (first_bytes[0] == ELFMAG0) and
(first_bytes[1] == ELFMAG1) and
(first_bytes[2] == ELFMAG2) and
(first_bytes[3] == ELFMAG3))
return true;
return false;
}
示例11: read
/// read portion of file into internal buffer
/// if a_crunch == true, crunch buffer before reading
bool read(bool a_crunch = true) {
if (!m_open || !m_file.is_open())
return false;
if (a_crunch)
m_buf.crunch();
while (true) {
BOOST_ASSERT(m_buf.capacity() > 0);
m_file.read(m_buf.wr_ptr(), m_buf.capacity());
int n = m_file.gcount();
if (n == 0) {
if (m_file.good()) continue;
if (m_file.eof()) return false;
// this should never happen since we have set badbit
throw io_error(errno, "Unexpected error reading ", m_fname);
}
m_buf.commit(n);
return true;
}
}
示例12: LoadPixels
/**
Reads the pixel rows from the bitmap file.
@param[in] FileStream The input file stream.
@param[out] DestBuffer The buffer to write the pixels to.
@param[in] FileHeader The bitmap file header.
@param[in] InfoHeader The bitmap info header.
@return One of #BitmapLoadStatus codes.
*/
static BitmapLoadStatus LoadPixels(std::ifstream& FileStream, std::vector<std::uint8_t>* DestBuffer,
const BitmapFileHeader& FileHeader, const BitmapInfoHeader& InfoHeader)
{
FileStream.seekg(FileHeader.PixelArrayOffset);
// Workaround for Paint.NET being stupid and generating broken images...
if (InfoHeader.PixelDataSize != 0) {
DestBuffer->resize(InfoHeader.PixelDataSize);
} else {
DestBuffer->resize(CalculateStride(InfoHeader) * InfoHeader.Height);
}
auto buffer = reinterpret_cast<char*>(&DestBuffer->at(0));
FileStream.read(buffer, InfoHeader.PixelDataSize);
if (FileStream.gcount() != InfoHeader.PixelDataSize) {
return UNEXPECTED_END_OF_FILE;
}
return LOAD_SUCCESS;
}
示例13: read_impl
/**
* Reads a single particle from disk into the specified buffer.
* @param data The location to read a single particle to. Must be at least m_layout.size() bytes.
* @return True if a particle was read, false if EOF or the stream was never opened.
*/
virtual bool read_impl( char* data ) {
if( m_particleCount == 0 ) {
if( !m_fin.is_open() || m_fin.eof() )
return false;
throw std::runtime_error( "The file \"" + m_filePath + "\" did not contain the number of particles it claimed" );
}
m_zstream.avail_out = static_cast<uInt>( m_layout.size() );
m_zstream.next_out = reinterpret_cast<unsigned char*>(data);
do {
if(m_zstream.avail_in == 0) {
m_fin.read(m_buffer, m_bufferSize);
if( m_fin.fail() && m_bufferSize == 0 )
throw std::ios_base::failure( "Failed to read from file \"" + m_filePath + "\"" );
m_zstream.avail_in = static_cast<uInt>(m_fin.gcount());
m_zstream.next_in = reinterpret_cast<unsigned char*>(m_buffer);
}
int ret = inflate(&m_zstream, Z_SYNC_FLUSH);
if(Z_OK != ret && Z_STREAM_END != ret) {
std::stringstream ss;
ss << "inflate() on file \"" << m_filePath << "\" ";
ss << "with " << m_particleCount << " particles left failed:\n\t";
ss << zError(ret);
throw std::runtime_error( ss.str() );
}
} while(m_zstream.avail_out != 0);
--m_particleCount;
return true;
}
示例14: read_meta_chunk
void read_meta_chunk( detail::prt_int32 chunkLength ) {
char channelName[32];
char valueName[32];
detail::prt_int32 valueType;
m_fin.getline( channelName, 32, '\0' );
chunkLength -= m_fin.gcount();
m_fin.getline( valueName, 32, '\0' );
chunkLength -= m_fin.gcount();
m_fin.read( reinterpret_cast<char*>( &valueType ), 4u );
chunkLength -= 4;
assert( chunkLength > 0 );
if( valueType < meta_types::type_string || valueType >= meta_types::type_last )
throw std::runtime_error( std::string() + "The data type specified for channel \"" + channelName + "\" metadata \"" + valueName + "\" in the input stream \"" + m_filePath + "\" is not valid." );
struct scoped_void_ptr {
void* ptr;
~scoped_void_ptr() {
operator delete( ptr );
}
} buffer = { operator new( chunkLength ) };
// We've been subtracting the read bytes as we go, so this is the remaining number of bytes in the chunk.
m_fin.read( static_cast<char*>( buffer.ptr ), chunkLength );
if( channelName[0] != '\0' && !detail::is_valid_channel_name( channelName ) ) {
std::cerr << "Invalid channel name: \"" << channelName << "\" in metadata: \"" << valueName << "\"" << std::endl;
return;
}
if( !detail::is_valid_channel_name( valueName ) ) {
std::cerr << "Invalid metadata name: \"" << valueName << "\" in channel: \"" << channelName << "\"" << std::endl;
return;
}
std::map< std::string, prt_meta_value >& metaValue = (channelName[0] == '\0') ? m_fileMetadata : m_channelMetadata[ std::string(channelName) ];
if( valueType == meta_types::type_string ) {
#ifdef _WIN32
int wcharLength = MultiByteToWideChar( CP_UTF8, MB_ERR_INVALID_CHARS, static_cast<const char*>( buffer.ptr ), chunkLength, NULL, 0 );
if( wcharLength <= 0 ) {
std::cerr << "Invalid string data in metadata: \"" << valueName << "\" in channel: \"" << channelName << "\"" << std::endl;
return;
}
// In Windows we convert from UTF8 to UTF16LE in memory.
std::vector<wchar_t> convertedString( wcharLength, L'\0' );
int r = MultiByteToWideChar( CP_UTF8, MB_ERR_INVALID_CHARS, static_cast<const char*>( buffer.ptr ), chunkLength, &convertedString.front(), wcharLength );
assert( r > 0 );
metaValue[ std::string(valueName) ].set_string( &convertedString.front(), static_cast<std::size_t>( chunkLength - 1 ) );
#else
// In non-Windows we can work directly with UTF8.
metaValue[ std::string(valueName) ].set_string( static_cast<char*>( buffer.ptr ), static_cast<std::size_t> ( chunkLength - 1 ) );
#endif
} else {
std::size_t basicSize = data_types::sizes[valueType]; // We've already verified that we have a valid index.
assert( chunkLength >= basicSize && (chunkLength % basicSize) == 0 );
std::size_t arity = chunkLength / basicSize;
metaValue[ std::string(valueName) ].set( static_cast<meta_types::option>( valueType ), arity, buffer.ptr );
}
}
示例15: read
virtual size_t read(char* buf, size_t num) {
std::unique_lock<std::mutex> lock(m_mutex); // Released when out of scope
ensureStream();
m_stream.read (buf, num);
return m_stream.gcount();
}