mirror of https://github.com/AxioDL/tinyxml2.git
Merge remote-tracking branch 'origin/master' into build-tests-option
This commit is contained in:
commit
105f32f64d
|
@ -7,9 +7,9 @@ IF(BIICODE)
|
||||||
ENDIF(BIICODE)
|
ENDIF(BIICODE)
|
||||||
cmake_minimum_required(VERSION 2.6 FATAL_ERROR)
|
cmake_minimum_required(VERSION 2.6 FATAL_ERROR)
|
||||||
cmake_policy(VERSION 2.6)
|
cmake_policy(VERSION 2.6)
|
||||||
if(POLICY CMP0063)
|
if(POLICY CMP0063)
|
||||||
cmake_policy(SET CMP0063 OLD)
|
cmake_policy(SET CMP0063 OLD)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
project(tinyxml2)
|
project(tinyxml2)
|
||||||
include(GNUInstallDirs)
|
include(GNUInstallDirs)
|
||||||
|
@ -29,25 +29,6 @@ set(GENERIC_LIB_SOVERSION "4")
|
||||||
|
|
||||||
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/.")
|
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/.")
|
||||||
|
|
||||||
################################
|
|
||||||
# Add custom target to copy all data
|
|
||||||
|
|
||||||
set(TARGET_DATA_COPY DATA_COPY)
|
|
||||||
set(DATA_COPY_FILES)
|
|
||||||
if(NOT ${CMAKE_CURRENT_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_BINARY_DIR})
|
|
||||||
foreach(data dream.xml empty.xml utf8test.xml utf8testverify.xml)
|
|
||||||
set(DATA_COPY_SRC ${CMAKE_CURRENT_SOURCE_DIR}/resources/${data})
|
|
||||||
set(DATA_COPY_DEST ${CMAKE_CURRENT_BINARY_DIR}/resources/${data})
|
|
||||||
add_custom_command(
|
|
||||||
OUTPUT ${DATA_COPY_DEST}
|
|
||||||
COMMAND ${CMAKE_COMMAND}
|
|
||||||
ARGS -E copy ${DATA_COPY_SRC} ${DATA_COPY_DEST}
|
|
||||||
DEPENDS ${DATA_COPY_SRC})
|
|
||||||
list(APPEND DATA_COPY_FILES ${DATA_COPY_DEST})
|
|
||||||
endforeach(data)
|
|
||||||
endif(NOT ${CMAKE_CURRENT_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_BINARY_DIR})
|
|
||||||
add_custom_target(${TARGET_DATA_COPY} DEPENDS ${DATA_COPY_FILES})
|
|
||||||
|
|
||||||
################################
|
################################
|
||||||
# Add definitions
|
# Add definitions
|
||||||
|
|
||||||
|
@ -61,7 +42,7 @@ set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG")
|
||||||
# Add targets
|
# Add targets
|
||||||
# By Default shared libray is being built
|
# By Default shared libray is being built
|
||||||
# To build static libs also - Do cmake . -DBUILD_STATIC_LIBS:BOOL=ON
|
# To build static libs also - Do cmake . -DBUILD_STATIC_LIBS:BOOL=ON
|
||||||
# User can choose not to build shared library by using cmake -BUILD_SHARED_LIBS:BOOL:OFF
|
# User can choose not to build shared library by using cmake -DBUILD_SHARED_LIBS:BOOL=OFF
|
||||||
# To build only static libs use cmake . -DBUILD_SHARED_LIBS:BOOL=OFF -DBUILD_STATIC_LIBS:BOOL=ON
|
# To build only static libs use cmake . -DBUILD_SHARED_LIBS:BOOL=OFF -DBUILD_STATIC_LIBS:BOOL=ON
|
||||||
# To build the tests, use cmake . -DBUILD_TESTS:BOOL=ON
|
# To build the tests, use cmake . -DBUILD_TESTS:BOOL=ON
|
||||||
# To disable the building of the tests, use cmake . -DBUILD_TESTS:BOOL=OFF
|
# To disable the building of the tests, use cmake . -DBUILD_TESTS:BOOL=OFF
|
||||||
|
@ -112,20 +93,21 @@ endif()
|
||||||
if(BUILD_TESTS)
|
if(BUILD_TESTS)
|
||||||
add_executable(xmltest xmltest.cpp)
|
add_executable(xmltest xmltest.cpp)
|
||||||
if(BUILD_SHARED_LIBS)
|
if(BUILD_SHARED_LIBS)
|
||||||
add_dependencies(xmltest tinyxml2)
|
add_dependencies(xmltest tinyxml2)
|
||||||
add_dependencies(xmltest ${TARGET_DATA_COPY})
|
target_link_libraries(xmltest tinyxml2)
|
||||||
target_link_libraries(xmltest tinyxml2)
|
|
||||||
else(BUILD_STATIC_LIBS)
|
else(BUILD_STATIC_LIBS)
|
||||||
add_dependencies(xmltest tinyxml2_static)
|
add_dependencies(xmltest tinyxml2_static)
|
||||||
add_dependencies(xmltest ${TARGET_DATA_COPY})
|
target_link_libraries(xmltest tinyxml2_static)
|
||||||
target_link_libraries(xmltest tinyxml2_static)
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
#add_test(xmltest ${SAMPLE_NAME} COMMAND $<TARGET_FILE:${SAMPLE_NAME}>)
|
# Copy test resources and create test output directory
|
||||||
|
add_custom_command(TARGET xmltest POST_BUILD
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/resources $<TARGET_FILE_DIR:xmltest>/resources
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:xmltest>/resources/out
|
||||||
|
COMMENT "Configuring xmltest resources directory: ${CMAKE_BINARY_DIR}/resources"
|
||||||
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
install(TARGETS DESTINATION ${CMAKE_INSTALL_BINDIR})
|
|
||||||
|
|
||||||
install(FILES tinyxml2.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
|
install(FILES tinyxml2.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
|
||||||
|
|
||||||
foreach(p LIB INCLUDE)
|
foreach(p LIB INCLUDE)
|
||||||
|
|
|
@ -3,5 +3,5 @@ before_build:
|
||||||
|
|
||||||
build_script:
|
build_script:
|
||||||
- msbuild tinyxml2.sln /m /p:Configuration=Release /t:ALL_BUILD
|
- msbuild tinyxml2.sln /m /p:Configuration=Release /t:ALL_BUILD
|
||||||
- copy Release\xmltest.exe .\ && copy Release\tinyxml2.dll .\
|
- cd Release
|
||||||
- xmltest.exe
|
- xmltest.exe
|
||||||
|
|
79
tinyxml2.cpp
79
tinyxml2.cpp
|
@ -368,6 +368,19 @@ const char* StrPair::GetStr()
|
||||||
|
|
||||||
// --------- XMLUtil ----------- //
|
// --------- XMLUtil ----------- //
|
||||||
|
|
||||||
|
const char* XMLUtil::writeBoolTrue = "true";
|
||||||
|
const char* XMLUtil::writeBoolFalse = "false";
|
||||||
|
|
||||||
|
void XMLUtil::SetBoolSerialization(const char* writeTrue, const char* writeFalse)
|
||||||
|
{
|
||||||
|
static const char* defTrue = "true";
|
||||||
|
static const char* defFalse = "false";
|
||||||
|
|
||||||
|
writeBoolTrue = (writeTrue) ? writeTrue : defTrue;
|
||||||
|
writeBoolFalse = (writeFalse) ? writeFalse : defFalse;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
const char* XMLUtil::ReadBOM( const char* p, bool* bom )
|
const char* XMLUtil::ReadBOM( const char* p, bool* bom )
|
||||||
{
|
{
|
||||||
TIXMLASSERT( p );
|
TIXMLASSERT( p );
|
||||||
|
@ -545,7 +558,7 @@ void XMLUtil::ToStr( unsigned v, char* buffer, int bufferSize )
|
||||||
|
|
||||||
void XMLUtil::ToStr( bool v, char* buffer, int bufferSize )
|
void XMLUtil::ToStr( bool v, char* buffer, int bufferSize )
|
||||||
{
|
{
|
||||||
TIXML_SNPRINTF( buffer, bufferSize, "%s", v ? "true" : "false" );
|
TIXML_SNPRINTF( buffer, bufferSize, "%s", v ? writeBoolTrue : writeBoolFalse);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -665,46 +678,34 @@ char* XMLDocument::Identify( char* p, XMLNode** node )
|
||||||
TIXMLASSERT( sizeof( XMLComment ) == sizeof( XMLDeclaration ) ); // use same memory pool
|
TIXMLASSERT( sizeof( XMLComment ) == sizeof( XMLDeclaration ) ); // use same memory pool
|
||||||
XMLNode* returnNode = 0;
|
XMLNode* returnNode = 0;
|
||||||
if ( XMLUtil::StringEqual( p, xmlHeader, xmlHeaderLen ) ) {
|
if ( XMLUtil::StringEqual( p, xmlHeader, xmlHeaderLen ) ) {
|
||||||
TIXMLASSERT( sizeof( XMLDeclaration ) == _commentPool.ItemSize() );
|
returnNode = CreateUnlinkedNode<XMLDeclaration>( _commentPool );
|
||||||
returnNode = new (_commentPool.Alloc()) XMLDeclaration( this );
|
|
||||||
returnNode->_parseLineNum = _parseCurLineNum;
|
returnNode->_parseLineNum = _parseCurLineNum;
|
||||||
returnNode->_memPool = &_commentPool;
|
|
||||||
p += xmlHeaderLen;
|
p += xmlHeaderLen;
|
||||||
}
|
}
|
||||||
else if ( XMLUtil::StringEqual( p, commentHeader, commentHeaderLen ) ) {
|
else if ( XMLUtil::StringEqual( p, commentHeader, commentHeaderLen ) ) {
|
||||||
TIXMLASSERT( sizeof( XMLComment ) == _commentPool.ItemSize() );
|
returnNode = CreateUnlinkedNode<XMLComment>( _commentPool );
|
||||||
returnNode = new (_commentPool.Alloc()) XMLComment( this );
|
|
||||||
returnNode->_parseLineNum = _parseCurLineNum;
|
returnNode->_parseLineNum = _parseCurLineNum;
|
||||||
returnNode->_memPool = &_commentPool;
|
|
||||||
p += commentHeaderLen;
|
p += commentHeaderLen;
|
||||||
}
|
}
|
||||||
else if ( XMLUtil::StringEqual( p, cdataHeader, cdataHeaderLen ) ) {
|
else if ( XMLUtil::StringEqual( p, cdataHeader, cdataHeaderLen ) ) {
|
||||||
TIXMLASSERT( sizeof( XMLText ) == _textPool.ItemSize() );
|
XMLText* text = CreateUnlinkedNode<XMLText>( _textPool );
|
||||||
XMLText* text = new (_textPool.Alloc()) XMLText( this );
|
|
||||||
returnNode = text;
|
returnNode = text;
|
||||||
returnNode->_parseLineNum = _parseCurLineNum;
|
returnNode->_parseLineNum = _parseCurLineNum;
|
||||||
returnNode->_memPool = &_textPool;
|
|
||||||
p += cdataHeaderLen;
|
p += cdataHeaderLen;
|
||||||
text->SetCData( true );
|
text->SetCData( true );
|
||||||
}
|
}
|
||||||
else if ( XMLUtil::StringEqual( p, dtdHeader, dtdHeaderLen ) ) {
|
else if ( XMLUtil::StringEqual( p, dtdHeader, dtdHeaderLen ) ) {
|
||||||
TIXMLASSERT( sizeof( XMLUnknown ) == _commentPool.ItemSize() );
|
returnNode = CreateUnlinkedNode<XMLUnknown>( _commentPool );
|
||||||
returnNode = new (_commentPool.Alloc()) XMLUnknown( this );
|
|
||||||
returnNode->_parseLineNum = _parseCurLineNum;
|
returnNode->_parseLineNum = _parseCurLineNum;
|
||||||
returnNode->_memPool = &_commentPool;
|
|
||||||
p += dtdHeaderLen;
|
p += dtdHeaderLen;
|
||||||
}
|
}
|
||||||
else if ( XMLUtil::StringEqual( p, elementHeader, elementHeaderLen ) ) {
|
else if ( XMLUtil::StringEqual( p, elementHeader, elementHeaderLen ) ) {
|
||||||
TIXMLASSERT( sizeof( XMLElement ) == _elementPool.ItemSize() );
|
returnNode = CreateUnlinkedNode<XMLElement>( _elementPool );
|
||||||
returnNode = new (_elementPool.Alloc()) XMLElement( this );
|
|
||||||
returnNode->_parseLineNum = _parseCurLineNum;
|
returnNode->_parseLineNum = _parseCurLineNum;
|
||||||
returnNode->_memPool = &_elementPool;
|
|
||||||
p += elementHeaderLen;
|
p += elementHeaderLen;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
TIXMLASSERT( sizeof( XMLText ) == _textPool.ItemSize() );
|
returnNode = CreateUnlinkedNode<XMLText>( _textPool );
|
||||||
returnNode = new (_textPool.Alloc()) XMLText( this );
|
|
||||||
returnNode->_memPool = &_textPool;
|
|
||||||
returnNode->_parseLineNum = _parseCurLineNum; // Report line of first non-whitespace character
|
returnNode->_parseLineNum = _parseCurLineNum; // Report line of first non-whitespace character
|
||||||
p = start; // Back it up, all the text counts.
|
p = start; // Back it up, all the text counts.
|
||||||
_parseCurLineNum = startLine;
|
_parseCurLineNum = startLine;
|
||||||
|
@ -954,7 +955,7 @@ const XMLElement* XMLNode::PreviousSiblingElement( const char* name ) const
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
char* XMLNode::ParseDeep( char* p, StrPair* parentEnd, int* curLineNumPtr )
|
char* XMLNode::ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr )
|
||||||
{
|
{
|
||||||
// This is a recursive method, but thinking about it "at the current level"
|
// This is a recursive method, but thinking about it "at the current level"
|
||||||
// it is a pretty simple flat list:
|
// it is a pretty simple flat list:
|
||||||
|
@ -1019,8 +1020,8 @@ char* XMLNode::ParseDeep( char* p, StrPair* parentEnd, int* curLineNumPtr )
|
||||||
if ( ele ) {
|
if ( ele ) {
|
||||||
// We read the end tag. Return it to the parent.
|
// We read the end tag. Return it to the parent.
|
||||||
if ( ele->ClosingType() == XMLElement::CLOSING ) {
|
if ( ele->ClosingType() == XMLElement::CLOSING ) {
|
||||||
if ( parentEnd ) {
|
if ( parentEndTag ) {
|
||||||
ele->_value.TransferTo( parentEnd );
|
ele->_value.TransferTo( parentEndTag );
|
||||||
}
|
}
|
||||||
node->_memPool->SetTracked(); // created and then immediately deleted.
|
node->_memPool->SetTracked(); // created and then immediately deleted.
|
||||||
DeleteNode( node );
|
DeleteNode( node );
|
||||||
|
@ -1132,6 +1133,7 @@ XMLNode* XMLText::ShallowClone( XMLDocument* doc ) const
|
||||||
|
|
||||||
bool XMLText::ShallowEqual( const XMLNode* compare ) const
|
bool XMLText::ShallowEqual( const XMLNode* compare ) const
|
||||||
{
|
{
|
||||||
|
TIXMLASSERT( compare );
|
||||||
const XMLText* text = compare->ToText();
|
const XMLText* text = compare->ToText();
|
||||||
return ( text && XMLUtil::StringEqual( text->Value(), Value() ) );
|
return ( text && XMLUtil::StringEqual( text->Value(), Value() ) );
|
||||||
}
|
}
|
||||||
|
@ -1447,7 +1449,7 @@ void XMLAttribute::SetAttribute( float v )
|
||||||
|
|
||||||
// --------- XMLElement ---------- //
|
// --------- XMLElement ---------- //
|
||||||
XMLElement::XMLElement( XMLDocument* doc ) : XMLNode( doc ),
|
XMLElement::XMLElement( XMLDocument* doc ) : XMLNode( doc ),
|
||||||
_closingType( 0 ),
|
_closingType( OPEN ),
|
||||||
_rootAttribute( 0 )
|
_rootAttribute( 0 )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -1837,6 +1839,7 @@ XMLAttribute* XMLElement::CreateAttribute()
|
||||||
{
|
{
|
||||||
TIXMLASSERT( sizeof( XMLAttribute ) == _document->_attributePool.ItemSize() );
|
TIXMLASSERT( sizeof( XMLAttribute ) == _document->_attributePool.ItemSize() );
|
||||||
XMLAttribute* attrib = new (_document->_attributePool.Alloc() ) XMLAttribute();
|
XMLAttribute* attrib = new (_document->_attributePool.Alloc() ) XMLAttribute();
|
||||||
|
TIXMLASSERT( attrib );
|
||||||
attrib->_memPool = &_document->_attributePool;
|
attrib->_memPool = &_document->_attributePool;
|
||||||
attrib->_memPool->SetTracked();
|
attrib->_memPool->SetTracked();
|
||||||
return attrib;
|
return attrib;
|
||||||
|
@ -1846,7 +1849,7 @@ XMLAttribute* XMLElement::CreateAttribute()
|
||||||
// <ele></ele>
|
// <ele></ele>
|
||||||
// <ele>foo<b>bar</b></ele>
|
// <ele>foo<b>bar</b></ele>
|
||||||
//
|
//
|
||||||
char* XMLElement::ParseDeep( char* p, StrPair* strPair, int* curLineNumPtr )
|
char* XMLElement::ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr )
|
||||||
{
|
{
|
||||||
// Read the element name.
|
// Read the element name.
|
||||||
p = XMLUtil::SkipWhiteSpace( p, curLineNumPtr );
|
p = XMLUtil::SkipWhiteSpace( p, curLineNumPtr );
|
||||||
|
@ -1865,11 +1868,11 @@ char* XMLElement::ParseDeep( char* p, StrPair* strPair, int* curLineNumPtr )
|
||||||
}
|
}
|
||||||
|
|
||||||
p = ParseAttributes( p, curLineNumPtr );
|
p = ParseAttributes( p, curLineNumPtr );
|
||||||
if ( !p || !*p || _closingType ) {
|
if ( !p || !*p || _closingType != OPEN ) {
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
p = XMLNode::ParseDeep( p, strPair, curLineNumPtr );
|
p = XMLNode::ParseDeep( p, parentEndTag, curLineNumPtr );
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1955,12 +1958,12 @@ const char* XMLDocument::_errorNames[XML_ERROR_COUNT] = {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
XMLDocument::XMLDocument( bool processEntities, Whitespace whitespace ) :
|
XMLDocument::XMLDocument( bool processEntities, Whitespace whitespaceMode ) :
|
||||||
XMLNode( 0 ),
|
XMLNode( 0 ),
|
||||||
_writeBOM( false ),
|
_writeBOM( false ),
|
||||||
_processEntities( processEntities ),
|
_processEntities( processEntities ),
|
||||||
_errorID(XML_SUCCESS),
|
_errorID(XML_SUCCESS),
|
||||||
_whitespace( whitespace ),
|
_whitespaceMode( whitespaceMode ),
|
||||||
_errorLineNum( 0 ),
|
_errorLineNum( 0 ),
|
||||||
_charBuffer( 0 ),
|
_charBuffer( 0 ),
|
||||||
_parseCurLineNum( 0 )
|
_parseCurLineNum( 0 )
|
||||||
|
@ -2008,9 +2011,7 @@ void XMLDocument::Clear()
|
||||||
|
|
||||||
XMLElement* XMLDocument::NewElement( const char* name )
|
XMLElement* XMLDocument::NewElement( const char* name )
|
||||||
{
|
{
|
||||||
TIXMLASSERT( sizeof( XMLElement ) == _elementPool.ItemSize() );
|
XMLElement* ele = CreateUnlinkedNode<XMLElement>( _elementPool );
|
||||||
XMLElement* ele = new (_elementPool.Alloc()) XMLElement( this );
|
|
||||||
ele->_memPool = &_elementPool;
|
|
||||||
ele->SetName( name );
|
ele->SetName( name );
|
||||||
return ele;
|
return ele;
|
||||||
}
|
}
|
||||||
|
@ -2018,9 +2019,7 @@ XMLElement* XMLDocument::NewElement( const char* name )
|
||||||
|
|
||||||
XMLComment* XMLDocument::NewComment( const char* str )
|
XMLComment* XMLDocument::NewComment( const char* str )
|
||||||
{
|
{
|
||||||
TIXMLASSERT( sizeof( XMLComment ) == _commentPool.ItemSize() );
|
XMLComment* comment = CreateUnlinkedNode<XMLComment>( _commentPool );
|
||||||
XMLComment* comment = new (_commentPool.Alloc()) XMLComment( this );
|
|
||||||
comment->_memPool = &_commentPool;
|
|
||||||
comment->SetValue( str );
|
comment->SetValue( str );
|
||||||
return comment;
|
return comment;
|
||||||
}
|
}
|
||||||
|
@ -2028,9 +2027,7 @@ XMLComment* XMLDocument::NewComment( const char* str )
|
||||||
|
|
||||||
XMLText* XMLDocument::NewText( const char* str )
|
XMLText* XMLDocument::NewText( const char* str )
|
||||||
{
|
{
|
||||||
TIXMLASSERT( sizeof( XMLText ) == _textPool.ItemSize() );
|
XMLText* text = CreateUnlinkedNode<XMLText>( _textPool );
|
||||||
XMLText* text = new (_textPool.Alloc()) XMLText( this );
|
|
||||||
text->_memPool = &_textPool;
|
|
||||||
text->SetValue( str );
|
text->SetValue( str );
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
@ -2038,9 +2035,7 @@ XMLText* XMLDocument::NewText( const char* str )
|
||||||
|
|
||||||
XMLDeclaration* XMLDocument::NewDeclaration( const char* str )
|
XMLDeclaration* XMLDocument::NewDeclaration( const char* str )
|
||||||
{
|
{
|
||||||
TIXMLASSERT( sizeof( XMLDeclaration ) == _commentPool.ItemSize() );
|
XMLDeclaration* dec = CreateUnlinkedNode<XMLDeclaration>( _commentPool );
|
||||||
XMLDeclaration* dec = new (_commentPool.Alloc()) XMLDeclaration( this );
|
|
||||||
dec->_memPool = &_commentPool;
|
|
||||||
dec->SetValue( str ? str : "xml version=\"1.0\" encoding=\"UTF-8\"" );
|
dec->SetValue( str ? str : "xml version=\"1.0\" encoding=\"UTF-8\"" );
|
||||||
return dec;
|
return dec;
|
||||||
}
|
}
|
||||||
|
@ -2048,9 +2043,7 @@ XMLDeclaration* XMLDocument::NewDeclaration( const char* str )
|
||||||
|
|
||||||
XMLUnknown* XMLDocument::NewUnknown( const char* str )
|
XMLUnknown* XMLDocument::NewUnknown( const char* str )
|
||||||
{
|
{
|
||||||
TIXMLASSERT( sizeof( XMLUnknown ) == _commentPool.ItemSize() );
|
XMLUnknown* unk = CreateUnlinkedNode<XMLUnknown>( _commentPool );
|
||||||
XMLUnknown* unk = new (_commentPool.Alloc()) XMLUnknown( this );
|
|
||||||
unk->_memPool = &_commentPool;
|
|
||||||
unk->SetValue( str );
|
unk->SetValue( str );
|
||||||
return unk;
|
return unk;
|
||||||
}
|
}
|
||||||
|
|
50
tinyxml2.h
50
tinyxml2.h
|
@ -527,7 +527,7 @@ enum XMLError {
|
||||||
/*
|
/*
|
||||||
Utility functionality.
|
Utility functionality.
|
||||||
*/
|
*/
|
||||||
class XMLUtil
|
class TINYXML2_LIB XMLUtil
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static const char* SkipWhiteSpace( const char* p, int* curLineNumPtr ) {
|
static const char* SkipWhiteSpace( const char* p, int* curLineNumPtr ) {
|
||||||
|
@ -605,6 +605,17 @@ public:
|
||||||
static bool ToFloat( const char* str, float* value );
|
static bool ToFloat( const char* str, float* value );
|
||||||
static bool ToDouble( const char* str, double* value );
|
static bool ToDouble( const char* str, double* value );
|
||||||
static bool ToInt64(const char* str, int64_t* value);
|
static bool ToInt64(const char* str, int64_t* value);
|
||||||
|
|
||||||
|
// Changes what is serialized for a boolean value.
|
||||||
|
// Default to "true" and "false". Shouldn't be changed
|
||||||
|
// unless you have a special testing or compatibility need.
|
||||||
|
// Be careful: static, global, & not thread safe.
|
||||||
|
// Be sure to set static const memory as parameters.
|
||||||
|
static void SetBoolSerialization(const char* writeTrue, const char* writeFalse);
|
||||||
|
|
||||||
|
private:
|
||||||
|
static const char* writeBoolTrue;
|
||||||
|
static const char* writeBoolFalse;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -896,7 +907,7 @@ protected:
|
||||||
XMLNode( XMLDocument* );
|
XMLNode( XMLDocument* );
|
||||||
virtual ~XMLNode();
|
virtual ~XMLNode();
|
||||||
|
|
||||||
virtual char* ParseDeep( char*, StrPair*, int* );
|
virtual char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr);
|
||||||
|
|
||||||
XMLDocument* _document;
|
XMLDocument* _document;
|
||||||
XMLNode* _parent;
|
XMLNode* _parent;
|
||||||
|
@ -964,7 +975,7 @@ protected:
|
||||||
XMLText( XMLDocument* doc ) : XMLNode( doc ), _isCData( false ) {}
|
XMLText( XMLDocument* doc ) : XMLNode( doc ), _isCData( false ) {}
|
||||||
virtual ~XMLText() {}
|
virtual ~XMLText() {}
|
||||||
|
|
||||||
char* ParseDeep( char*, StrPair* endTag, int* curLineNumPtr );
|
char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool _isCData;
|
bool _isCData;
|
||||||
|
@ -995,7 +1006,7 @@ protected:
|
||||||
XMLComment( XMLDocument* doc );
|
XMLComment( XMLDocument* doc );
|
||||||
virtual ~XMLComment();
|
virtual ~XMLComment();
|
||||||
|
|
||||||
char* ParseDeep( char*, StrPair* endTag, int* curLineNumPtr);
|
char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
XMLComment( const XMLComment& ); // not supported
|
XMLComment( const XMLComment& ); // not supported
|
||||||
|
@ -1034,7 +1045,7 @@ protected:
|
||||||
XMLDeclaration( XMLDocument* doc );
|
XMLDeclaration( XMLDocument* doc );
|
||||||
virtual ~XMLDeclaration();
|
virtual ~XMLDeclaration();
|
||||||
|
|
||||||
char* ParseDeep( char*, StrPair* endTag, int* curLineNumPtr );
|
char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
XMLDeclaration( const XMLDeclaration& ); // not supported
|
XMLDeclaration( const XMLDeclaration& ); // not supported
|
||||||
|
@ -1069,7 +1080,7 @@ protected:
|
||||||
XMLUnknown( XMLDocument* doc );
|
XMLUnknown( XMLDocument* doc );
|
||||||
virtual ~XMLUnknown();
|
virtual ~XMLUnknown();
|
||||||
|
|
||||||
char* ParseDeep( char*, StrPair* endTag, int* curLineNumPtr );
|
char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
XMLUnknown( const XMLUnknown& ); // not supported
|
XMLUnknown( const XMLUnknown& ); // not supported
|
||||||
|
@ -1548,19 +1559,19 @@ public:
|
||||||
float FloatText(float defaultValue = 0) const;
|
float FloatText(float defaultValue = 0) const;
|
||||||
|
|
||||||
// internal:
|
// internal:
|
||||||
enum {
|
enum ElementClosingType {
|
||||||
OPEN, // <foo>
|
OPEN, // <foo>
|
||||||
CLOSED, // <foo/>
|
CLOSED, // <foo/>
|
||||||
CLOSING // </foo>
|
CLOSING // </foo>
|
||||||
};
|
};
|
||||||
int ClosingType() const {
|
ElementClosingType ClosingType() const {
|
||||||
return _closingType;
|
return _closingType;
|
||||||
}
|
}
|
||||||
virtual XMLNode* ShallowClone( XMLDocument* document ) const;
|
virtual XMLNode* ShallowClone( XMLDocument* document ) const;
|
||||||
virtual bool ShallowEqual( const XMLNode* compare ) const;
|
virtual bool ShallowEqual( const XMLNode* compare ) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
char* ParseDeep( char* p, StrPair* endTag, int* curLineNumPtr );
|
char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
XMLElement( XMLDocument* doc );
|
XMLElement( XMLDocument* doc );
|
||||||
|
@ -1578,7 +1589,7 @@ private:
|
||||||
XMLAttribute* CreateAttribute();
|
XMLAttribute* CreateAttribute();
|
||||||
|
|
||||||
enum { BUF_SIZE = 200 };
|
enum { BUF_SIZE = 200 };
|
||||||
int _closingType;
|
ElementClosingType _closingType;
|
||||||
// The attribute list is ordered; there is no 'lastAttribute'
|
// The attribute list is ordered; there is no 'lastAttribute'
|
||||||
// because the list needs to be scanned for dupes before adding
|
// because the list needs to be scanned for dupes before adding
|
||||||
// a new attribute.
|
// a new attribute.
|
||||||
|
@ -1602,7 +1613,7 @@ class TINYXML2_LIB XMLDocument : public XMLNode
|
||||||
friend class XMLElement;
|
friend class XMLElement;
|
||||||
public:
|
public:
|
||||||
/// constructor
|
/// constructor
|
||||||
XMLDocument( bool processEntities = true, Whitespace = PRESERVE_WHITESPACE );
|
XMLDocument( bool processEntities = true, Whitespace whitespaceMode = PRESERVE_WHITESPACE );
|
||||||
~XMLDocument();
|
~XMLDocument();
|
||||||
|
|
||||||
virtual XMLDocument* ToDocument() {
|
virtual XMLDocument* ToDocument() {
|
||||||
|
@ -1666,7 +1677,7 @@ public:
|
||||||
return _processEntities;
|
return _processEntities;
|
||||||
}
|
}
|
||||||
Whitespace WhitespaceMode() const {
|
Whitespace WhitespaceMode() const {
|
||||||
return _whitespace;
|
return _whitespaceMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1804,7 +1815,7 @@ private:
|
||||||
bool _writeBOM;
|
bool _writeBOM;
|
||||||
bool _processEntities;
|
bool _processEntities;
|
||||||
XMLError _errorID;
|
XMLError _errorID;
|
||||||
Whitespace _whitespace;
|
Whitespace _whitespaceMode;
|
||||||
mutable StrPair _errorStr1;
|
mutable StrPair _errorStr1;
|
||||||
mutable StrPair _errorStr2;
|
mutable StrPair _errorStr2;
|
||||||
int _errorLineNum;
|
int _errorLineNum;
|
||||||
|
@ -1819,8 +1830,21 @@ private:
|
||||||
static const char* _errorNames[XML_ERROR_COUNT];
|
static const char* _errorNames[XML_ERROR_COUNT];
|
||||||
|
|
||||||
void Parse();
|
void Parse();
|
||||||
|
|
||||||
|
template<class NodeType, int PoolElementSize>
|
||||||
|
NodeType* CreateUnlinkedNode( MemPoolT<PoolElementSize>& pool );
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<class NodeType, int PoolElementSize>
|
||||||
|
inline NodeType* XMLDocument::CreateUnlinkedNode( MemPoolT<PoolElementSize>& pool )
|
||||||
|
{
|
||||||
|
TIXMLASSERT( sizeof( NodeType ) == PoolElementSize );
|
||||||
|
TIXMLASSERT( sizeof( NodeType ) == pool.ItemSize() );
|
||||||
|
NodeType* returnNode = new (pool.Alloc()) NodeType( this );
|
||||||
|
TIXMLASSERT( returnNode );
|
||||||
|
returnNode->_memPool = &pool;
|
||||||
|
return returnNode;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
A XMLHandle is a class that wraps a node pointer with null checks; this is
|
A XMLHandle is a class that wraps a node pointer with null checks; this is
|
||||||
|
|
29
xmltest.cpp
29
xmltest.cpp
|
@ -10,16 +10,10 @@
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
|
|
||||||
#if defined( _MSC_VER )
|
#if defined( _MSC_VER )
|
||||||
#include <direct.h> // _mkdir
|
|
||||||
#include <crtdbg.h>
|
#include <crtdbg.h>
|
||||||
#define WIN32_LEAN_AND_MEAN
|
#define WIN32_LEAN_AND_MEAN
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
_CrtMemState startMemState;
|
_CrtMemState startMemState;
|
||||||
_CrtMemState endMemState;
|
|
||||||
#elif defined(MINGW32) || defined(__MINGW32__)
|
|
||||||
#include <io.h> // mkdir
|
|
||||||
#else
|
|
||||||
#include <sys/stat.h> // mkdir
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
using namespace tinyxml2;
|
using namespace tinyxml2;
|
||||||
|
@ -299,17 +293,6 @@ int main( int argc, const char ** argv )
|
||||||
_CrtSetDbgFlag(_CrtSetDbgFlag(_CRTDBG_REPORT_FLAG) | _CRTDBG_LEAK_CHECK_DF);
|
_CrtSetDbgFlag(_CrtSetDbgFlag(_CRTDBG_REPORT_FLAG) | _CRTDBG_LEAK_CHECK_DF);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(_MSC_VER) || defined(MINGW32) || defined(__MINGW32__)
|
|
||||||
#if defined __MINGW64_VERSION_MAJOR && defined __MINGW64_VERSION_MINOR
|
|
||||||
//MINGW64: both 32 and 64-bit
|
|
||||||
mkdir( "resources/out/" );
|
|
||||||
#else
|
|
||||||
_mkdir( "resources/out/" );
|
|
||||||
#endif
|
|
||||||
#else
|
|
||||||
mkdir( "resources/out/", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
{
|
{
|
||||||
TIXMLASSERT( true );
|
TIXMLASSERT( true );
|
||||||
}
|
}
|
||||||
|
@ -752,6 +735,18 @@ int main( int argc, const char ** argv )
|
||||||
XMLTest("Attribute: bool", true, v, true);
|
XMLTest("Attribute: bool", true, v, true);
|
||||||
XMLTest("Attribute: bool", true, element->BoolAttribute("attrib"), true);
|
XMLTest("Attribute: bool", true, element->BoolAttribute("attrib"), true);
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
element->SetAttribute("attrib", true);
|
||||||
|
const char* result = element->Attribute("attrib");
|
||||||
|
XMLTest("Bool true is 'true'", "true", result);
|
||||||
|
|
||||||
|
XMLUtil::SetBoolSerialization("1", "0");
|
||||||
|
element->SetAttribute("attrib", true);
|
||||||
|
result = element->Attribute("attrib");
|
||||||
|
XMLTest("Bool true is '1'", "1", result);
|
||||||
|
|
||||||
|
XMLUtil::SetBoolSerialization(0, 0);
|
||||||
|
}
|
||||||
{
|
{
|
||||||
element->SetAttribute("attrib", 100.0);
|
element->SetAttribute("attrib", 100.0);
|
||||||
double v = 0;
|
double v = 0;
|
||||||
|
|
Loading…
Reference in New Issue