• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ TemporaryFile类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: myDirectory

TemporaryDirectory::TemporaryDirectory(const std::string& aDirPath)
{
    theDirPath = aDirPath;
    
    boost::filesystem::path myDirectory(theDirPath);

    if(!boost::filesystem::exists(myDirectory))
    {
        std::string myError("Directory ");
        myError += theDirPath;
        myError += " does not exist";
        throw std::runtime_error(myError);
    }

    if ( ! boost::filesystem::is_directory(myDirectory) ) {
        
        std::string myError = theDirPath;
        myError += " is not a directory";
        throw std::runtime_error(myError);
    }
    
    boost::filesystem::directory_iterator myEndIter;
    boost::filesystem::directory_iterator myDirIter(myDirectory);
    for(/*void*/;
        myDirIter != myEndIter;
        ++myDirIter)
    {
        TemporaryFile * myFile = new TemporaryFile(theDirPath + "/" + myDirIter->leaf() );

        theFiles.insert(std::make_pair(myFile->getFileName(), myFile));
    }
}
开发者ID:graingert,项目名称:6share,代码行数:32,代码来源:TemporaryDirectory.cpp


示例2: TEST

TEST(String, readFile) {
  const TemporaryFile afileTemp, emptyFileTemp;
  auto afile = afileTemp.path().string();
  auto emptyFile = emptyFileTemp.path().string();

  EXPECT_TRUE(writeFile(string(), emptyFile.c_str()));
  EXPECT_TRUE(writeFile(StringPiece("bar"), afile.c_str()));

  {
    string contents;
    EXPECT_TRUE(readFile(emptyFile.c_str(), contents));
    EXPECT_EQ(contents, "");
    EXPECT_TRUE(readFile(afile.c_str(), contents, 0));
    EXPECT_EQ("", contents);
    EXPECT_TRUE(readFile(afile.c_str(), contents, 2));
    EXPECT_EQ("ba", contents);
    EXPECT_TRUE(readFile(afile.c_str(), contents));
    EXPECT_EQ("bar", contents);
  }
  {
    vector<unsigned char> contents;
    EXPECT_TRUE(readFile(emptyFile.c_str(), contents));
    EXPECT_EQ(vector<unsigned char>(), contents);
    EXPECT_TRUE(readFile(afile.c_str(), contents, 0));
    EXPECT_EQ(vector<unsigned char>(), contents);
    EXPECT_TRUE(readFile(afile.c_str(), contents, 2));
    EXPECT_EQ(vector<unsigned char>({'b', 'a'}), contents);
    EXPECT_TRUE(readFile(afile.c_str(), contents));
    EXPECT_EQ(vector<unsigned char>({'b', 'a', 'r'}), contents);
  }
}
开发者ID:SamSaffron,项目名称:DiscourseMobile,代码行数:31,代码来源:FileUtilTest.cpp


示例3: test_write_empty_workbook

 void test_write_empty_workbook()
 {
     xlnt::workbook wb;
     TemporaryFile file;
     xlnt::save_workbook(wb, file.GetFilename());
     TS_ASSERT(PathHelper::FileExists(file.GetFilename()));
 }
开发者ID:MoffD,项目名称:xlnt,代码行数:7,代码来源:test_write_workbook.hpp


示例4: TEST

TEST(RecordIOTest, Simple) {
  TemporaryFile file;
  {
    RecordIOWriter writer(File(file.fd()));
    writer.write(iobufs({"hello ", "world"}));
    writer.write(iobufs({"goodbye"}));
  }
  {
    RecordIOReader reader(File(file.fd()));
    auto it = reader.begin();
    ASSERT_FALSE(it == reader.end());
    EXPECT_EQ("hello world", sp((it++)->first));
    ASSERT_FALSE(it == reader.end());
    EXPECT_EQ("goodbye", sp((it++)->first));
    EXPECT_TRUE(it == reader.end());
  }
  {
    RecordIOWriter writer(File(file.fd()));
    writer.write(iobufs({"meow"}));
    writer.write(iobufs({"woof"}));
  }
  {
    RecordIOReader reader(File(file.fd()));
    auto it = reader.begin();
    ASSERT_FALSE(it == reader.end());
    EXPECT_EQ("hello world", sp((it++)->first));
    ASSERT_FALSE(it == reader.end());
    EXPECT_EQ("goodbye", sp((it++)->first));
    ASSERT_FALSE(it == reader.end());
    EXPECT_EQ("meow", sp((it++)->first));
    ASSERT_FALSE(it == reader.end());
    EXPECT_EQ("woof", sp((it++)->first));
    EXPECT_TRUE(it == reader.end());
  }
}
开发者ID:derek-zhang,项目名称:folly,代码行数:35,代码来源:RecordIOTest.cpp


