本文整理汇总了C++中std::istream::gcount方法的典型用法代码示例。如果您正苦于以下问题:C++ istream::gcount方法的具体用法?C++ istream::gcount怎么用?C++ istream::gcount使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::istream
的用法示例。
在下文中一共展示了istream::gcount方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: putback_test_two
bool putback_test_two(std::istream& is)
{
try {
do {
char buf[chunk_size];
is.read(buf, chunk_size);
if (is.gcount() < static_cast<std::streamsize>(chunk_size))
break;
is.putback('a');
is.putback('b');
is.putback('c');
is.putback('d');
if ( is.get() != 'd' || is.get() != 'c' ||
is.get() != 'b' || is.get() != 'a' )
{
return false;
}
} while (!is.eof());
return true;
} catch (std::exception&) { return false; }
}
示例2: deserialize_string_raw
int deserialize_string_raw(
std::istream& istr,
std::string& value,
S32 max_bytes)
{
int count = 0;
const S32 BUF_LEN = 20;
char buf[BUF_LEN]; /* Flawfinder: ignore */
istr.get(buf, BUF_LEN - 1, ')');
count += istr.gcount();
char c = istr.get();
c = istr.get();
count += 2;
if(((c == '"') || (c == '\'')) && (buf[0] == '('))
{
// We probably have a valid raw string. determine
// the size, and read it.
// *FIX: This is memory inefficient.
S32 len = strtol(buf + 1, NULL, 0);
if((max_bytes>0)&&(len>max_bytes)) return LLSDParser::PARSE_FAILURE;
std::vector<char> buf;
if(len)
{
buf.resize(len);
count += fullread(istr, (char *)&buf[0], len);
value.assign(buf.begin(), buf.end());
}
c = istr.get();
++count;
if(!((c == '"') || (c == '\'')))
{
return LLSDParser::PARSE_FAILURE;
}
}
else
{
return LLSDParser::PARSE_FAILURE;
}
return count;
}
示例3: readFragmentProgram
/*! Read the program string from the given stream
*/
bool ShaderChunk::readFragmentProgram(std::istream &stream)
{
#define BUFSIZE 200
editFragmentProgram().erase();
char buf[BUFSIZE];
if(!stream.good())
{
FWARNING(("SHLChunk::readFragmentProgram: stream is not good!\n"));
return false;
}
do
{
stream.read(buf, BUFSIZE);
editFragmentProgram().append(buf, stream.gcount());
}
while(!stream.eof());
return true;
}
示例4: while
////////////////////////////////////////////////////////////////////////////
// MemParser constructor
//////////////////////////////////////////////////////////////////////////////
MemParser::MemParser(std::istream &in, UInt32 bytes) {
if (bytes == 0) {
// -----------------------------------------------------------------------------
// Read all available bytes from the stream
// -----------------------------------------------------------------------------
std::string data;
const int chunkSize = 0x10000;
auto chunkP = new char[chunkSize];
while (!in.eof()) {
in.read(chunkP, chunkSize);
NTA_CHECK(in.good() || in.eof())
<< "MemParser::MemParser() - error reading data from stream";
data.append(chunkP, in.gcount());
}
bytes_ = (UInt32)data.size();
bufP_ = new char[bytes_ + 1];
NTA_CHECK(bufP_ != nullptr) << "MemParser::MemParser() - out of memory";
::memmove((void *)bufP_, data.data(), bytes_);
((char *)bufP_)[bytes_] = 0;
delete[] chunkP;
} else {
// -----------------------------------------------------------------------------
// Read given # of bytes from the stream
// -----------------------------------------------------------------------------
bytes_ = bytes;
bufP_ = new char[bytes_ + 1];
NTA_CHECK(bufP_ != nullptr) << "MemParser::MemParser() - out of memory";
in.read((char *)bufP_, bytes);
((char *)bufP_)[bytes] = 0;
NTA_CHECK(in.good())
<< "MemParser::MemParser() - error reading data from stream";
}
// Setup start and end pointers
startP_ = bufP_;
endP_ = startP_ + bytes_;
}
示例5: load
//------------------------------------------------------------------------------
bool load( std::istream &stream )
{
clean();
unsigned char e_ident[EI_NIDENT];
// Read ELF file signature
stream.seekg( 0 );
stream.read( reinterpret_cast<char*>( &e_ident ), sizeof( e_ident ) );
// Is it ELF file?
if ( stream.gcount() != sizeof( e_ident ) ||
e_ident[EI_MAG0] != ELFMAG0 ||
e_ident[EI_MAG1] != ELFMAG1 ||
e_ident[EI_MAG2] != ELFMAG2 ||
e_ident[EI_MAG3] != ELFMAG3 ) {
return false;
}
if ( ( e_ident[EI_CLASS] != ELFCLASS64 ) &&
( e_ident[EI_CLASS] != ELFCLASS32 )) {
return false;
}
convertor.setup( e_ident[EI_DATA] );
header = create_header( e_ident[EI_CLASS], e_ident[EI_DATA] );
if ( 0 == header ) {
return false;
}
if ( !header->load( stream ) ) {
return false;
}
load_sections( stream );
load_segments( stream );
return true;
}
示例6: buffer
ArchiveKeys::ArchiveKeys(std::istream &stream, RsaKeyPair &keypair){
this->init(CryptoPP::Twofish::MAX_KEYLENGTH, CryptoPP::Twofish::BLOCKSIZE, false);
auto &private_key = keypair.get_private_key();
CryptoPP::RSA::PrivateKey priv;
priv.Load(CryptoPP::ArraySource((const byte *)&private_key[0], private_key.size(), true));
CryptoPP::SecByteBlock buffer(this->size);
{
auto n = 4096 / 8;
typedef CryptoPP::RSAES<CryptoPP::OAEP<CryptoPP::SHA>>::Decryptor decryptor_t;
typedef CryptoPP::PK_DecryptorFilter filter_t;
decryptor_t dec(priv);
CryptoPP::SecByteBlock temp(n);
stream.read((char *)temp.data(), temp.size());
auto read = stream.gcount();
if (read != temp.size())
throw RsaBlockDecryptionException("Not enough bytes read from RSA block.");
try{
auto sink = new CryptoPP::ArraySink(buffer.data(), buffer.size());
auto filter = new filter_t(*random_number_generator, dec, sink);
CryptoPP::ArraySource(temp.data(), temp.size(), true, filter);
}catch (...){
throw RsaBlockDecryptionException("Invalid data in RSA block.");
}
}
size_t offset = 0;
for (size_t i = 0; i < this->key_count; i++){
auto &key = this->keys[i];
auto &iv = this->ivs[i];
memcpy(key.data(), buffer.data() + offset, key.size());
offset += key.size();
memcpy(iv.data(), buffer.data() + offset, iv.size());
offset += iv.size();
}
}
示例7: readString
std::string cgicc::readString(std::istream& in)
{
std::string::size_type dataSize = 0;
in >> dataSize;
in.get(); // skip ' '
// Avoid allocation of a zero-length vector
if(0 == dataSize) {
return std::string();
}
// Don't use auto_ptr, but vector instead
// Bug reported by [email protected] / fix by [email protected]
std::vector<char> temp(dataSize);
in.read(&temp[0], dataSize);
if(static_cast<std::string::size_type>(in.gcount()) != dataSize) {
throw std::runtime_error("I/O error");
}
return std::string(&temp[0], dataSize);
}
示例8: while
void ModPhpHandler::inParent(int *p, std::ostream& os, std::istream& is)
{
std::cout << "ModPhpHandler::inParent" << std::endl;
if (dup2(p[0], 0) == -1)
std::cerr << "dup2 failed in parent" << std::endl;
// close(p[1]);
// TODO: envoyer le $_POST dans p[1]
char buf2[4096];
int read_size = 0;
while (!is.eof())
{
is.read(buf2, 4096);
if (is.eof())
read_size = is.gcount();
else
read_size = 4096;
if (read_size == 0)
continue ;
if (write(p[1], buf2, read_size) == -1)
{
std::cerr << "Write fail in ModPhpHandler" << std::endl;
break ;
}
// la t'ecris buf dans le pipe
}
char buf[512];
memset(buf, 0, 512);
while (read(0, buf, 512) > 0)
{
os << buf;
std::cout << buf << std::endl;
memset(buf, 0, 512);
}
}
示例9: ReadStreamChunk
bool Soy::ReadStreamChunk(ArrayBridge<char>& Data,std::istream& Stream)
{
// dunno how much to read
if ( !Soy::Assert( !Data.IsEmpty(), "Soy::ReadStreamChunk no data length specified, resorting to 1byte" ) )
Data.SetSize(1);
if ( Data.IsEmpty() )
return false;
auto Peek = Stream.peek();
if ( Peek == std::char_traits<char>::eof() )
return false;
Stream.read( Data.GetArray(), Data.GetDataSize() );
if ( Stream.fail() && !Stream.eof() )
return false;
auto BytesRead = Stream.gcount();
Data.SetSize( BytesRead );
return true;
}
示例10: compress
void compress(std::istream& in, std::ostream& out)
{
const size_t BUFFER_SIZE = 512;
std::vector<byte_t> r_buffer(BUFFER_SIZE);
std::vector<bit_t> w_buffer;
ahc::Tree tree(ahc::Algorithm::FGK);
w_buffer.reserve(8 * BUFFER_SIZE + BUFFER_SIZE);
while (in)
{
in.read(reinterpret_cast<char*>(r_buffer.data()), BUFFER_SIZE);
size_t read_bytes = in.gcount();
// encode bytes read
for (size_t i = 0; i < read_bytes; ++i)
{
std::vector<bit_t> code = tree.encode(r_buffer[i]);
std::copy(std::begin(code), std::end(code), std::back_inserter(w_buffer));
}
// flush buffer if it is almost filled
if (w_buffer.size() >= 8 * BUFFER_SIZE)
flush_buffer(w_buffer, out);
}
// fill buffer with zeroes if byte is not complete
byte_t extra_bits = 0;
if (w_buffer.size() % 8 != 0)
{
extra_bits = 8 - w_buffer.size() % 8;
std::fill_n(std::back_inserter(w_buffer), extra_bits, 0);
}
flush_buffer(w_buffer, out);
out.write(reinterpret_cast<char*>(&extra_bits), 1);
}
示例11: copyIterator
static void copyIterator(
std::istream & in,
iterator & out,
uint64_t n,
uint64_t const multiplier = 1)
{
n *= multiplier;
::libmaus2::autoarray::AutoArray < char > buf(16*1024,false);
while ( n )
{
uint64_t const tocopy = std::min(n,buf.getN());
in.read(buf.get(), tocopy);
assert ( in.gcount() == static_cast<int64_t>(tocopy) );
std::copy(buf.get(),buf.get()+tocopy,out);
//out.write ( buf.get(), tocopy );
// assert ( out );
n -= tocopy;
}
}
示例12: read_scanline_old
static void read_scanline_old(std::istream& in,
std::vector<packed_colour>& scanline,
size_t i = 0) {
int rshift = 0;
while (i < scanline.size()) {
in.read((char*)&scanline[i].val, 4);
if (in.gcount() != 4)
throw std::runtime_error("premature EOF");
if (scanline[i].r == 1 && scanline[i].g == 1 && scanline[i].b == 1) {
size_t j = i + (scanline[i].e << rshift);
if (j > scanline.size())
throw std::runtime_error("RLE overflow");
uint32_t copy = scanline[i - 1].val;
for (; i < j; i++) {
scanline[i].val = copy;
}
rshift += 8;
} else {
i++;
rshift = 0;
}
}
}
示例13: readHeader
OSG_BEGIN_NAMESPACE
/*! \class TGAImageFileType
Image File Type to read/write and store/restore Image objects as
TGA data.
All the type specific code is included in the class. Does
not depend on external libs.
*/
bool TGAImageFileType::readHeader(std::istream &is, TGAHeader &header)
{
UInt8 dum[18];
is.read(reinterpret_cast<char *>(dum), 18);
if(is.gcount() != 18)
return false;
header.idLength = dum[ 0];
header.colorMapType = dum[ 1];
header.imageType = dum[ 2];
header.cmapFirst = dum[ 3] | (dum[ 4] << 8);
header.cmapLength = dum[ 5] | (dum[ 6] << 8);
header.cmapEntrySize = dum[ 7];
header.xOrigin = dum[ 8] | (dum[ 9] << 8);
header.yOrigin = dum[10] | (dum[11] << 8);
header.width = dum[12] | (dum[13] << 8);
header.height = dum[14] | (dum[15] << 8);
header.depth = dum[16];
header.descriptor = dum[17];
return true;
}
示例14: buffer
void
Producer::populateStore(std::istream& is)
{
BOOST_ASSERT(m_store.size() == 0);
if (m_isVerbose)
std::cerr << "Loading input ..." << std::endl;
std::vector<uint8_t> buffer(m_maxSegmentSize);
while (is.good()) {
is.read(reinterpret_cast<char*>(buffer.data()), buffer.size());
const auto nCharsRead = is.gcount();
if (nCharsRead > 0) {
auto data = make_shared<Data>(Name(m_versionedPrefix).appendSegment(m_store.size()));
data->setFreshnessPeriod(m_freshnessPeriod);
data->setContent(&buffer[0], nCharsRead);
m_store.push_back(data);
}
}
if (m_store.empty()) {
auto data = make_shared<Data>(Name(m_versionedPrefix).appendSegment(0));
data->setFreshnessPeriod(m_freshnessPeriod);
m_store.push_back(data);
}
auto finalBlockId = name::Component::fromSegment(m_store.size() - 1);
for (const auto& data : m_store) {
data->setFinalBlockId(finalBlockId);
m_keyChain.sign(*data, m_signingInfo);
}
if (m_isVerbose)
std::cerr << "Created " << m_store.size() << " chunks for prefix " << m_prefix << std::endl;
}
示例15: read_buffer
static bool read_buffer(std::istream& is, z_stream& z, char* in_buf, void* p, size_t size) {
z.next_out=(Bytef*)p;
z.avail_out=(uInt)size;
while (z.avail_out) {
if ( z.avail_in == 0 ) {
if (!is.eof()) {
z.next_in = (Bytef*)in_buf;
is.read((char*)z.next_in, OUT_BUFSIZE);
if (is.bad()) {
std::cerr<<"read error "<<std::endl;;
return false;
}
z.avail_in = (uInt)is.gcount();
}
}
int ret = inflate( &z, Z_BLOCK );
if ( ret != Z_OK && ret != Z_STREAM_END ) {
std::cerr<<"Zlib error "<<z.msg<<std::endl;;
return false;
}
}
return true;
}