changeset 107:691ef5c6b9e2

maint: Clean up std namespace pollution * octave_to_python.cc, pytave.cc, python_to_octave.cc: Clean up std namespace pollution.
author Mike Miller <mtmiller@octave.org>
date Tue, 28 Apr 2015 21:31:10 -0400
parents 896fdc369789
children 74f17b2a5d45
files octave_to_python.cc pytave.cc python_to_octave.cc
diffstat 3 files changed, 29 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/octave_to_python.cc	Tue Apr 14 07:44:24 2015 -0400
+++ b/octave_to_python.cc	Tue Apr 28 21:31:10 2015 -0400
@@ -47,7 +47,6 @@
  *  (e.g. PyArray_INT ).
  */
 
-using namespace std;
 using namespace boost::python;
 
 namespace pytave {
@@ -163,7 +162,7 @@
             bytes == sizeof(short) && bytes != sizeof(int)> inst;
          return create_array<unsigned short, CLASS>(value, PyArray_USHORT, inst);
       } else {
-         ostringstream os;
+         std::ostringstream os;
          os << "Numeric arrays does not support unsigned " << (bytes*8)
             << "-bit values on this architecture.";
          throw value_convert_exception(os.str());
@@ -195,7 +194,7 @@
             bytes==sizeof(short) && bytes != sizeof(int)> inst;
          return create_array<signed short, CLASS>(value, PyArray_SHORT, inst);
       } else {
-         ostringstream os;
+         std::ostringstream os;
          os << "Numeric arrays doesn't support signed " << (bytes*8)
             << "-bit values on this architecture.";
          throw value_convert_exception(os.str());
--- a/pytave.cc	Tue Apr 14 07:44:24 2015 -0400
+++ b/pytave.cc	Tue Apr 28 21:31:10 2015 -0400
@@ -54,7 +54,6 @@
 #include "python_to_octave.h"
 
 using namespace boost::python;
-using namespace std;
 
 namespace pytave { /* {{{ */
 
@@ -126,10 +125,10 @@
                                   variable_name_exception::excclass)));
    }
 