示例5: process

  bool process ()
  {
    bool error = false;

    // Make sure the template file exists

    if (! m_templateFile.existsAsFile())
    {
      std::cout << name () << " The template file doesn't exist!\n\n";
      error = true;
    }

    if (!error)
    {
      // Prepare to write output to a temporary file.

      std::cout << "  Building: " << m_targetFile.getFullPathName() << "...\n";

      TemporaryFile temp (m_targetFile);
      ScopedPointer <FileOutputStream> out (temp.getFile().createOutputStream (1024 * 128));

      if (out == 0)
      {
        std::cout << "  \n!! ERROR - couldn't write to the target file: "
          << temp.getFile().getFullPathName() << "\n\n";
        return false;
      }

      out->setNewLineString ("\n");

      if (! parseFile (m_targetFile.getParentDirectory(),
        m_targetFile,
        *out,
        m_templateFile,
        m_alreadyIncludedFiles,
        m_includesToIgnore,
        m_wildcards,
        0, false))
      {
        return false;
      }

      out = 0;

      if (calculateFileHashCode (m_targetFile) == calculateFileHashCode (temp.getFile()))
      {
        std::cout << "   -- No need to write - new file is identical\n";
        return true;
      }

      if (! temp.overwriteTargetFileWithTemporary())
      {
        std::cout << "  \n!! ERROR - couldn't write to the target file: "
          << m_targetFile.getFullPathName() << "\n\n";
        return false;
      }
    }

    return error;
  }
开发者ID:Terricide,项目名称:HumbleNet,代码行数:60,代码来源:Amalgamate.cpp


示例6: munge

//==============================================================================
static bool munge (const File& templateFile, const File& targetFile, const String& wildcard,
                   StringArray& alreadyIncludedFiles, const StringArray& includesToIgnore)
{
    if (! templateFile.existsAsFile())
    {
        std::cout << " The template file doesn't exist!\n\n";
        return false;
    }

    StringArray wildcards;
    wildcards.addTokens (wildcard, ";,", "'\"");
    wildcards.trim();
    wildcards.removeEmptyStrings();

    std::cout << "Building: " << targetFile.getFullPathName() << "...\n";

    TemporaryFile temp (targetFile);
    ScopedPointer <FileOutputStream> out (temp.getFile().createOutputStream (1024 * 128));

    if (out == 0)
    {
        std::cout << "\n!! ERROR - couldn't write to the target file: "
                  << temp.getFile().getFullPathName() << "\n\n";
        return false;
    }

    out->setNewLineString ("\n");

    if (! parseFile (targetFile.getParentDirectory(),
                     targetFile,
                     *out, templateFile,
                     alreadyIncludedFiles,
                     includesToIgnore,
                     wildcards,
                     true, false))
    {
        return false;
    }

    out = 0;

    if (calculateFileHashCode (targetFile) == calculateFileHashCode (temp.getFile()))
    {
        std::cout << " -- No need to write - new file is identical\n";
        return true;
    }

    if (! temp.overwriteTargetFileWithTemporary())
    {
        std::cout << "\n!! ERROR - couldn't write to the target file: "
                  << targetFile.getFullPathName() << "\n\n";
        return false;
    }

    return true;
}
开发者ID:randi2kewl,项目名称:ShoutOut,代码行数:57,代码来源:Main.cpp


示例7: test_write_empty_workbook

    void test_write_empty_workbook()
    {
        xlnt::workbook wb;
        TemporaryFile file;

        xlnt::excel_serializer serializer(wb);
        serializer.save_workbook(file.GetFilename());
        
        TS_ASSERT(PathHelper::FileExists(file.GetFilename()));
    }
