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


C++ FileStream::Open方法代码示例

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


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

示例1: TestClangMSExtensionsPreprocessedOutput

// TestClangMSExtensionsPreprocessedOutput
//------------------------------------------------------------------------------
void TestIncludeParser::TestClangMSExtensionsPreprocessedOutput() const
{
    FBuild fBuild; // needed fer CleanPath for relative dirs

    FileStream f;
    TEST_ASSERT( f.Open( "Data/TestIncludeParser/fbuildcore.clang.ms-extensions.ii", FileStream::READ_ONLY) )
    const size_t fileSize = (size_t)f.GetFileSize();
    AutoPtr< char > mem( (char *)ALLOC( fileSize + 1 ) );
    TEST_ASSERT( f.Read( mem.Get(), fileSize ) == fileSize );
    mem.Get()[ fileSize ] = 0;

    Timer t;

    const size_t repeatCount( 100 );
    for ( size_t i=0; i<repeatCount; ++i )
    {
        CIncludeParser parser;
        TEST_ASSERT( parser.ParseGCC_Preprocessed( mem.Get(), fileSize ) );

        // check number of includes found to prevent future regressions
        const Array< AString > & includes = parser.GetIncludes();
        TEST_ASSERT( includes.GetSize() == 285 );
#ifdef DEBUG
        TEST_ASSERT( parser.GetNonUniqueCount() == 4758 );
#endif
    }

    float time = t.GetElapsed();
    OUTPUT( "Clang (ms-extensions): %2.3fs (%2.1f MiB/sec)\n", time, ( (float)( fileSize * repeatCount / ( 1024.0f * 1024.0f ) ) / time ) );
}
开发者ID:dontnod,项目名称:fastbuild,代码行数:32,代码来源:TestIncludeParser.cpp

示例2: FileCopy

// FileCopy
//------------------------------------------------------------------------------
void TestFileIO::FileCopy() const
{
	// generate a process unique file path
	AStackString<> path;
	GenerateTempFileName( path );

	// generate copy file name
	AStackString<> pathCopy( path );
	pathCopy += ".copy";

	// make sure nothing is left from previous runs
	FileIO::FileDelete( path.Get() );
	FileIO::FileDelete( pathCopy.Get() );
	TEST_ASSERT( FileIO::FileExists( path.Get() ) == false );
	TEST_ASSERT( FileIO::FileExists( pathCopy.Get() ) == false );

	// create it
	FileStream f;
	TEST_ASSERT( f.Open( path.Get(), FileStream::WRITE_ONLY ) == true );
	f.Close();

	// copy it
	TEST_ASSERT( FileIO::FileCopy( path.Get(), pathCopy.Get() ) );
	TEST_ASSERT( FileIO::FileExists( pathCopy.Get() ) == true );

	// copy without overwrite allowed should fail
	const bool allowOverwrite = false;
	TEST_ASSERT( FileIO::FileCopy( path.Get(), pathCopy.Get(), allowOverwrite ) == false );

	// cleanup
	VERIFY( FileIO::FileDelete( path.Get() ) );
	VERIFY( FileIO::FileDelete( pathCopy.Get() ) );
}
开发者ID:scott-nelson,项目名称:fastbuild,代码行数:35,代码来源:TestFileIO.cpp

示例3: FileExists

REGISTER_TESTS_END

// FileExists
//------------------------------------------------------------------------------
void TestFileIO::FileExists() const
{
	// generate a process unique file path
	AStackString<> path;
	GenerateTempFileName( path );

	// ensure doesn't exist
	FileIO::FileDelete( path.Get() ); // delete in case left over from previous test run
	TEST_ASSERT( FileIO::FileExists( path.Get() ) == false );

	// create it
	FileStream f;
	TEST_ASSERT( f.Open( path.Get(), FileStream::WRITE_ONLY ) == true );
	f.Close();

	// ensure exists
	TEST_ASSERT( FileIO::FileExists( path.Get() ) == true );

	// clean up
	TEST_ASSERT( FileIO::FileDelete( path.Get() ) == true );
	TEST_ASSERT( FileIO::FileExists( path.Get() ) == false );
}
开发者ID:scott-nelson,项目名称:fastbuild,代码行数:26,代码来源:TestFileIO.cpp

示例4:

// CreateTempFile
//------------------------------------------------------------------------------
/*static*/ bool WorkerThread::CreateTempFile( const AString & tmpFileName,
										FileStream & file )
{
	ASSERT( tmpFileName.IsEmpty() == false );
	ASSERT( PathUtils::IsFullPath( tmpFileName ) );
	return file.Open( tmpFileName.Get(), FileStream::WRITE_ONLY );
}
开发者ID:zhangf911,项目名称:fastbuild,代码行数:9,代码来源:WorkerThread.cpp

示例5: ReadOnly

