当前位置: 首页>>代码示例>>C++>>正文


C++ TFile::Seek方法代码示例

本文整理汇总了C++中TFile::Seek方法的典型用法代码示例。如果您正苦于以下问题:C++ TFile::Seek方法的具体用法?C++ TFile::Seek怎么用?C++ TFile::Seek使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TFile的用法示例。


在下文中一共展示了TFile::Seek方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: FindUMXNameTableEntryImpl

static bool FindUMXNameTableEntryImpl(TFile &file, const UMXFileHeader &fileHeader, const char *name)
{
	if(!name)
	{
		return false;
	}
	std::size_t name_len = std::strlen(name);
	if(name_len == 0)
	{
		return false;
	}
	bool result = false;
	const FileReader::off_t oldpos = file.GetPosition();
	if(file.Seek(fileHeader.nameOffset))
	{
		for(uint32 i = 0; i < fileHeader.nameCount && file.CanRead(4); i++)
		{
			if(fileHeader.packageVersion >= 64)
			{
				int32 length = ReadUMXIndexImpl(file);
				if(length <= 0)
				{
					continue;
				}
			}
			bool match = true;
			std::size_t pos = 0;
			char c = 0;
			while((c = file.ReadUint8()) != 0)
			{
				c = mpt::ToLowerCaseAscii(c);
				if(pos < name_len)
				{
					match = match && (c == name[pos]);
				}
				pos++;
			}
			if(pos != name_len)
			{
				match = false;
			}
			if(match)
			{
				result = true;
			}
			file.Skip(4);  // Object flags
		}
	}
	file.Seek(oldpos);
	return result;
}
开发者ID:kode54,项目名称:Cog,代码行数:51,代码来源:UMXTools.cpp

示例2: PrechargeImpl

// maybe we should move this function to another .cpp file to avoid unwanted optimization?
static int PrechargeImpl(TFile f, void* data, size_t dataSize, size_t off, size_t size) {
    if (off > dataSize) {
        assert(false);
        return 0;
    }
    size_t endOff = (size == (size_t)-1 ? dataSize : off + size);
    if (endOff > dataSize) {
        assert(false);
        endOff = dataSize;
    }
    size = endOff - off;
    if (dataSize == 0 || size == 0)
        return 0;

    const char *c = (char*)data + off, *e = c + size;
    int n = 0;
#ifdef _freebsd_
    if (off % PAGE_SIZE) {
        off = off / PAGE_SIZE * PAGE_SIZE; // align on PAGE_SIZE
        size = endOff - off;
        c = (char*)data + off;
    }

    madvise((void*)c, e - c, MADV_WILLNEED);
    f.Seek(0, sSet);
    const size_t rdSize1 = 64 << 20, rdSize2 = 4 << 20;
    const size_t rdSize = size > rdSize2 * 32? rdSize1 : rdSize2;
    TArrayHolder<char> pages(new char[(rdSize1 + PAGE_SIZE - 1) / PAGE_SIZE]);
    TBuffer buf(Min(rdSize, size));
    ui32 nbufs = 0, nread = 0;
    for (size_t r = 0; r < size; r += rdSize) {
        bool needRead = true;
        size_t toRead = Min(rdSize, size - r);
        if (mincore(c + r, toRead, pages.Get()) != -1)
            needRead = memchr(pages.Get(), 0, (toRead + PAGE_SIZE - 1) / PAGE_SIZE) != 0;
        if (needRead)
            f.Read(buf.Data(), toRead);
        madvise((void*)(c + r), toRead, MADV_WILLNEED);
        for (const char *d = c; d < c + r; d += 512)
            n += *d;
        nbufs++;
        nread += needRead;
    }
    //warnx("precharge: read %u/%u (blk %"PRISZT")", nread, nbufs, rdSize);
    return 0;
#else
    UNUSED(f);
#endif
    for (; c < e; c += 512)
        n += *c;
    return n; // prevent loop optimization
}
开发者ID:Mirocow,项目名称:balancer,代码行数:53,代码来源:filemap.cpp

示例3: if

