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


C++ Stream::GetLength方法代码示例

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


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

示例1: GetNextMessage

char* FileBasedAGSDebugger::GetNextMessage()
{
    Stream *in = Common::File::OpenFileRead("dbgsend.tmp");
    if (in == NULL)
    {
        // check again, because the editor might have deleted the file in the meantime
        return NULL;
    }
    int fileSize = in->GetLength();
    char *msg = (char*)malloc(fileSize + 1);
    in->Read(msg, fileSize);
    delete in;
    unlink("dbgsend.tmp");
    msg[fileSize] = 0;
    return msg;
}
开发者ID:AlanDrake,项目名称:ags,代码行数:16,代码来源:filebasedagsdebugger.cpp

示例2: Load

	///////////////////////////////////////////////////////////////////////////////
	//                                                                           //
	// File I/O                                                                  //
	//                                                                           //
	///////////////////////////////////////////////////////////////////////////////
	aalError Sample::Load(const char * _name)
	{
		Stream * stream = CreateStream(_name);

		if (!stream) return AAL_ERROR_FILEIO;

		stream->GetFormat(format);
		stream->GetLength(length);
		DeleteStream(stream);

		aalVoid * ptr = realloc(name, strlen(_name) + 1);

		if (!ptr) return AAL_ERROR_MEMORY;

		name = (char *)ptr;
		strcpy(name, _name);

		return AAL_OK;
	}
开发者ID:kstuedem,项目名称:arxfatalis,代码行数:24,代码来源:Athena_Sample.cpp

示例3: consistencyTesting

// Test whether all three reads return the same thing.
void consistencyTesting(Stream &s) {
	int location = rand() % s.GetLength();
	int size = 128;

	// Run all three tests: Sequential, Backwards, and Random.
	int* seq = testReadSequential(s, location, size);
	int* back = testReadBackwards(s, location, size);
	int* random = testReadRandom(s, location, size);

	// Are they all the same?
	if (seq == back && back == random)
		printf("Data is consistent between all three read formats.\n");
	// Otherwise, error check.
	else {
		if (seq != back)
			printf("Error: Data is not consistent between sequential and backwards reading.\n");
		if (seq != random)
			printf("Error: Data is not consistent between sequential and random reading.\n");
		if (random != back)
			printf("Error: Data is not consistent between backwards and random reading.\n");
	}
}
开发者ID:SandMan36,项目名称:CPTS_422_HW2,代码行数:23,代码来源:ConsistencyTests.hpp

示例4: start_playback

void start_playback()
{
    Stream *in = Common::File::OpenFileRead(replayfile);
    if (in != NULL) {
        char buffer [100];
        in->Read(buffer, 12);
        buffer[12] = 0;
        if (strcmp (buffer, "AGSRecording") != 0) {
            Display("ERROR: Invalid recorded data file");
            play.playback = 0;
        }
        else {
            String version_string = String::FromStream(in, 12);
            AGS::Engine::Version requested_engine_version(version_string);
            if (requested_engine_version.Major != '2') 
                quit("!Replay file is from an old version of AGS");
            if (requested_engine_version < AGS::Engine::Version(2, 55, 553))
                quit("!Replay file was recorded with an older incompatible version");

            if (requested_engine_version != EngineVersion) {
                // Disable text as speech while displaying the warning message
                // This happens if the user's graphics card does BGR order 16-bit colour
                int oldalways = game.options[OPT_ALWAYSSPCH];
                game.options[OPT_ALWAYSSPCH] = 0;
                play.playback = 0;
                Display("Warning! replay is from a different version of AGS (%s) - it may not work properly.", buffer);
                play.playback = 1;
                srand (play.randseed);
                play.gamestep = 0;
                game.options[OPT_ALWAYSSPCH] = oldalways;
            }

            int replayver = in->ReadInt32();

            if ((replayver < 1) || (replayver > 3))
                quit("!Unsupported Replay file version");

            if (replayver >= 2) {
                fgetstring_limit (buffer, in, 99);
                int uid = in->ReadInt32 ();
                if ((strcmp (buffer, game.gamename) != 0) || (uid != game.uniqueid)) {
                    char msg[150];
                    sprintf (msg, "!This replay is meant for the game '%s' and will not work correctly with this game.", buffer);
                    delete in;
                    quit (msg);
                }
                // skip the total time
                in->ReadInt32 ();
                // replay description, maybe we'll use this later
                fgetstring_limit (buffer, in, 99);
            }

            play.randseed = in->ReadInt32();
            int flen = in->GetLength() - in->GetPosition ();
            if (replayver >= 3) {
                flen = in->ReadInt32() * sizeof(short);
            }
            recordbuffer = (short*)malloc (flen);
            in->Read(recordbuffer, flen);
            srand (play.randseed);
            recbuffersize = flen / sizeof(short);
            recsize = 0;
            disable_mgetgraphpos = 1;
            replay_time = 0;
            replay_last_second = loopcounter;
            if (replayver >= 3) {
                int issave = in->ReadInt32();
                if (issave) {
                    if (RestoreGameState(in, kSvgVersion_321) != kSvgErr_NoError)
                        quit("!Error running replay... could be incorrect game version");
                    replay_last_second = loopcounter;
                }
            }
            delete in;
        }
    }
    else // file not found
        play.playback = 0;
}
开发者ID:,项目名称:,代码行数:79,代码来源:

