summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrandomdan <randomdan@localhost>2011-06-29 19:13:24 +0000
committerrandomdan <randomdan@localhost>2011-06-29 19:13:24 +0000
commitb20f8191ea4da22bc7191e10e46c2875d8718269 (patch)
tree6f2d08957cf0f2a7e08d55f14f319d0dc1b980cc
parentBuild fsRows against both versions 2 and 3 of boost::filesystem (diff)
downloadproject2-b20f8191ea4da22bc7191e10e46c2875d8718269.tar.bz2
project2-b20f8191ea4da22bc7191e10e46c2875d8718269.tar.xz
project2-b20f8191ea4da22bc7191e10e46c2875d8718269.zip
Fix unused_result warning when compiled with optimization enabled
Fix incorrect error handling when object loading fails
-rw-r--r--project2/fileStrmVarWriter.cpp8
-rw-r--r--project2/xmlObjectLoader.cpp16
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<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::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<SourceObjectPtr> LoaderBase::loadedObjects;
+class DepthCounter {
+ public:
+ DepthCounter(unsigned int & c) : counter(c) {
+ counter += 1;
+ }
+ ~DepthCounter() {
+ counter -= 1;
+ }
+ private:
+ unsigned int & counter;
+};
+
typedef std::map<std::string, boost::shared_ptr<ElementLoader> > ElementLoaderMap;
typedef std::set<boost::shared_ptr<ComponentLoader> > 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<const xmlpp::Element *>(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()) {