__int64 CDVDInputStreamStack::Seek(__int64 offset, int whence)
{
  __int64 pos, len;

  if     (whence == SEEK_SET)
    pos = offset;
  else if(whence == SEEK_CUR)
    pos = offset + m_pos;
  else if(whence == SEEK_END)
    pos = offset + m_length;
  else
    return -1;

  len = 0;
  for(TSegVec::iterator it = m_files.begin(); it != m_files.end(); it++)
  {
    if(len + it->length > pos)
    {
      TFile   file     = it->file;
      __int64 file_pos = pos - len;
      if(file->GetPosition() != file_pos)
      {
        if(file->Seek(file_pos, SEEK_SET) < 0)
          return false;
      }

      m_file = file;
      m_pos  = pos;
      m_eof  = false;
      return pos;
    }
    len += it->length;
  }

  return -1;
}
开发者ID:AWilco,项目名称:xbmc,代码行数:36,代码来源:DVDInputStreamStack.cpp

示例4: main


//.........这里部分代码省略.........
            std::cout << pfn << " appears not to have been closed correctly and has been autorecovered \n";
            std::cout << "Proceeding anyway\n";
          }
        } else {
          std::cout << pfn << " appears not to have been closed correctly and has been autorecovered \n";
          std::cout << "Stopping. Use --allowRecovery to try ignoring this\n";
          return 1;
        }
      } else {
        if (verbose) std::cout << "ECU:: Collection not autorecovered. Continuing\n";
      }

      // Ok. Do we have the expected trees?
      for (unsigned int i = 0; i < expectedTrees.size(); ++i) {
        TTree *t = (TTree*) tfile->Get(expectedTrees[i].c_str());
        if (t == 0) {
          std::cout << "Tree " << expectedTrees[i] << " appears to be missing. Not a valid collection\n";
          std::cout << "Exiting\n";
          return 1;
        } else {
          if (verbose) std::cout << "ECU:: Found Tree " << expectedTrees[i] << std::endl;
        }
      }

      if (verbose) std::cout << "ECU:: Found all expected trees\n";

      std::ostringstream auout;
      if (adler32) {
        unsigned int const EDMFILEUTILADLERBUFSIZE = 10*1024*1024; // 10MB buffer
        char buffer[EDMFILEUTILADLERBUFSIZE];
        size_t bufToRead = EDMFILEUTILADLERBUFSIZE;
        uint32_t a = 1, b = 0;
        size_t fileSize = tfile->GetSize();
        tfile->Seek(0, TFile::kBeg);

        for (size_t offset = 0; offset < fileSize;
              offset += EDMFILEUTILADLERBUFSIZE) {
            // true on last loop
            if (fileSize - offset < EDMFILEUTILADLERBUFSIZE)
              bufToRead = fileSize - offset;
            tfile->ReadBuffer((char*)buffer, bufToRead);
            cms::Adler32(buffer, bufToRead, a, b);
        }
        uint32_t adler32sum = (b << 16) | a;
        if (json) {
          auout << ",\"adler32sum\":" << adler32sum;
        } else {
          auout << ", " << std::hex << adler32sum << " adler32sum";
        }
      }

      if (uuid) {
        TTree *paramsTree = (TTree*)tfile->Get(edm::poolNames::metaDataTreeName().c_str());
        if (json) {
          auout << ",\"uuid\":\"" << edm::getUuid(paramsTree) << '"';
        } else {
          auout << ", " << edm::getUuid(paramsTree) << " uuid";
        }
      }

      // Ok. How many events?
      int nruns = edm::numEntries(tfile, edm::poolNames::runTreeName());
      int nlumis = edm::numEntries(tfile, edm::poolNames::luminosityBlockTreeName());
      int nevents = edm::numEntries(tfile, edm::poolNames::eventTreeName());
      if (json) {
        if (j > 0) std::cout << ',' << std::endl;
开发者ID:12345ieee,项目名称:cmg-cmssw,代码行数:67,代码来源:EdmFileUtil.cpp


注:本文中的TFile::Seek方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。