From a58275c27dcd17f02c8873786b93b553c18ad0bb Mon Sep 17 00:00:00 2001 From: randomdan Date: Wed, 29 Jun 2011 19:13:24 +0000 Subject: Fix unused_result warning when compiled with optimization enabled Fix incorrect error handling when object loading fails --- project2/fileStrmVarWriter.cpp | 8 ++++++-- project2/xmlObjectLoader.cpp | 16 +++++++++++++--- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/project2/fileStrmVarWriter.cpp b/project2/fileStrmVarWriter.cpp index 8f3ca5c..564c86a 100644 --- a/project2/fileStrmVarWriter.cpp +++ b/project2/fileStrmVarWriter.cpp @@ -49,10 +49,14 @@ void FileStreamVariableWriter::operator()(const double & i) const { fprintf(out, "%g", i); } void FileStreamVariableWriter::operator()(const Glib::ustring & i) const { - fwrite(i.c_str(), i.bytes(), 1, out); + if (fwrite(i.c_str(), i.bytes(), 1, out) < 1) { + // Care much? None of the others check. + } } void FileStreamVariableWriter::operator()(const boost::shared_ptr & i) const { - fwrite(i->c_str(), i->bytes(), 1, out); + if (fwrite(i->c_str(), i->bytes(), 1, out) < 1) { + // Care much? None of the others check. + } } void FileStreamVariableWriter::operator()(const boost::posix_time::ptime & i) const { fprintf(out, "[%s]", boost::posix_time::to_iso_extended_string(i).c_str()); diff --git a/project2/xmlObjectLoader.cpp b/project2/xmlObjectLoader.cpp index b33bf85..d2f25e7 100644 --- a/project2/xmlObjectLoader.cpp +++ b/project2/xmlObjectLoader.cpp @@ -10,6 +10,18 @@ unsigned int LoaderBase::depth = 0; std::set LoaderBase::loadedObjects; +class DepthCounter { + public: + DepthCounter(unsigned int & c) : counter(c) { + counter += 1; + } + ~DepthCounter() { + counter -= 1; + } + private: + unsigned int & counter; +}; + typedef std::map > ElementLoaderMap; typedef std::set > ComponentLoaderSet; @@ -47,7 +59,7 @@ LoaderBase::collectAll(const xmlpp::Element * node, bool childrenOnly, Unsupport if (!node) { return; } - depth += 1; + DepthCounter dc(depth); unsigned int created = 0; if (!childrenOnly && node->get_namespace_uri() == ns) { Glib::ustring name = node->get_name(); @@ -74,7 +86,6 @@ LoaderBase::collectAll(const xmlpp::Element * node, bool childrenOnly, Unsupport collectAll(dynamic_cast(child), false, uh); } } - depth -= 1; } void @@ -102,7 +113,6 @@ void LoaderBase::onIteration() { // This is a fail safe in the event that something goes pearshape - depth = 0; loadedObjects.clear(); BOOST_FOREACH(ComponentLoaderSet::value_type l, *componentLoaders()) { -- cgit v1.2.3