コード例 #1
0
ファイル: o_xml.cpp プロジェクト: AzyxWare/ryzom
bool COXml::xmlCommentInternal (const char *comment)
{
	nlassert( ! isReading() );

	// Check _InternalStream
	if ( _InternalStream )
	{
		// Not in the push mode ?
		if ( _CurrentNode != NULL)
		{
			// Add a comment node
			xmlNodePtr commentPtr = xmlNewComment ((const xmlChar *)comment);

			// Add the node
			xmlAddChild (_CurrentNode, commentPtr);
		}
		else
		{
			nlwarning ( "XML: You must call xmlCommentInternal between xmlPushBegin and xmlPushEnd.");
			return false;
		}
	}
	else
	{
		nlwarning ( "XML: Output stream has not been setuped.");
		return false;
	}
	// Ok
	return true;
}
コード例 #2
0
ファイル: o_xml.cpp プロジェクト: AzyxWare/ryzom
bool COXml::xmlSetAttribInternal (const char *attribName)
{
	nlassert( ! isReading() );

	// Check _InternalStream
	if ( _InternalStream )
	{
		// Can make a xmlPushEnd ?
		if ( _PushBegin )
		{
			// Set attribute name
			_AttribName = attribName;

			// Attribute name is present
			_AttribPresent = true;
		}
		else
		{
			nlwarning ( "XML: You must call xmlSetAttrib between xmlPushBegin and xmlPushEnd calls.");
			return false;
		}
	}
	else
	{
		nlwarning ( "XML: Output stream has not been setuped.");
		return false;
	}

	// Ok
	return true;
}
コード例 #3
0
ファイル: o_xml.cpp プロジェクト: AzyxWare/ryzom
bool COXml::xmlBreakLineInternal ()
{
	nlassert( ! isReading() );

	// Check _InternalStream
	if ( _InternalStream )
	{
		// Not in the push mode ?
		if ( ! _PushBegin )
		{
			// Add a break line
			_ContentString += '\n';
		}
		else
		{
			nlwarning ( "XML: You must call xmlNBreakLine after xmlPushEnd.");
			return false;
		}
	}
	else
	{
		nlwarning ( "XML: Output stream has not been setuped.");
		return false;
	}

	// Ok
	return true;
}
コード例 #4
0
ファイル: o_xml.cpp プロジェクト: AzyxWare/ryzom
bool COXml::xmlPushEndInternal ()
{
	nlassert( ! isReading() );

	// Check _InternalStream
	if ( _InternalStream )
	{
		// Can make a xmlPushEnd ?
		if ( _PushBegin )
		{
			// Push begun
			_PushBegin = false;
		}
		else
		{
			nlwarning ( "XML: You must call xmlPushBegin before calling xmlPushEnd.");
			return false;
		}
	}
	else
	{
		nlwarning ( "XML: Output stream has not been setuped.");
		return false;
	}

	// Ok
	return true;
}
コード例 #5
0
ファイル: o_xml.cpp プロジェクト: AzyxWare/ryzom
bool COXml::xmlPopInternal ()
{
	nlassert( ! isReading() );

	// Check _InternalStream
	if ( _InternalStream )
	{
		// Not in the push mode ?
		if ( ! _PushBegin )
		{
			// Some content to write ?
			flushContentString ();

			// Get parent
			_CurrentNode=_CurrentNode->parent;
		}
		else
		{
			nlwarning ( "XML: You must call xmlPop after xmlPushEnd.");
			return false;
		}
	}
	else
	{
		nlwarning ( "XML: Output stream has not been setuped.");
		return false;
	}

	// Ok
	return true;
}
コード例 #6
0
ファイル: mem_stream.cpp プロジェクト: AzyxWare/ryzom
// ***************************************************************************
uint			CMemStream::getDbgStreamSize() const
{
	if(isReading())
		return length();
	else
		return 0;
}
コード例 #7
0
ファイル: o_xml.cpp プロジェクト: AzyxWare/ryzom
bool COXml::xmlPushBeginInternal (const char *nodeName)
{
	nlassert( ! isReading() );

	// Check _InternalStream
	if ( _InternalStream )
	{
		// Can make a xmlPushBegin ?
		if ( ! _PushBegin )
		{
			// Current node exist ?
			if (_CurrentNode==NULL)
			{
				// No document ?
				if (_Document == NULL)
				{
					// Initialise the document
					_Document = xmlNewDoc ((const xmlChar *)_Version.c_str());

					// Return NULL if error
					nlassert (_Document);
				}

				// Create the first node
				_CurrentNode=xmlNewDocNode (_Document, NULL, (const xmlChar*)nodeName, NULL);
				xmlDocSetRootElement (_Document, _CurrentNode);

				// Return NULL if error
				nlassert (_CurrentNode);
			}
			else
			{
				// Flush current content string ?
				flushContentString ();

				// Create a new node
				_CurrentNode=xmlNewChild (_CurrentNode, NULL, (const xmlChar*)nodeName, NULL);

				// Return NULL if error
				nlassert (_CurrentNode);
			}

			// Push begun
			_PushBegin = true;
		}
		else
		{
			nlwarning ( "XML: You must close your xmlPushBegin - xmlPushEnd before calling a new xmlPushBegin.");
			return false;
		}
	}
	else
	{
		nlwarning ( "XML: Output stream has not been setuped.");
		return false;
	}

	// Ok
	return true;
}
コード例 #8
0
ファイル: mem_stream.cpp プロジェクト: AzyxWare/ryzom
/*
 * Input: read from the stream until the next separator, and return the number of bytes read. The separator is then skipped.
 */
