示例#1
0
  void UserStream::readBuffer(void *buffer, NxU32 size)const
  {
#ifdef _DEBUG
    size_t w = nxu_fread(buffer, size, 1, fp);
    NX_ASSERT(w);
#else
    nxu_fread(buffer, size, 1,  fp);
#endif
  }
示例#2
0
  double UserStream::readDouble()const
  {
    NxF64 f;
#ifdef _DEBUG
    size_t r = nxu_fread(&f, sizeof(NxF64), 1, fp);
    NX_ASSERT(r);
#else
    nxu_fread(&f, sizeof(NxF64),  1, fp);
#endif
    return f;
  }
示例#3
0
  float UserStream::readFloat()const
  {
    NxReal f;
#ifdef _DEBUG
    size_t r = nxu_fread(&f, sizeof(NxReal), 1, fp);
    NX_ASSERT(r);
#else
    nxu_fread(&f, sizeof(NxReal), 1,  fp);
#endif
    return f;
  }
示例#4
0
  NxU32 UserStream::readDword()const
  {
    NxU32 d;
#ifdef _DEBUG
    size_t r = nxu_fread(&d, sizeof(NxU32), 1, fp);
    NX_ASSERT(r);
#else
    nxu_fread(&d, sizeof(NxU32),  1, fp);
#endif
    return d;
  }
示例#5
0
  NxU16 UserStream::readWord()const
  {
    NxU16 w;
#ifdef _DEBUG
    size_t r = nxu_fread(&w, sizeof(NxU16), 1, fp);
    NX_ASSERT(r);
#else
    nxu_fread(&w, sizeof(NxU16),  1, fp);
#endif
    return w;
  }
示例#6
0
  // Loading API
  NxU8 UserStream::readByte()const
  {
    NxU8 b;
#ifdef _DEBUG
    size_t r = nxu_fread(&b, sizeof(NxU8), 1, fp);
    NX_ASSERT(r);
#else
    nxu_fread(&b, sizeof(NxU8), 1,  fp);
#endif
    return b;
  }
示例#7
0
bool TiXmlDocument::LoadFile(NXU_FILE	*file, TiXmlEncoding encoding)
{
	if (!file)
	{
		SetError(TIXML_ERROR_OPENING_NXU_FILE, 0,	0, TIXML_ENCODING_UNKNOWN);
		return false;
	}

	// Delete	the	existing data:
	Clear();
	location.Clear();

	// Get the file	size,	so we	can	pre-allocate the string. HUGE	speed	impact.
	long length	=	0;
	nxu_fseek(file,	0, SEEK_END);
	length = (long) nxu_ftell(file);
	nxu_fseek(file,	0, SEEK_SET);

	// Strange case, but good	to handle	up front.
	if (length ==	0)
	{
		SetError(TIXML_ERROR_DOCUMENT_EMPTY, 0,	0, TIXML_ENCODING_UNKNOWN);
		return false;
	}

	// If	we have	a	file,	assume it	is all one big XML file, and read	it in.
	// The document	parser may decide	the	document ends	sooner than	the	entire file, however.	
	TIXML_STRING data;
	data.reserve(length);

	// Subtle	bug	here.	TinyXml	did	use	fgets. But from	the	XML	spec:
	// 2.11	End-of-Line	Handling
	// <snip>
	// <quote>
	// ...the	XML	processor	MUST behave	as if	it normalized	all	line breaks	in external
	// parsed	entities (including	the	document entity) on	input, before	parsing, by	translating
	// both	the	two-character	sequence #xD #xA and any #xD that	is not followed	by #xA to
	// a single	#xA	character.
	// </quote>
	//
	// It	is not clear fgets does	that,	and	certainly	isn't	clear	it works cross platform.
	// Generally,	you	expect fgets to	translate	from the convention	of the OS	to the c/unix
	// convention, and not work	generally.

	/*
	while( fgets(	buf, sizeof(buf),	file ) )
	{
	data +=	buf;
	}
	 */

	char *buf	=	new	char[length	+	1];
	buf[0] = 0;

	if (nxu_fread(buf, length, 1,	file)	!= 1)
	{
		SetError(TIXML_ERROR_OPENING_NXU_FILE, 0,	0, TIXML_ENCODING_UNKNOWN);
		return false;
	}

	const	char *lastPos	=	buf;
	const	char *p	=	buf;

	buf[length]	=	0;
	while	(*p)
	{
		assert(p < (buf	+	length));
		if (*p ==	0xa)
		{
			// Newline character.	No special rules for this. Append	all	the	characters
			// since the last	string,	and	include	the	newline.
			data.append(lastPos, (p	-	lastPos	+	1)); //	append,	include	the	newline
			++p; //	move past	the	newline
			lastPos	=	p; //	and	point	to the new buffer	(may be	0)
			assert(p <=	(buf + length));
		}
		else if	(*p	== 0xd)
		{
			// Carriage	return.	Append what	we have	so far,	then
			// handle	moving forward in	the	buffer.
			if ((p - lastPos)	>	0)
			{
				data.append(lastPos, p - lastPos); //	do not add the CR
			}
			data +=	(char)0xa; //	a	proper newline

			if (*(p	+	1) ==	0xa)
			{
				// Carriage	return - new line	sequence
				p	+= 2;
				lastPos	=	p;
				assert(p <=	(buf + length));
			}
			else
			{
				// it	was	followed by	something	else...that	is presumably	characters again.
				++p;
				lastPos	=	p;
				assert(p <=	(buf + length));
			}
		}
		else
		{
			++p;
		}
	}
	// Handle	any	left over	characters.
	if (p	-	lastPos)
	{
		data.append(lastPos, p - lastPos);
	}
	delete []	buf;
	buf	=	0;

	Parse(data.c_str(),	0, encoding);

	if (Error())
	{
		return false;
	}
	else
	{
		return true;
	}
}