开发者ID:xpol,项目名称:xlnt,代码行数:10,代码来源:test_write_workbook.hpp


示例8: MtpNameTooLong

void MtpFolder::CreateFile(const std::string& name)
{
	if (name.length() > MAX_MTP_NAME_LENGTH)
		throw MtpNameTooLong();

	NewLIBMTPFile newFile(name, m_folderId, m_storageId);
	TemporaryFile empty;
	m_device.SendFile(newFile, empty.FileNo());
	m_cache.clearItem(((LIBMTP_file_t*)newFile)->item_id);
	m_cache.clearItem(m_id);
}
开发者ID:JasonFerrara,项目名称:jmtpfs,代码行数:11,代码来源:MtpFolder.cpp


示例9: testStreamOpenerPath

void URIStreamOpenerTest::testStreamOpenerPath()
{
	TemporaryFile tempFile;
	std::string path = tempFile.path();
	std::ofstream ostr(path.c_str());
	assert (ostr.good());
	ostr << "Hello, world!" << std::endl;
	ostr.close();
		
	URIStreamOpener opener;
	std::istream* istr = opener.open(path);
	assert (istr != 0);
	assert (istr->good());
	delete istr;
}
开发者ID:Victorcasas,项目名称:georest,代码行数:15,代码来源:URIStreamOpenerTest.cpp


示例10: overwriteFileWithNewDataIfDifferent

    bool overwriteFileWithNewDataIfDifferent (const File& file, const void* data, int numBytes)
    {
        if (file.getSize() == numBytes)
        {
            MemoryInputStream newStream (data, numBytes, false);

            if (calculateStreamHashCode (newStream) == calculateFileHashCode (file))
                return true;
        }

        TemporaryFile temp (file);

        return temp.getFile().appendData (data, numBytes)
                 && temp.overwriteTargetFileWithTemporary();
    }
开发者ID:Labmind,项目名称:GUI,代码行数:15,代码来源:jucer_FileHelpers.cpp


示例11: testStreamOpenerRelative

void URIStreamOpenerTest::testStreamOpenerRelative()
{
	TemporaryFile tempFile;
	std::string path = tempFile.path();
	std::ofstream ostr(path.c_str());
	assert (ostr.good());
	ostr << "Hello, world!" << std::endl;
	ostr.close();
	
	URI uri(Path(path).toString(Path::PATH_UNIX));
	std::string uriString = uri.toString();
	
	URIStreamOpener opener;
	std::istream* istr = opener.open(uri);
	assert (istr != 0);
	assert (istr->good());
	delete istr;
}
开发者ID:Victorcasas,项目名称:georest,代码行数:18,代码来源:URIStreamOpenerTest.cpp


示例12: mySender

unsigned long long FluteLibTest::performsFileSend(
    const TemporaryFile& aTemporaryFile, int aKBitRates)
{
    FluteSender mySender(aTemporaryFile.getFilePath(), aKBitRates);

    unsigned long long mySessionSize = mySender.sessionSize();
    mySender.startSending();

    return mySessionSize;
}
开发者ID:AdithyanIlangovan,项目名称:ATSC_ROUTE,代码行数:10,代码来源:FluteLibTest.cpp


示例13: testStreamOpenerPathResolve

void URIStreamOpenerTest::testStreamOpenerPathResolve()
{
	TemporaryFile tempFile;
	std::string path = tempFile.path();
	std::ofstream ostr(path.c_str());
	assert (ostr.good());
	ostr << "Hello, world!" << std::endl;
	ostr.close();
	
	Path p(path);
	Path parent(p.parent());
	std::string base = parent.toString();
		
	URIStreamOpener opener;
	std::istream* istr = opener.open(base, p.getFileName());
	assert (istr != 0);
	assert (istr->good());
	delete istr;
}
开发者ID:Victorcasas,项目名称:georest,代码行数:19,代码来源:URIStreamOpenerTest.cpp


示例14: tempFile

