From 4e35856e1045d356d3fcad1b4db4e40e613847c6 Mon Sep 17 00:00:00 2001 From: jhurst Date: Fri, 11 Jul 2008 06:30:14 +0000 Subject: [PATCH] added ostream for log, SAX parser improvements --- src/KM_log.cpp | 20 ++++++++++++++++++++ src/KM_log.h | 5 +++++ src/KM_xml.cpp | 14 +++++++++----- 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/src/KM_log.cpp b/src/KM_log.cpp index 4778ffc..aa0303b 100755 --- a/src/KM_log.cpp +++ b/src/KM_log.cpp @@ -34,6 +34,8 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include +#include #ifdef KM_WIN32 #define getpid GetCurrentProcessId @@ -144,6 +146,24 @@ Kumu::StreamLogSink::WriteEntry(const LogEntry& Entry) //------------------------------------------------------------------------------------------ +// +std::basic_ostream >& +Kumu::operator<<(std::basic_ostream >& strm, LogEntry const& Entry) +{ + std::basic_ostringstream > s; + s.copyfmt(strm); + s.width(0); + std::string buf; + + s << Entry.CreateStringWithOptions(buf, LOG_OPTION_ALL); + + strm << s.str(); + return strm; +} + +//------------------------------------------------------------------------------------------ + + // bool Kumu::LogEntry::TestFilter(i32_t filter) const diff --git a/src/KM_log.h b/src/KM_log.h index fb8d805..671c072 100755 --- a/src/KM_log.h +++ b/src/KM_log.h @@ -38,6 +38,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include #define LOG_MSG_IMPL(t) \ va_list args; \ @@ -135,6 +136,10 @@ namespace Kumu bool Unarchive(MemIOReader* Reader); }; + // + std::basic_ostream >& + operator<<(std::basic_ostream >& strm, LogEntry const& Entry); + typedef ArchivableList LogEntryList; diff --git a/src/KM_xml.cpp b/src/KM_xml.cpp index b7b8c09..4792e9b 100644 --- a/src/KM_xml.cpp +++ b/src/KM_xml.cpp @@ -683,6 +683,7 @@ Kumu::XMLElement::ParseString(const std::string& document) asdcp_init_xml_dom(); + int errorCount = 0; SAXParser* parser = new SAXParser(); parser->setDoValidation(true); parser->setDoNamespaces(true); // optional @@ -704,25 +705,28 @@ Kumu::XMLElement::ParseString(const std::string& document) char* message = XMLString::transcode(e.getMessage()); DefaultLogSink().Error("Parser error: %s\n", message); XMLString::release(&message); - return false; + errorCount++; } catch (const SAXParseException& e) { char* message = XMLString::transcode(e.getMessage()); DefaultLogSink().Error("Parser error: %s at line %d\n", message, e.getLineNumber()); XMLString::release(&message); - return false; + errorCount++; } catch (...) { DefaultLogSink().Error("Unexpected XML parser error\n"); - return false; + errorCount++; } - m_NamespaceOwner = (void*)docHandler->TakeNamespaceMap(); + if ( errorCount == 0 ) + m_NamespaceOwner = (void*)docHandler->TakeNamespaceMap(); + delete parser; delete docHandler; - return true; + + return errorCount > 0 ? false : true; } // -- 2.30.2