示例5: Write_Validation_Tests

void Write_Validation_Tests(Stream & S)
{
	char s_buf[4000];
	char r_buf[4000];

	for (int i = 0; i < 4000; i++)
	{
		s_buf[i] = 'a';
	}
	s_buf[3999] = '\0';

	//cout << s_buf << endl;
	if (S.CanWrite())
	{
		cout << "Can write" << endl;
	}
	else
	{
		cout << "Can't write Unit test passed" << endl;

		return;
	}

	S.Write(s_buf, 4000);
	S.Read(r_buf, 4000);
	if (memcmp(r_buf, s_buf, 4000) == 0)
	{
		cout << "T1). PASS: Write all in one write works" << endl;
	}
	else
	{
		cout << "T1). FAILED: Write all in one write does not match" << endl;
	}

	char k_buf[1024];
	char o_buf[1801];
	for (int i = 0; i < 4000; i++)
	{
		s_buf[i] = 'b';
	}
	s_buf[3999] = '\0';
	S.SetPosition(S.GetLength());

	int k = 4000;
	for (int i = 0; i <= 3; i++)
	{
		int l;
		if ((k - 1024) >= 0)
		{
			l = 1024;
			k = k - 1024;
		}
		else
		{
			l = k;
		}
		for (int j = 0; j < l; j++)
		{
			k_buf[j] = s_buf[i * 1024 + j];
		}
		S.Write(k_buf, l);
		S.SetPosition(S.GetLength());
	}

	S.SetPosition(4000);
	k = 4000;
	for (int i = 0; i <= 3; i++)
	{
		if (k - 1024 >= 0)
		{
			S.Read(k_buf, 1024);
			k = k - 1024;
			memcpy(&r_buf[i * 1024], k_buf, 1024);
		}
		else
		{
			S.Read(k_buf, k);
			memcpy(&r_buf[i * 1024], k_buf, k);
		}

		S.SetPosition(4000 + (i*1024));
	}
	r_buf[3999] = '\0';

	if (memcmp(r_buf, s_buf, 4000) == 0)
	{
		cout << "T2). PASS: Write by block works" << endl;
	}
	else
	{
		cout << "T2). FAILED: Write all in one write does not match" << endl;
	}



	for (int i = 0; i < 4000; i++)
	{
		s_buf[i] = 'c';
	}
	s_buf[3999] = '\0';
//.........这里部分代码省略.........
开发者ID:SandMan36,项目名称:CPTS_422_HW2,代码行数:101,代码来源:WriteTests.hpp


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