void FileLogger::trimFileSize (int64 maxFileSizeBytes) const
{
    if (maxFileSizeBytes <= 0)
    {
        logFile.deleteFile();
    }
    else
    {
        const int64 fileSize = logFile.getSize();

        if (fileSize > maxFileSizeBytes)
        {
            TemporaryFile tempFile (logFile);

            {
                FileOutputStream out (tempFile.getFile());
                FileInputStream in (logFile);

                if (! (out.openedOk() && in.openedOk()))
                    return;

                in.setPosition (fileSize - maxFileSizeBytes);

                for (;;)
                {
                    const char c = in.readByte();
                    if (c == 0)
                        return;

                    if (c == '\n' || c == '\r')
                    {
                        out << c;
                        break;
                    }
                }

                out.writeFromInputStream (in, -1);
            }

            tempFile.overwriteTargetFileWithTemporary();
        }
    }
}
开发者ID:AUSTRALIANBITCOINS,项目名称:rippled,代码行数:43,代码来源:beast_FileLogger.cpp


示例15: temp

bool Utils::writeStringToFile(const String& s, const File& f)
{
	TemporaryFile temp (f);

	ScopedPointer <FileOutputStream> out (temp.getFile().createOutputStream());

	if (out != nullptr)
	{
		out->write(s.toUTF8(), s.getNumBytesAsUTF8());
		out = nullptr; // (deletes the stream)

		bool succeeded = temp.overwriteTargetFileWithTemporary();
		return succeeded;
	}
	else
	{
		return false;
	}
}
开发者ID:alessandrostone,项目名称:SaM-Designer,代码行数:19,代码来源:MiscUtilities.cpp


示例16: TEST

TEST(sys_mman, mmap_file_write_at_offset) {
    TemporaryFile tf;
    size_t pagesize = sysconf(_SC_PAGESIZE);

    // Create the file with three pages worth of data.
    ASSERT_EQ(STR_SSIZE(PAGE0_MSG), write(tf.fd, PAGE0_MSG, sizeof(PAGE0_MSG)));
    ASSERT_NE(-1, lseek(tf.fd, pagesize, SEEK_SET));
    ASSERT_EQ(STR_SSIZE(PAGE1_MSG), write(tf.fd, PAGE1_MSG, sizeof(PAGE1_MSG)));
    ASSERT_NE(-1, lseek(tf.fd, 2 * pagesize, SEEK_SET));
    ASSERT_EQ(STR_SSIZE(PAGE2_MSG), write(tf.fd, PAGE2_MSG, sizeof(PAGE2_MSG)));
    ASSERT_NE(-1, lseek(tf.fd, 3 * pagesize - sizeof(END_MSG), SEEK_SET));
    ASSERT_EQ(STR_SSIZE(END_MSG), write(tf.fd, END_MSG, sizeof(END_MSG)));

    ASSERT_NE(-1, lseek(tf.fd, 0, SEEK_SET));

    void* map = mmap(NULL, pagesize, PROT_WRITE, MAP_SHARED, tf.fd, pagesize);
    ASSERT_NE(MAP_FAILED, map);
    close(tf.fd);

    memcpy(map, NEWPAGE1_MSG, sizeof(NEWPAGE1_MSG));
    ASSERT_EQ(0, munmap(map, pagesize));

    tf.reopen();
    map = mmap(NULL, pagesize, PROT_WRITE, MAP_SHARED, tf.fd, 2 * pagesize);
    ASSERT_NE(MAP_FAILED, map);
    close(tf.fd);

    memcpy(map, NEWPAGE2_MSG, sizeof(NEWPAGE2_MSG));
    ASSERT_EQ(0, munmap(map, pagesize));

    tf.reopen();
    char buf[pagesize];
    ASSERT_EQ(static_cast<ssize_t>(pagesize), read(tf.fd, buf, pagesize));
    ASSERT_STREQ(PAGE0_MSG, buf);
    ASSERT_NE(-1, lseek(tf.fd, pagesize, SEEK_SET));
    ASSERT_EQ(static_cast<ssize_t>(pagesize), read(tf.fd, buf, pagesize));
    ASSERT_STREQ(NEWPAGE1_MSG, buf);
    ASSERT_NE(-1, lseek(tf.fd, 2 * pagesize, SEEK_SET));
    ASSERT_EQ(static_cast<ssize_t>(pagesize), read(tf.fd, buf, pagesize));
    ASSERT_STREQ(NEWPAGE2_MSG, buf);
    ASSERT_STREQ(END_MSG, buf+pagesize-sizeof(END_MSG));
}
开发者ID:MonkeyZZZZ,项目名称:platform_bionic,代码行数:42,代码来源:sys_mman_test.cpp


