[cig-commits] r21117 - cs/spatialdata/trunk/libsrc/units

brad at geodynamics.org brad at geodynamics.org
Mon Dec 10 14:28:49 PST 2012


Author: brad
Date: 2012-12-10 14:28:48 -0800 (Mon, 10 Dec 2012)
New Revision: 21117

Modified:
   cs/spatialdata/trunk/libsrc/units/Parser.cc
Log:
Small cleanup of error reporting in Parser.

Modified: cs/spatialdata/trunk/libsrc/units/Parser.cc
===================================================================
--- cs/spatialdata/trunk/libsrc/units/Parser.cc	2012-12-10 22:17:36 UTC (rev 21116)
+++ cs/spatialdata/trunk/libsrc/units/Parser.cc	2012-12-10 22:28:48 UTC (rev 21117)
@@ -73,25 +73,25 @@
    * x = p.parse(units) [units is a string]
    * scale = x.value
    */
-  PyObject *pyUnit  = PyObject_CallMethod(_parser, "parse", "s", units);
-  if (pyUnit == 0) {
+  PyObject* pyUnit  = PyObject_CallMethod(_parser, "parse", "s", units);
+  if (!pyUnit) {
     if (PyErr_Occurred()) {
       PyErr_Clear();
-      std::ostringstream msg;
-      msg << "Could not parse units string '" << units << "'.";
-      throw std::runtime_error(msg.str());
-    } // if
+    } // if      
+    std::ostringstream msg;
+    msg << "Could not parse units string '" << units << "'.";
+    throw std::runtime_error(msg.str());
   } // if
-  PyObject *pyScale = PyObject_GetAttrString(pyUnit, "value");
-  if (pyScale == 0) {
+  PyObject* pyScale = PyObject_GetAttrString(pyUnit, "value");
+  if (!pyScale) {
     Py_DECREF(pyUnit);
     if (PyErr_Occurred()) {
       PyErr_Clear();
-      std::ostringstream msg;
-      msg << "Could not get floating point value when parsing units string '"
-	  << units << "'.";
-      throw std::runtime_error(msg.str());
     } // if
+    std::ostringstream msg;
+    msg << "Could not get floating point value when parsing units string '"
+	<< units << "'.";
+    throw std::runtime_error(msg.str());
   } // if
   if (!PyFloat_Check(pyScale)) {
     Py_DECREF(pyScale);
@@ -106,6 +106,7 @@
   scale = PyFloat_AsDouble(pyScale);
   Py_DECREF(pyScale);
   Py_DECREF(pyUnit);
+
   return scale;
 } // parser
 



More information about the CIG-COMMITS mailing list