uint CMemStream::serialSeparatedBufferIn( uint8 *buf, uint len )
{
	nlassert( _StringMode && isReading() );

	// Check that we don't read more than there is to read
	if ( ( _Buffer.Pos == _Buffer.getBuffer().size() ) || // we are at the end
		 ( ( lengthS()+len+SEP_SIZE > length() ) && (_Buffer.getBuffer()[_Buffer.getBuffer().size()-1] != SEPARATOR ) ) ) // we are before the end // calls virtual length (cf. sub messages)
	{
		throw EStreamOverflow();
	}
	// Serialize in
	uint32 i = 0;
	const uint8	*pos = _Buffer.getBuffer().getPtr()+_Buffer.Pos;
	while ( (i<len) && (*pos) != SEPARATOR )
	{
		*(buf+i) = *pos;
		i++;
		++pos;
		++_Buffer.Pos;
	}
	// Exceeds len
	if ( (*pos) != SEPARATOR )
	{
		throw EStreamOverflow();
	}
	_Buffer.Pos += SEP_SIZE;

	return i;
}
コード例 #9
0
ファイル: TextFile.cpp プロジェクト: unisb-bioinf/genetrail2
	std::vector<std::string> TextFile::read()
	{
		if(!isValid_() || !isReading()) {
			throw IOError("File is not open for reading");
		}

		for(const auto& symbol : skipSymbols_)
		{
			if(boost::starts_with(next_line_, symbol))
			{
				advanceLine_();
				return read();
			}
		}

		std::vector<std::string> sline;
		boost::split(sline, next_line_, boost::is_any_of(delimiter_));
		for(auto& s : sline)
		{
			boost::trim(s);
		}

		// Prefetch the next line from the file.
		advanceLine_();

		return sline;
	}