示例17: CleanOutGarbageRegistry

	static void CleanOutGarbageRegistry()
	{
		char gbgFile[1024];
		GetTempPath(1024, gbgFile);
		strcat(gbgFile, "GensTempFileRecords");

		char key[64];
		int i = 0;
		while(true)
		{
			sprintf(key, "File%d", i);
			GetPrivateProfileString("Files", key, "", Str_Tmp, 1024, gbgFile);
			if(!*Str_Tmp)
				break;
			TemporaryFile temp;
			strcpy(temp.filename, Str_Tmp);
			if(!temp.Delete(true))
				i++;
		}
	}
开发者ID:snowasnow,项目名称:DeSmuME,代码行数:20,代码来源:OpenArchive.cpp


示例18: TEST

TEST(LineReader, Simple) {
  TemporaryFile file;
  int fd = file.fd();
  writeAll(fd,
           "Meow\n"
           "Hello world\n"
           "This is a long line. It is longer than the other lines.\n"
           "\n"
           "Incomplete last line");

  {
    CHECK_ERR(lseek(fd, 0, SEEK_SET));
    char buf[10];
    LineReader lr(fd, buf, sizeof(buf));
    expect(lr, "Meow\n");
    expect(lr, "Hello worl");
    expect(lr, "d\n");
    expect(lr, "This is a ");
    expect(lr, "long line.");
    expect(lr, " It is lon");
    expect(lr, "ger than t");
    expect(lr, "he other l");
    expect(lr, "ines.\n");
    expect(lr, "\n");
    expect(lr, "Incomplete");
    expect(lr, " last line");
    expect(lr, "");
  }

  {
    CHECK_ERR(lseek(fd, 0, SEEK_SET));
    char buf[80];
    LineReader lr(fd, buf, sizeof(buf));
    expect(lr, "Meow\n");
    expect(lr, "Hello world\n");
    expect(lr, "This is a long line. It is longer than the other lines.\n");
    expect(lr, "\n");
    expect(lr, "Incomplete last line");
    expect(lr, "");
  }
}
开发者ID:HunterChen,项目名称:folly,代码行数:41,代码来源:LineReaderTest.cpp


示例19: TEST

TEST(TemporaryFile, Simple) {
  int fd = -1;
  char c = 'x';
  {
    TemporaryFile f;
    EXPECT_FALSE(f.path().empty());
    EXPECT_TRUE(f.path().is_absolute());
    fd = f.fd();
    EXPECT_LE(0, fd);
    ssize_t r = write(fd, &c, 1);
    EXPECT_EQ(1, r);
  }

  // The file must have been closed.  This assumes that no other thread
  // has opened another file in the meanwhile, which is a sane assumption
  // to make in this test.
  ssize_t r = write(fd, &c, 1);
  int savedErrno = errno;
  EXPECT_EQ(-1, r);
  EXPECT_EQ(EBADF, savedErrno);
}
开发者ID:DrhF,项目名称:folly,代码行数:21,代码来源:TestUtilTest.cpp


示例20: testStreamOpenerURIResolve

void URIStreamOpenerTest::testStreamOpenerURIResolve()
{
	TemporaryFile tempFile;
	std::string path = tempFile.path();
	std::ofstream ostr(path.c_str());
	assert (ostr.good());
	ostr << "Hello, world!" << std::endl;
	ostr.close();
	
	Path p(path);
	p.makeAbsolute();
	Path parent(p.parent());
	
	URI uri;
	uri.setScheme("file");
	uri.setPath(parent.toString(Path::PATH_UNIX));
	std::string uriString = uri.toString();
	
	URIStreamOpener opener;
	std::istream* istr = opener.open(uriString, p.getFileName());
	assert (istr != 0);
	assert (istr->good());
	delete istr;
}
开发者ID:Victorcasas,项目名称:georest,代码行数:24,代码来源:URIStreamOpenerTest.cpp



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ TemporaryPtr类代码示例发布时间:2022-05-31
下一篇:
C++ TemporalValueType类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap