[Pkg-octave-commit] [SCM] octave-symbolic branch, master, updated. a718b53403d9f164f8c2a3df521385a01d28a11b

bluethgen bluethgen at 416fae20-06d0-4450-9b69-c6c34d4b5f03
Mon Jan 3 03:41:10 UTC 2011


The following commit has been merged in the master branch:
commit 6ad61313a501b8b585ca90f314468bd679b924e5
Author: bluethgen <bluethgen at 416fae20-06d0-4450-9b69-c6c34d4b5f03>
Date:   Sun Mar 9 12:05:12 2008 +0000

    Added to_char() and get_char() functions to mimick matlab's char() on symbolic expressions
    
    git-svn-id: https://octave.svn.sourceforge.net/svnroot/octave/trunk/octave-forge/main/symbolic@4703 416fae20-06d0-4450-9b69-c6c34d4b5f03

diff --git a/PKG_ADD b/PKG_ADD
index 15d6376..a8fe021 100644
--- a/PKG_ADD
+++ b/PKG_ADD
@@ -3,6 +3,7 @@ autoload ("sym", fullfile (fileparts (mfilename ("fullpath")), "symbols.oct"));
 autoload ("is_vpa", fullfile (fileparts (mfilename ("fullpath")), "symbols.oct"));
 autoload ("is_sym", fullfile (fileparts (mfilename ("fullpath")), "symbols.oct"));
 autoload ("is_ex", fullfile (fileparts (mfilename ("fullpath")), "symbols.oct"));
+autoload ("to_char", fullfile (fileparts (mfilename ("fullpath")), "symbols.oct"));
 autoload ("to_double", fullfile (fileparts (mfilename ("fullpath")), "symbols.oct"));
 autoload ("digits", fullfile (fileparts (mfilename ("fullpath")), "symbols.oct"));
 autoload ("Cos", fullfile (fileparts (mfilename ("fullpath")), "symbols.oct"));
diff --git a/src/symbols.cc b/src/symbols.cc
index 64eae05..f6d33ee 100644
--- a/src/symbols.cc
+++ b/src/symbols.cc
@@ -22,6 +22,8 @@ along with this program; If not, see <http://www.gnu.org/licenses/>.
 // * use GiNaC::ex_to<GiNaC::blah>(x) rather than ex_to_blah(x)
 // 2003-04-19 Willem Atsma <watsma at users.sf.net>
 // * added get_relational()
+// 2008-03-09 Nils Bluethgen <bluethgen (AT) users.sourceforge.net>
+// * added get_char() and to_char()
 
 #include <octave/config.h>
 #include <octave/defun-dld.h>
@@ -39,6 +41,8 @@ along with this program; If not, see <http://www.gnu.org/licenses/>.
 #include "ov-relational.h"
 #include "sym-ops.h"
 #include "symbols.h"
+#include <string>
+#include <sstream>
 
 bool get_expression(const octave_value arg, GiNaC::ex& expression)
 {
@@ -66,6 +70,18 @@ bool get_expression(const octave_value arg, GiNaC::ex& expression)
 
   return true;
 }
+			   
+
+bool get_char(const octave_value arg, std::string& str)
+{
+  GiNaC::ex ex;
+  if (!get_expression(arg, ex)) 
+    return false;
+  std::stringstream strstr;
+  strstr << GiNaC::dflt << ex;
+  str = strstr.str();
+  return true;
+}
 
 bool get_symbol(const octave_value arg, GiNaC::ex& sym)
 {
@@ -155,6 +171,45 @@ DEFUN_DLD(symbols,args,,"Initialize symbolic manipulation")
   return retval;
 }
 
+DEFUN_DLD(to_char,args, , 
+"-*- texinfo -*-\n\
+ at deftypefn {Loadable Function} {d =} to_char(@var{n})\n\
+\n\
+Convert a vpa, string, ex or string type to a string.\n\
+\n\
+ at end deftypefn\n\
+")
+{
+  octave_value retval;
+  int nargin = args.length();
+  std::string str;
+
+  if (nargin != 1)
+    {
+      print_usage ();
+      return retval;
+    }
+
+  try 
+    {
+      if (!get_char (args(0), str))
+	{
+	  print_usage ();
+	  return retval;
+	}
+      retval = octave_value(str);
+    }
+  catch (std::exception &e)
+    { 
+      error (e.what ());
+      retval = octave_value (); 
+    } 
+
+  return retval;
+}
+
+
+
 DEFUN_DLD(to_double,args, , 
 "-*- texinfo -*-\n\
 @deftypefn {Loadable Function} {d =} to_double(@var{n})\n\

-- 
octave-symbolic



More information about the Pkg-octave-commit mailing list