本文整理汇总了C++中std::istream::tellg方法的典型用法代码示例。如果您正苦于以下问题:C++ istream::tellg方法的具体用法?C++ istream::tellg怎么用?C++ istream::tellg使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::istream
的用法示例。
在下文中一共展示了istream::tellg方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: next
// TODO: fix
boost::shared_ptr<Token> Tokenizer::peek(std::istream &is, SymbolTablePtr symbols) {
std::streampos pos = is.tellg();
boost::shared_ptr<Token> peek = next(is, symbols);
is.seekg(pos);
return peek;
}
示例2: while
boost::shared_ptr<Token> Tokenizer::next(std::istream &is, SymbolTablePtr symbols) {
// Clear any whitespace until the next token. This works because no token
// depends on _leading_ whitespace, as long as it is separated from the
// previous token.
while(std::isspace(is.peek())) is.get();
// Now that we've cleared whitespace, may be at EOF.
if(!is.good()) return NULL;
for(size_t i = 0; i < TOKEN_PARSING_FUNCS_LENGTH; i++) {
std::streampos pos = is.tellg();
TokenParsingFunc f = TOKEN_PARSING_FUNCS[i];
boost::shared_ptr<Token> token = f(is, symbols);
if(token) {
return token;
} else {
is.seekg(pos);
}
}
std::cerr << "Tokenizer error!" << std::endl;
exit(0);
return NULL;
}
示例3: determineEndianness
void OgreMeshDeserializer::determineEndianness(std::istream& stream)
{
if (stream.tellg() != 0) {
throw std::runtime_error(
"Can only determine the endianness of the input stream if it "
"is at the start");
}
std::uint16_t dest;
// read header id manually (no conversion)
stream.read(reinterpret_cast<char*>(&dest), sizeof(std::uint16_t));
auto actually_read = stream.gcount();
// skip back
stream.seekg(0);
if (actually_read != sizeof(std::uint16_t)) {
// end of file?
std::runtime_error("Couldn't read 16 bit header value from input stream.");
}
if (dest == HEADER_STREAM_ID) {
m_flipEndian = false;
} else if (dest == OTHER_ENDIAN_HEADER_STREAM_ID) {
m_flipEndian = true;
} else {
std::runtime_error("Header chunk didn't match either endian: Corrupted stream?");
}
}
示例4: load
bool load(std::istream &in, Memory& mem, addr_t img_base) {
if (virt_sz > 0) {
addr_t sect_addr_va = img_base + virt_addr;
int prot = get_prot(charac);
mem.alloc_protect(sect_addr_va , virt_sz, prot | Memory::Write);
//TODO check for file_sz > virt_sz (explained in spec)
if (file_sz > 0) {
std::istream::streampos pos_orig = in.tellg();
if (pos_orig == std::istream::pos_type(std::istream::off_type(-1)))
return false;
in.seekg(file_pos, std::ios_base::beg);
// TODO is "bad()" the right thing to check?
if (in.bad())
return false;
char *sect_data = new char[file_sz];
in.read(sect_data, file_sz);
if (std::size_t(in.gcount()) < file_sz) {
delete[] sect_data;
return false;
}
// perhaps change "write" interface to accept const char * to
// avoid this copying madness?
mem.write(sect_addr_va, std::string(sect_data, file_sz));
delete[] sect_data;
if (!(prot & Memory::Write))
mem.alloc_protect(sect_addr_va, virt_sz, prot);
in.seekg(pos_orig);
if (in.bad())
return false;
}
}
return true;
}
示例5: while
bool archive::get_file(std::istream & stream_, const entry_p entry, file_p output) {
uint32_t file_offset, bytes_read, use_size;
std::streampos _save = stream_.tellg();
file_offset = begin_data_offset + entry->offset;
use_size = std::max(entry->size, entry->storage_size);
output->data = new uint8_t[use_size];
bytes_read = 0;
stream_.seekg(file_offset, stream_.beg);
while (bytes_read < use_size) {
if (!stream_.read((char *)output->data + bytes_read, use_size - bytes_read)) {
delete[] output->data;
output->data = nullptr;
return false;
}
bytes_read += stream_.gcount();
}
output->size = use_size;
output->entry = entry;
stream_.seekg(_save, stream_.beg);
return true;
}
示例6: getSparseCount
static uint64_t getSparseCount(std::istream & CIS)
{
CIS.clear();
CIS.seekg(0,std::ios::end);
uint64_t const n = CIS.tellg() / (2*sizeof(uint64_t));
return n;
}
示例7: parse_full
bool demo_csgo::parse_full(std::istream& is) {
while(!this->case_demo_stop) {
int64_t start_pos = is.tellg();
memset(&this->current_cmdheader, 0, sizeof(demo_cmdheader));
if(!demo_cmdheader_read(is, this->current_cmdheader)) {
std::cerr << "demo_csgo::parse_full(): !demo_cmdheader_read(is, this->current_cmdheader)" << std::endl;
return false;
}
bool success;
switch(this->current_cmdheader.cmd) {
case DEMO_SIGNON: success = handle_cmdheader<DEMO_SIGNON>(is, this->current_cmdheader); break;
case DEMO_PACKET: success = handle_cmdheader<DEMO_PACKET>(is, this->current_cmdheader); break;
case DEMO_SYNCTICK: success = handle_cmdheader<DEMO_SYNCTICK>(is, this->current_cmdheader); break;
case DEMO_CONSOLECMD: success = handle_cmdheader<DEMO_CONSOLECMD>(is, this->current_cmdheader); break;
case DEMO_USERCMD: success = handle_cmdheader<DEMO_USERCMD>(is, this->current_cmdheader); break;
case DEMO_DATATABLES: success = handle_cmdheader<DEMO_DATATABLES>(is, this->current_cmdheader); break;
case DEMO_STOP: success = handle_cmdheader<DEMO_STOP>(is, this->current_cmdheader); break;
case DEMO_CUSTOMDATA: success = handle_cmdheader<DEMO_CUSTOMDATA>(is, this->current_cmdheader); break;
case DEMO_STRINGTABLES: success = handle_cmdheader<DEMO_STRINGTABLES>(is, this->current_cmdheader); break;
default:
std::cerr << "demo_csgo::parse_full(): switch(this->current_cmdheader.cmd), default case, this->current_cmdheader.cmd=" << std::dec << (uint32_t)this->current_cmdheader.cmd << std::endl;
}
if(!success) {
std::cerr << "demo_csgo::parse_full(): !success" << std::endl;
return false;
}
}
return true;
}
示例8: fprintf
bool L3DS::Load(std::istream &is)
{
// get length of file:
is.seekg(0, std::ios::end);
m_bufferSize = is.tellg();
is.seekg(0, std::ios::beg);
m_buffer = static_cast<unsigned char*>(calloc(m_bufferSize, 1));
if (m_buffer == 0)
{
fprintf(stderr, "L3DS::LoadFile - not enough memory (malloc failed)");
return false;
}
is.read(reinterpret_cast<char *>(m_buffer), m_bufferSize);
if(is.gcount() != std::streamsize(m_bufferSize))
{
free(m_buffer);
m_bufferSize = 0;
fprintf(stderr, "L3DS::LoadFile - error reading from stream");
return false;
}
Clear();
bool res = Read3DS();
free(m_buffer);
m_buffer = 0;
m_bufferSize = 0;
return res;
}
示例9: readEntry
IndexEntry readEntry(std::istream & indexistr, uint64_t const entryid) const
{
uint64_t const entrybitpos = getEntryBitPos(entryid);
uint64_t const entrybytepos = entrybitpos>>3;
uint64_t const entrybitoff = entrybitpos - (entrybytepos<<3);
// seek to index position
indexistr.clear();
indexistr.seekg(entrybytepos,std::ios::beg);
if ( static_cast<int64_t>(indexistr.tellg()) != static_cast<int64_t>(entrybytepos) )
{
::libmaus2::exception::LibMausException se;
se.getStream() << "Failed to seek to index position " << entrybytepos << " in file " << filename << " of size "
<< ::libmaus2::util::GetFileSize::getFileSize(filename) << std::endl;
se.finish();
throw se;
}
::libmaus2::bitio::StreamBitInputStream SBIS(indexistr);
SBIS.read(entrybitoff);
uint64_t const pos = SBIS.read(posbits);
uint64_t const kcnt = SBIS.read(kbits);
uint64_t const vcnt = SBIS.read(vbits);
return IndexEntry(pos,kcnt,vcnt);
}
示例10: while
msdata::msdata(std::istream& in, size_t fsize) : loaded_( false )
{
static_assert(sizeof( detail::msdata ) == msdata::block_size
, "struct 'msdata' not alinged to 256 octets, check declaration.");
int16_t scan = 0;
while ( ( fsize - in.tellg() ) >= block_size ) {
//auto pos = in.tellg();
auto d = std::make_shared< detail::msdata >();
in.read( reinterpret_cast<char *>(d.get()), block_size );
//const detail::msdata * pdata = d.get();
if ( in.fail() )
return;
if ( (d->flags & 0x0f) != record_type_code )
return;
if ( scan == 0 ) // 1-orign value
scan = d->scan;
if ( scan != d->scan )
return;
data_.push_back( d );
}
}
示例11: check_contents
static void check_contents(std::istream& s)
{
int c;
c = s.get();
BOOST_CHECK(c == 'R');
c = s.get();
BOOST_CHECK(c == 'e');
s.seekg(-4, std::ios_base::end);
std::streamoff e = s.tellg();
BOOST_CHECK(e == 78);
c = s.get();
BOOST_CHECK(c == 'n');
BOOST_CHECK(!s.eof());
BOOST_CHECK(s.get() == '.');
BOOST_CHECK(s.get() == '.');
BOOST_CHECK(s.get() == '.');
BOOST_CHECK(s.get() == -1);
BOOST_CHECK(s.eof());
return;
}
示例12: readSimpleToken
void BoWBinaryReaderPrivate::readSimpleToken(std::istream& file,
BoWToken* token)
{
LimaString lemma,inflectedForm;
Misc::readUTF8StringField(file,lemma);
#ifdef DEBUG_LP
BOWLOGINIT;
LDEBUG << "BoWBinaryReader::readSimpleToken file at: " << file.tellg();
LDEBUG << "BoWBinaryReader::readSimpleToken read lemma: " << lemma;
#endif
Misc::readUTF8StringField(file,inflectedForm);
#ifdef DEBUG_LP
LDEBUG << "BoWBinaryReader::readSimpleToken read infl: " << inflectedForm;
#endif
LinguisticCode category;
uint64_t position,length;
category=static_cast<LinguisticCode>(Misc::readCodedInt(file));
position=Misc::readCodedInt(file);
length=Misc::readCodedInt(file);
token->setLemma(lemma);
token->setInflectedForm(inflectedForm);
token->setCategory(category);
token->setPosition(position);
token->setLength(length);
}
示例13: findNextCompatFrame
// moves the read pointer to the first frame compatible with the stream; returns "false" if no such frame is found
bool MpegStream::findNextCompatFrame(std::istream& in, std::streampos posMax)
{
streampos pos (in.tellg());
NoteColl notes (10);
for (;;)
{
try
{
pos = getNextStream(in, pos);
if (pos > posMax)
{
return false;
}
in.seekg(pos);
try
{
MpegFrameBase frm (notes, in);
if (isCompatible(frm))
{
in.seekg(pos);
return true;
}
}
catch (const MpegFrameBase::NotMpegFrame&)
{
}
}
catch (const EndOfFile&)
{
return false;
}
}
}
示例14: initReadProgress
void SceneFileHandlerBase::initReadProgress(std::istream &is)
{
if(_readProgressFP == NULL)
return;
// get length of the stream.
_progressData.is = &is;
is.seekg(0, std::ios::end);
_progressData.length = is.tellg();
is.seekg(0, std::ios::beg);
_readReady = false;
if(_useProgressThread)
{
_progressData.thread = Thread::find("OSG::FileIOReadProgressThread");
if(_progressData.thread == NULL)
{
_progressData.thread =
OSG::Thread::get("OSG::FileIOReadProgressThread", true);
}
if(_progressData.thread != NULL)
{
_progressData.thread->runFunction(readProgress, 0, NULL);
}
else
{
SWARNING << "Couldn't create read progress thread!" << std::endl;
}
}
}
示例15: ReadVb
void Vab::ReadVb( std::istream& aStream )
{
// aStream.setByteOrder( QDataStream::LittleEndian );
aStream.seekg(0, aStream.end);
int streamSize = aStream.tellg();
aStream.seekg(0, aStream.beg);
if (streamSize > 5120) // No exoddus vb is greater than 5kb
{
for (_Uint32t i = 0; i < iHeader->iNumVags; ++i)
{
AoVag* vag = new AoVag();
aStream.read((char*)&vag->iSize, sizeof(vag->iSize));
aStream.read((char*)&vag->iSampleRate, sizeof(vag->iSampleRate));
vag->iSampleData.resize(vag->iSize);
aStream.read((char*)vag->iSampleData.data(), vag->iSize);
iAoVags.push_back(vag);
}
}
else
{
for (unsigned int i = 0; i < iHeader->iNumVags; i++)
{
AEVh* vh = new AEVh(aStream);
iOffs.push_back(vh);
}
}
}