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


C++ Toplevel::throwError方法代码示例

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


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

示例1: read

	Stringp FileClass::read(Stringp filename)
	{
		Toplevel* toplevel = this->toplevel();
		AvmCore* core = this->core();

		if (!filename) {
			toplevel->throwArgumentError(kNullArgumentError, "filename");
		}
		StUTF8String filenameUTF8(filename);
		File* fp = Platform::GetInstance()->createFile();
		if(!fp || !fp->open(filenameUTF8.c_str(), File::OPEN_READ))
		{
			if(fp)
			{
				Platform::GetInstance()->destroyFile(fp);
			}

			toplevel->throwError(kFileOpenError, filename);
		}

		int64_t fileSize = fp->size();
		if(fileSize >= (int64_t)INT32_T_MAX) //File APIs cannot handle files > 2GB
		{
			toplevel->throwRangeError(kOutOfRangeError, filename);
		}

		int len = (int)fileSize;

		MMgc::GC::AllocaAutoPtr _c;
		union {
			uint8_t* c;
			wchar* c_w;
		};
		c = (uint8_t*)VMPI_alloca(core, _c, len+1);

		len = (int)fp->read(c, len); //need to force since the string creation functions expect an int
		c[len] = 0;
		
		fp->close();
		Platform::GetInstance()->destroyFile(fp);

		if (len >= 3)
		{
			// UTF8 BOM
			if ((c[0] == 0xef) && (c[1] == 0xbb) && (c[2] == 0xbf))
			{
				return core->newStringUTF8((const char*)c + 3, len - 3);
			}
			else if ((c[0] == 0xfe) && (c[1] == 0xff))
			{
				//UTF-16 big endian
				c += 2;
				len = (len - 2) >> 1;
				return core->newStringEndianUTF16(/*littleEndian*/false, c_w, len);
			}
			else if ((c[0] == 0xff) && (c[1] == 0xfe))
开发者ID:Jeffxz,项目名称:nodeas,代码行数:56,代码来源:FileClass.cpp

示例2: read

    Stringp FileClass::read(Stringp filename)
    {
        Toplevel* toplevel = this->toplevel();
        AvmCore* core = this->core();

        if (!filename) {
            toplevel->throwArgumentError(kNullArgumentError, "filename");
        }
        StUTF8String filenameUTF8(filename);
        File* fp = Platform::GetInstance()->createFile();
        if(!fp || !fp->open(filenameUTF8.c_str(), File::OPEN_READ))
        {
            if(fp)
            {
                Platform::GetInstance()->destroyFile(fp);
            }

            toplevel->throwError(kFileOpenError, filename);
        }

        int64_t fileSize = fp->size();
        if(fileSize >= (int64_t)INT32_T_MAX) //File APIs cannot handle files > 2GB
        {
            toplevel->throwRangeError(kOutOfRangeError, filename);
        }

        int len = (int)fileSize;

        // Avoid VMPI_alloca - the buffer can be large and the memory is non-pointer-containing,
        // but the GC will scan it conservatively.
        uint8_t* c = (uint8_t*)core->gc->Alloc(len+1);
        
        len = (int)fp->read(c, len); //need to force since the string creation functions expect an int
        c[len] = 0;

        fp->close();
        Platform::GetInstance()->destroyFile(fp);

        Stringp ret = NULL;

        if (len >= 3)
        {
            // UTF8 BOM
            if ((c[0] == 0xef) && (c[1] == 0xbb) && (c[2] == 0xbf))
            {
                ret = core->newStringUTF8((const char*)c + 3, len - 3);
            }
            else if ((c[0] == 0xfe) && (c[1] == 0xff))
            {
                //UTF-16 big endian
                c += 2;
                len = (len - 2) >> 1;
                ret = core->newStringEndianUTF16(/*littleEndian*/false, (wchar*)(void*)c, len);
            }
            else if ((c[0] == 0xff) && (c[1] == 0xfe))
开发者ID:bsdf,项目名称:AVMPLUS_MAC,代码行数:55,代码来源:FileClass.cpp

示例3: read

	Stringp FileClass::read(Stringp filename)
	{
		Toplevel* toplevel = this->toplevel();
		AvmCore* core = this->core();

		if (!filename) {
			toplevel->throwArgumentError(kNullArgumentError, "filename");
		}
		UTF8String* filenameUTF8 = filename->toUTF8String();
		FILE *fp = fopen(filenameUTF8->c_str(), "r");
		if (fp == NULL) {
			toplevel->throwError(kFileOpenError, filename);
		}
		fseek(fp, 0L, SEEK_END);
		long len = ftell(fp);
		#ifdef UNDER_CE
		fseek (fp, 0L, SEEK_SET);
		#else
		rewind(fp);
		#endif

		unsigned char *c = new unsigned char[len+1];
		len = (long)fread(c, 1, len, fp);
		c[len] = 0;
		
		fclose(fp);

		if (len >= 3)
		{
			// UTF8 BOM
			if ((c[0] == 0xef) && (c[1] == 0xbb) && (c[2] == 0xbf))
			{
				return core->newString(((char *)c) + 3, len - 3);
			}
			else if ((c[0] == 0xfe) && (c[1] == 0xff))
			{
				//UTF-16 big endian
				c += 2;
				len = (len - 2) >> 1;
				Stringp out = new (core->GetGC()) String(len);
				wchar *buffer = out->lockBuffer();
				for (long i = 0; i < len; i++)
				{
					buffer[i] = (c[0] << 8) + c[1];
					c += 2;
				}
				out->unlockBuffer();

				return out;
			}
			else if ((c[0] == 0xff) && (c[1] == 0xfe))
开发者ID:PushButtonLabs,项目名称:PBNetworking,代码行数:51,代码来源:FileClass.cpp


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