コード例 #10
0
ファイル: o_xml.cpp プロジェクト: AzyxWare/ryzom
void COXml::serialSeparatedBufferOut( const char *value )
{
	nlassert( ! isReading() );

	// Output stream has been setuped ?
	if ( _InternalStream )
	{
		// Current node presents ?
		if (_CurrentNode)
		{
			// Write a push attribute ?
			if (_PushBegin)
			{
				// Current attrib is set ?
				if (_AttribPresent)
				{
					// Set the attribute
					xmlSetProp (_CurrentNode, (const xmlChar*)_AttribName.c_str(), (const xmlChar*)value);

					// The attribute has been used
					_AttribPresent = false;
				}
				else
				{
					// * Error, the stream don't use XML streaming properly
					// * You must take care of this in your last serial call:
					// * - Between xmlPushBegin() and xmlPushEnd(), before each serial, you must set the attribute name with xmlSetAttrib.
					// * - Between xmlPushBegin() and xmlPushEnd(), you must serial only basic objects (numbers and strings).
					nlerror ( "Error, the stream don't use XML streaming properly" );
				}
			}
			else
			{
				// Get the content buffer size
				uint size=(uint)_ContentString.length();

				// Add a separator
				if ((size) && (_ContentString[size-1]!='\n'))
					_ContentString += SEPARATOR;

				// Concat the strings
				_ContentString += value;
			}
		}
		else
		{
			// * Error, no current node present.
			// * Check that your serial is initialy made between a xmlPushBegin and xmlPushEnd calls.
			nlerror ( "Error, the stream don't use XML streaming properly" );
		}
	}
	else
	{
		nlerror ( "Output stream has not been setuped" );
	}
}
コード例 #11
0
ファイル: o_xml.cpp プロジェクト: AzyxWare/ryzom
void COXml::serial(ucstring &b)
{
	nlassert( ! isReading() );

	// convert ucstring to utf-8 std::string
	std::string output = b.toUtf8();

	// Serial this string
	serial (output);
}
コード例 #12
0
ファイル: myqADC.cpp プロジェクト: myqthorn/myq-atmel-studio
///@description	Perform a complete conversion. Should only be used when waiting isn't a problem.
uint16_t ANALOG::read(){
		
	//start conversion
	start();
	
	//wait for conversion to finish (interrupt flag is set)
	while( isReading() && !isInterruptFlagSet());
	
	clearFlag();
	return (ADC);
}
コード例 #13
0
ファイル: mem_stream.cpp プロジェクト: AzyxWare/ryzom
/*
 * serialBit (inherited from IStream)
 */
void CMemStream::serialBit(bool &bit)
{
	uint8 u;
	if ( isReading() )
	{
		serial( u );
		bit = (u!=0);
	}
	else
	{
		u = (uint8)bit;
		serial( u );
	}
}
コード例 #14
0
ファイル: mem_stream.cpp プロジェクト: AzyxWare/ryzom
/*
 * Output: writes len bytes from buf into the stream
 */
void CMemStream::serialSeparatedBufferOut( uint8 *buf, uint len )
{
	nlassert( _StringMode && (!isReading()) );

	// Serialize out
	uint32 oldBufferSize = _Buffer.getBuffer().size();
	if (_Buffer.Pos + (len + SEP_SIZE) > oldBufferSize)
	{
		// need to increase the buffer size
		_Buffer.getBufferWrite().resize(oldBufferSize*2 + len + SEP_SIZE);
	}

	CFastMem::memcpy( _Buffer.getBufferWrite().getPtr()+_Buffer.Pos, buf, len );
	_Buffer.Pos += len;
	*(_Buffer.getBufferWrite().getPtr()+_Buffer.Pos) = SEPARATOR;
	_Buffer.Pos += SEP_SIZE;

}
コード例 #15
0
ファイル: o_xml.cpp プロジェクト: AzyxWare/ryzom
void COXml::serial(std::string &b)
{
	nlassert( ! isReading() );

	// Attibute ?
	if (_PushBegin)
	{
		// Only serial the string
		serialSeparatedBufferOut( b.c_str() );
	}
	else
	{
		// Open a string node
		xmlPush ("S");

		// Serial the string
		serialSeparatedBufferOut( b.c_str() );

		// Close the node
		xmlPop ();
	}
}
コード例 #16
0
ファイル: mem_stream.cpp プロジェクト: AzyxWare/ryzom
/*
 * serial (inherited from IStream)
 */
void CMemStream::serialBuffer(uint8 *buf, uint len)
{
	// commented for optimum performance
//	nlassert (len > 0);

	if (len == 0)
		return;

	nlassert (buf != NULL);

	if ( isReading() )
	{
		// Check that we don't read more than there is to read
		//checkStreamSize(len);

		uint32 pos = lengthS();
		uint32 total = length();
		if ( pos+len > total ) // calls virtual length (cf. sub messages)
		{
			throw EStreamOverflow( "CMemStream serialBuffer overflow: Read past %u bytes", total );
		}

		// Serialize in
		CFastMem::memcpy( buf, _Buffer.getBuffer().getPtr()+_Buffer.Pos, len );
		_Buffer.Pos += len;
	}
	else
	{
		// Serialize out

		increaseBufferIfNecessary (len);
		CFastMem::memcpy( _Buffer.getBufferWrite().getPtr()+_Buffer.Pos, buf, len );
		_Buffer.Pos += len;

	}
}