-   string make_error_message (const octave_map& map) {
-      ostringstream exceptionmsg;
-      string message = map(0).getfield("message").string_value();
-      string identifier = map(0).getfield("identifier").string_value();
+   std::string make_error_message (const octave_map& map) {
+      std::ostringstream exceptionmsg;
+      std::string message = map(0).getfield("message").string_value();
+      std::string identifier = map(0).getfield("identifier").string_value();
       Cell stackCell = map.contents("stack");
 
       // Trim trailing new lines
@@ -139,8 +138,8 @@
          // The struct element is called "stack" but only contain
          // info about the top frame.
          octave_map stack = stackCell(0).map_value();
-         string file = stack(0).getfield("file").string_value();
-         string name = stack(0).getfield("name").string_value();
+         std::string file = stack(0).getfield("file").string_value();
+         std::string name = stack(0).getfield("name").string_value();
          int line = stack(0).getfield("line").int_value();
          int column = stack(0).getfield("column").int_value();
 
@@ -158,7 +157,7 @@
    }
 
    boost::python::tuple func_eval(const int nargout,
-                                  const string &funcname,
+                                  const std::string &funcname,
                                   const boost::python::tuple &arguments) {
 
       octave_value_list octave_args, retval;
@@ -180,7 +179,7 @@
       Py_BEGIN_ALLOW_THREADS
       try {
          retval = feval(funcname, octave_args, (nargout >= 0) ? nargout : 0);
-      } catch (bad_alloc) {
+      } catch (std::bad_alloc) {
          bad_alloc_state = true;
       }
       Py_END_ALLOW_THREADS
@@ -191,7 +190,7 @@
 #endif
 
       if (bad_alloc_state)
-         throw bad_alloc (); // Translated to MemoryError by boost::python
+         throw std::bad_alloc (); // Translated to MemoryError by boost::python
 
       else if (error_state != 0) {
 // error_state values:
@@ -203,7 +202,7 @@
          octave_value_list lasterror = eval_string("lasterror",
                                                    true, parse_status, 1);
          if (!lasterror.empty() && lasterror(0).is_map()) {
-            string exceptionmsg = make_error_message(lasterror(0).map_value ());
+            std::string exceptionmsg = make_error_message(lasterror(0).map_value ());
             throw octave_error_exception(exceptionmsg);
          } else
             throw octave_error_exception("No Octave error available");
@@ -220,7 +219,7 @@
    }
 
    boost::python::tuple str_eval(int nargout,
-                                 const string &code,
+                                 const std::string &code,
                                  bool silent) {
 
       octave_value_list retval;
@@ -242,7 +241,7 @@
       try {
          retval = eval_string(code, silent, parse_status,
             (nargout >= 0) ? nargout : 0);
-      } catch (bad_alloc) {
+      } catch (std::bad_alloc) {
          bad_alloc_state = true;
       }
       Py_END_ALLOW_THREADS
@@ -253,7 +252,7 @@
 #endif
 
       if (bad_alloc_state)
-         throw bad_alloc (); // Translated to MemoryError by boost::python
+         throw std::bad_alloc (); // Translated to MemoryError by boost::python
 
       if (parse_status != 0 || error_state != 0) {
 // error_state values:
@@ -265,7 +264,7 @@
          octave_value_list lasterror = eval_string("lasterror",
                                                    true, parse_status1, 1);
          if (!lasterror.empty() && lasterror(0).is_map()) {
-            string exceptionmsg = make_error_message (lasterror(0).map_value ());
+            std::string exceptionmsg = make_error_message (lasterror(0).map_value ());
 
             if (parse_status != 0)
                throw octave_parse_exception(exceptionmsg);
@@ -285,7 +284,7 @@
       }
    }
 
-   boost::python::object getvar(const string& name,
+   boost::python::object getvar(const std::string& name,
                                 bool global) {
       octave_value val;
 
@@ -304,7 +303,7 @@
       return pyobject;
    }
 
-   void setvar(const string& name, 
+   void setvar(const std::string& name,
                const boost::python::object& pyobject,
                bool global) {
       octave_value val;
@@ -321,7 +320,7 @@
          symbol_table::assign (name, val);
    }
 
-   bool isvar(const string& name, bool global) {
+   bool isvar(const std::string& name, bool global) {
       bool retval;
 
       if (global)
@@ -332,7 +331,7 @@
       return retval;
    }
 
-   void delvar(const string& name, bool global) {
+   void delvar(const std::string& name, bool global) {
 
       if (global) {
 
--- a/python_to_octave.cc	Tue Apr 14 07:44:24 2015 -0400
+++ b/python_to_octave.cc	Tue Apr 28 21:31:10 2015 -0400
@@ -40,7 +40,6 @@
 #include "arrayobjectdefs.h"
 #include "exceptions.h"
 
-using namespace std;
 using namespace boost::python;
 
 namespace pytave {
@@ -91,12 +90,12 @@
          for (int i = 0; i < pyarr->dimensions[dimension]; i++) {
             PyObject *pobj = *(PyObject **)
                &ptr[offset + i*pyarr->strides[dimension]];
-            pyobj_to_octvalue (matrix.elem(matindex + i*matstride), 
+            pyobj_to_octvalue (matrix.elem(matindex + i*matstride),
                                object(handle<PyObject> (borrowed (pobj))));
          }
       } else if (pyarr->nd == 0) {
             PyObject *pobj = *(PyObject **) ptr;
-            pyobj_to_octvalue (matrix.elem(0), 
+            pyobj_to_octvalue (matrix.elem(0),
                                object(handle<PyObject> (borrowed (pobj))));
       } else {
          for (int i = 0; i < pyarr->dimensions[dimension]; i++) {
@@ -202,7 +201,7 @@
             throw object_convert_exception(
                PyEval_GetFuncName((PyObject*)pyarr)
                + (PyEval_GetFuncDesc((PyObject*)pyarr)
-               + string(": Unsupported Python array type")));
+               + std::string(": Unsupported Python array type")));
       }
    }
 
@@ -319,7 +318,7 @@
             break;
          default:
             throw object_convert_exception(
-               PyEval_GetFuncDesc((PyObject*)(pyarr)) + string(" ")
+               PyEval_GetFuncDesc((PyObject*)(pyarr)) + std::string(" ")
                + PyEval_GetFuncName((PyObject*)(pyarr))
                + ": Encountered unsupported Python array");
             break;
@@ -358,7 +357,7 @@
 
       // Extract all keys and convert values. Remember whether dimensions
       // match.
-      
+
       for(octave_idx_type i = 0; i < length; i++) {
 
          std::string& key = keys[i];
@@ -369,7 +368,7 @@
          boost::python::extract<std::string> str(tuple[0]);
          if(!str.check()) {
             throw object_convert_exception(
-               string("Can not convert key of type ")
+               std::string("Can not convert key of type ")
                + PyEval_GetFuncName(boost::python::object(tuple[0]).ptr())
                + PyEval_GetFuncDesc(boost::python::object(tuple[0]).ptr())
                + " to a structure field name. Field names must be strings.");
@@ -379,7 +378,7 @@
 
          if (!valid_identifier(key)) {
             throw object_convert_exception(
-               string("Can not convert key `") + key + "' to a structure "
+               std::string("Can not convert key `") + key + "' to a structure "
                "field name. Field names must be valid Octave identifiers.");
          }
 
@@ -423,7 +422,7 @@
       extract<int> intx(py_object);
       extract<double> doublex(py_object);
       extract<Complex> complexx(py_object);
-      extract<string> stringx(py_object);
+      extract<std::string> stringx(py_object);
       extract<numeric::array> arrayx(py_object);
       extract<boost::python::list> listx(py_object);
       extract<boost::python::dict> dictx(py_object);
@@ -445,7 +444,7 @@
          throw object_convert_exception(
             PyEval_GetFuncName(py_object.ptr())
             + (PyEval_GetFuncDesc(py_object.ptr())
-               + string(": Unsupported Python object type, "
+               + std::string(": Unsupported Python object type, "
                         "cannot convert to Octave value")));
       }
    }