// ReadOnly
//------------------------------------------------------------------------------
void TestFileIO::ReadOnly() const
{
	// generate a process unique file path
	AStackString<> path;
	GenerateTempFileName( path );

	// create it
	FileStream f;
	TEST_ASSERT( f.Open( path.Get(), FileStream::WRITE_ONLY ) == true );
	f.Close();

	// should not be read only
	TEST_ASSERT( FileIO::GetReadOnly( path ) == false );

	// set readonly
	TEST_ASSERT( FileIO::SetReadOnly( path.Get(), true ) == true );

	// should be read only
	TEST_ASSERT( FileIO::GetReadOnly( path ) == true );

	// delete should fail
	TEST_ASSERT( FileIO::FileDelete( path.Get() ) == false );

	// clean up
	TEST_ASSERT( FileIO::SetReadOnly( path.Get(), false ) == true );
    TEST_ASSERT( FileIO::GetReadOnly( path ) == false );
	TEST_ASSERT( FileIO::FileDelete( path.Get() ) == true );
}
开发者ID:scott-nelson,项目名称:fastbuild,代码行数:30,代码来源:TestFileIO.cpp

示例6: Load

void Settings::Load()
{
    Directory appDataDir = GetAppDataDir();
    if (appDataDir.Exists())
    {
        File config;
        config.SetLocation(appDataDir.Location().OriginalString() + "/config.txt");
        FileStream fs;
        if (config.Exists())
        {
            AutoPointerArray<UInt8> buf(new UInt8[config.Size()], config.Size());
            if (fs.Open(config.Location(), FileAccessMode::Read, FileAccessPriority::ReadThroughput))
            {
                fs.Read(buf.Get(), 0, buf.Size());
                fs.Close();
                for (Size i = 0, s = 0; i < buf.Size(); ++i)
                    if (buf[i] == '\n')
                    {
                        String line = String(reinterpret_cast<const char*>(&buf[s]), i - s);
                        AutoPointerArray<String> keyValue = line.Split(String("="));
                        if (keyValue.Count() == 2)
                        {
                            const char* key = StringCache::Find(keyValue[0]);
                            if (key == 0)
                                key = keyValue[0].c_str();
                            m_PImpl->m_Data[key] = keyValue[1];
                        }
                        s = i+1;
                    }
            }
        }
    }
}
开发者ID:wangscript,项目名称:RadonFramework,代码行数:33,代码来源:Settings.cpp

示例7: Load

// Load
//------------------------------------------------------------------------------
void WorkerSettings::Load()
{
    AStackString<> settingsPath;
    Env::GetExePath( settingsPath );
    settingsPath += ".settings";

    FileStream f;
    if ( f.Open( settingsPath.Get(), FileStream::READ_ONLY ) )
    {
        char header[ 4 ] = { 0 };
        f.Read( &header, 4 );
        if ( ( header[ 3 ] < FBUILDWORKER_SETTINGS_MIN_VERSION ) ||
             ( header[ 3 ] > FBUILDWORKER_SETTINGS_CURRENT_VERSION ) )
        {
            return; // version is too old, or newer, and cannot be read
        }

        // settings
        uint32_t mode;
        f.Read( mode );
        m_Mode = (Mode)mode;
        f.Read( m_NumCPUsToUse );
        f.Read( m_StartMinimized );
    }
}
开发者ID:dontnod,项目名称:fastbuild,代码行数:27,代码来源:WorkerSettings.cpp

示例8: ms

// Load
//------------------------------------------------------------------------------
/*static*/ Object * ReflectionInfo::Load( const char * scopedName )
{
	AStackString<> fullPath;
	fullPath.Format( "Reflection\\%s.obj", scopedName );

	FileStream fs;
	if ( fs.Open( fullPath.Get(), FileStream::READ_ONLY ) == false )
	{
		return nullptr;
	}

	const size_t fileSize = (size_t)fs.GetFileSize();
	AutoPtr< char > mem( (char *)Alloc( fileSize + 1 ) );
	if ( fs.Read( mem.Get(), fileSize ) != fileSize )
	{
		return nullptr;
	}
	mem.Get()[ fileSize ] = 0;

	ConstMemoryStream ms( mem.Get(), fileSize + 1 );
	TextReader tr( ms );
	RefObject * refObject = tr.Read();
	ASSERT( !refObject || DynamicCast< Object >( refObject ) );

	return (Object *)refObject;
}
开发者ID:ClxS,项目名称:fastbuild,代码行数:28,代码来源:ReflectionInfo.cpp

