From: Leon W. <moo...@us...> - 2005-04-14 11:31:17
|
Update of /cvsroot/anyedit/AnyEditv2 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6167 Modified Files: XMLFile.cpp XMLFile.h Log Message: Class Improvements - Added AddChildElement functions, to add child nodes to a node. - Added extra check in set functions. We only change the value if it is different, so we don't set the modified flag unneeded and need to save unneeded. Index: XMLFile.h =================================================================== RCS file: /cvsroot/anyedit/AnyEditv2/XMLFile.h,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** XMLFile.h 23 Dec 2004 11:42:59 -0000 1.7 --- XMLFile.h 14 Apr 2005 11:30:20 -0000 1.8 *************** *** 119,122 **** --- 119,140 ---- bool SetStringAttributeToXMLFile( pug::xml_node& xnode, const TCHAR* attribute, const CString& szValue ); + /// Add a child boolean element to a section. + bool AddChildBoolElement( const TCHAR* section, const TCHAR* name, bool bValue ); + + /// Add a child boolean element to a node. + bool AddChildBoolElement( pug::xml_node& xnode, const TCHAR* name, bool bValue ); + + /// Add a child int element to a section. + bool AddChildIntElement( const TCHAR* section, const TCHAR* name, int iValue ); + + /// Add a child int element to a node. + bool AddChildIntElement( pug::xml_node& xnode, const TCHAR* name, int iValue ); + + /// Add a child string element to a section. + bool AddChildStringElement( const TCHAR* section, const TCHAR* name, const CString& szValue, bool bParsedData = true ); + + /// Add a child string element to a node. + bool AddChildStringElement( pug::xml_node& xnode, const TCHAR* name, const CString& szValue, bool bParsedData = true ); + public: DECLARE_DYNAMIC(CXMLFile) Index: XMLFile.cpp =================================================================== RCS file: /cvsroot/anyedit/AnyEditv2/XMLFile.cpp,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** XMLFile.cpp 23 Dec 2004 11:42:59 -0000 1.9 --- XMLFile.cpp 14 Apr 2005 11:30:19 -0000 1.10 *************** *** 126,132 **** if( xnode.empty() || !xnode.has_child_nodes() ) return false; ! if( !SetStringToXMLFile( xnode, element, sValue, bParsedData ) ) return false; ! ! return m_bModified = true; } --- 126,130 ---- if( xnode.empty() || !xnode.has_child_nodes() ) return false; ! return SetStringToXMLFile( xnode, element, sValue, bParsedData ); } *************** *** 146,149 **** --- 144,148 ---- else { + if( sValue == tnode.child(0).value() ) return true; tnode.child(0).type( bParsedData ? pug::node_pcdata : pug::node_cdata ); if( !tnode.child(0).value( sValue ) ) return false; *************** *** 268,271 **** --- 267,271 ---- else { + if( szValue == xattribute.value() ) return true; if( !xattribute.value( szValue ) ) return false; } *************** *** 274,277 **** --- 274,337 ---- } + // Add a child boolean element to a section. + bool CXMLFile::AddChildBoolElement( const TCHAR* section, const TCHAR* name, bool bValue ) + { + return AddChildIntElement( section, name, bValue ? 1 : 0 ); + } + + // Add a child boolean element to a node. + bool CXMLFile::AddChildBoolElement( pug::xml_node& xnode, const TCHAR* name, bool bValue ) + { + return AddChildIntElement( xnode, name, bValue ? 1 : 0 ); + } + + // Add a child int element to a section. + bool CXMLFile::AddChildIntElement( const TCHAR* section, const TCHAR* name, int iValue ) + { + CString sValue; + + sValue.Format( "%i", iValue ); + + return AddChildStringElement( section, name, sValue ); + } + + // Add a child int element to a node. + bool CXMLFile::AddChildIntElement( pug::xml_node& xnode, const TCHAR* name, int iValue ) + { + CString sValue; + + sValue.Format( "%i", iValue ); + + return AddChildStringElement( xnode, name, sValue ); + } + + // Add a child string element to a section. + bool CXMLFile::AddChildStringElement( const TCHAR* section, const TCHAR* name, const CString& szValue, bool bParsedData ) + { + if( !m_bParsed && !Parse() ) return false; + + pug::xml_node xnode( m_xml_parser.document().first_element_by_name( section ) ); + if( xnode.empty() ) return false; + + return AddChildStringElement( xnode, name, szValue, bParsedData ); + } + + // Add a child string element to a node. + bool CXMLFile::AddChildStringElement( pug::xml_node& xnode, const TCHAR* name, const CString& szValue, bool bParsedData ) + { + pug::xml_node tnode; + tnode = xnode.append_child( pug::node_element ); + if( tnode.empty() ) return false; + + m_bModified = true; + + if( !tnode.name( name ) ) return false; + + tnode = tnode.append_child( bParsedData ? pug::node_pcdata : pug::node_cdata ); + if( tnode.empty() ) return false; + + return tnode.value( szValue ); + } + // Constructor CXMLFile::CXMLFile() |