示例9: while

    /*static*/ void FileIO::WorkAroundForWindowsFilePermissionProblem( const AString & fileName )
    {
        // Sometimes after closing a file, subsequent operations on that file will
        // fail.  For example, trying to set the file time, or even another process
        // opening the file.
        //
        // This seems to be a known issue in windows, with multiple potential causes
        // like Virus scanners and possibly the behaviour of the kernel itself.
        //
        // A work-around for this problem is to attempt to open a file we just closed.
        // This will sometimes fail, but if we retry until it succeeds, we avoid the
        // problem on the subsequent operation.
        FileStream f;
        Timer timer;
        while ( f.Open( fileName.Get() ) == false )
        {
            Thread::Sleep( 1 );

            // timeout so we don't get stuck in here forever
            if ( timer.GetElapsed() > 1.0f )
            {
                ASSERT( false && "WorkAroundForWindowsFilePermissionProblem Failed!" );
                return;
            }
        }
        f.Close();
    }
开发者ID:JeremieA,项目名称:fastbuild,代码行数:27,代码来源:FileIO.cpp

示例10: TestMSVCPreprocessedOutput

REGISTER_TESTS_END

// TestMSVCPreprocessedOutput
//------------------------------------------------------------------------------
void TestIncludeParser::TestMSVCPreprocessedOutput() const
{
    FileStream f;
    TEST_ASSERT( f.Open( "Data/TestIncludeParser/fbuildcore.msvc.ii", FileStream::READ_ONLY) )
    const size_t fileSize = (size_t)f.GetFileSize();
    AutoPtr< char > mem( (char *)ALLOC( fileSize + 1 ) );
    TEST_ASSERT( f.Read( mem.Get(), fileSize ) == fileSize );
    mem.Get()[ fileSize ] = 0;

    Timer t;

    const size_t repeatCount( 100 );
    for ( size_t i=0; i<repeatCount; ++i )
    {
        CIncludeParser parser;
        TEST_ASSERT( parser.ParseMSCL_Preprocessed( mem.Get(), fileSize ) );

        // check number of includes found to prevent future regressions
        const Array< AString > & includes = parser.GetIncludes();
        TEST_ASSERT( includes.GetSize() == 284 );
#ifdef DEBUG
        TEST_ASSERT( parser.GetNonUniqueCount() == 381 );
#endif
    }

    float time = t.GetElapsed();
    OUTPUT( "MSVC                 : %2.3fs (%2.1f MiB/sec)\n", time, ( (float)( fileSize * repeatCount / ( 1024.0f * 1024.0f ) ) / time ) );
}
开发者ID:dontnod,项目名称:fastbuild,代码行数:32,代码来源:TestIncludeParser.cpp

示例11: Save

// Save
//------------------------------------------------------------------------------
void Report::Save() const
{
	FileStream f;
	if ( f.Open( "report.html", FileStream::WRITE_ONLY ) )
	{
		f.Write( m_Output.Get(), m_Output.GetLength() );
	}
}
开发者ID:hilbertdu,项目名称:fastbuild,代码行数:10,代码来源:Report.cpp

示例12: DoesFileExist

bool DoesFileExist( const char* pBuff, long& lSize ){
	FileStream file;
	if ( file.Open( pBuff, "r" ) ) {
		lSize += file.GetLength();
		file.Close();
		return true;
	}
	return false;
}
开发者ID:GSIO01,项目名称:GtkRadiant,代码行数:9,代码来源:qe3.cpp

示例13: ParseXMLFile

xmlDocPtr ParseXMLFile( const char* filename, bool validate = false ){
	FileStream stream;
	if ( stream.Open( filename, "r" ) ) {
		return ParseXMLStream( &stream, validate );
	}

	Sys_FPrintf( SYS_ERR, "Failed to open file: %s\n",filename );
	return NULL;
}
开发者ID:GSIO01,项目名称:GtkRadiant,代码行数:9,代码来源:qe3.cpp

示例14: OpenFile

FileStream* FileStream::OpenFile(const char* filename)
{
	FileStream *fs = new FileStream();
	if (fs->Open(filename))
		return fs;

	delete fs;
	return NULL;
}
开发者ID:AlanWasTaken,项目名称:gemrb,代码行数:9,代码来源:FileStream.cpp

示例15: OpenFileStream

/// Attempt to open a file with a new file stream object.
///
/// @param[in] pPath      FilePath name of the file to open.
/// @param[in] modeFlags  Combination of FileStream::EMode flags specifying the mode in which to open the file.
/// @param[in] bTruncate  If the FileStream::MODE_WRITE flag is set, true to truncate any existing file, false to
///                       append to any existing file.  This is ignored if FileStream::MODE_WRITE is not set.
///
/// @return  Pointer to a FileStream instance opened for the specified file if it was successfully opened, null if
///          opening failed.  Note that the caller is responsible for deleting the FileStream instance when it is no
///          longer needed.
FileStream* FileStream::OpenFileStream( const char* pPath, uint32_t modeFlags, bool bTruncate )
{
	FileStream* pStream = new FileStream();
	HELIUM_ASSERT( pStream );
	if( !pStream->Open( pPath, modeFlags, bTruncate ) )
	{
		delete pStream;
		return NULL;
	}

	return pStream;
}
开发者ID:HeN1Project,项目名称:Foundation,代码行数:22,代码来源:FileStream.cpp


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