diff inst/private/generate_mf_save.m @ 261:f22588ae37af

Improve template meshfunction implementation * inst/import_meshfunction_type.m: provide to the auxiliary functions a type name and a valid identifier * inst/private/generate_mf_*.m: add space before closing angle bracket to avoid parse errors
author Eugenio Gianniti <eugenio.gianniti@mail.polimi.it>
date Thu, 07 Aug 2014 11:13:54 +0200
parents 1e2a9be8083a
children
line wrap: on
line diff
--- a/inst/private/generate_mf_save.m	Wed Aug 06 19:52:03 2014 +0200
+++ b/inst/private/generate_mf_save.m	Thu Aug 07 11:13:54 2014 +0200
@@ -18,10 +18,10 @@
 ## function for internal usage only
 ## @end deftypefn
 
-function output = generate_mf_save (typename)
+function output = generate_mf_save (typename, label)
 
 STRING ="\n\
-#include ""meshfunction_@@TYPENAME@@.h""\n\
+#include ""meshfunction_@@LABEL@@.h""\n\
 \n\
 DEFUN_DLD (save, args, nargout, ""save (MESHFUNCTION, FILENAME)"")\n\
 {\n\
@@ -32,24 +32,24 @@
     print_usage ();\n\
   else\n\
     {\n\
-      if (! meshfunction_@@TYPENAME@@_type_loaded)\n\
+      if (! meshfunction_@@LABEL@@_type_loaded)\n\
         {\n\
-          meshfunction_@@TYPENAME@@::register_type ();\n\
-          meshfunction_@@TYPENAME@@_type_loaded = true;\n\
+          meshfunction_@@LABEL@@::register_type ();\n\
+          meshfunction_@@LABEL@@_type_loaded = true;\n\
           mlock ();\n\
         }\n\
 \n\
-      if (args(0).type_id () == meshfunction_@@TYPENAME@@::static_type_id ()\n\
+      if (args(0).type_id () == meshfunction_@@LABEL@@::static_type_id ()\n\
           && args(1).is_string ())\n\
         {\n\
-          meshfunction_@@TYPENAME@@ const & mf_arg =\n\
-            static_cast<meshfunction_@@TYPENAME@@ const &>\n\
+          meshfunction_@@LABEL@@ const & mf_arg =\n\
+            static_cast<meshfunction_@@LABEL@@ const &>\n\
             (args(0).get_rep ());\n\
           std::string str = args(1).string_value ();\n\
 \n\
           if (!error_state)\n\
             {\n\
-              dolfin::MeshFunction <@@TYPENAME@@> const &\n\
+              dolfin::MeshFunction <@@TYPENAME@@ > const &\n\
                 mf = mf_arg.get_mf ();\n\
               str += "".xdmf"";\n\
               try\n\
@@ -58,7 +58,7 @@
                   file << mf;\n\
                 }\n\
               catch (std::runtime_error &)\n\
-                { error (""error saving meshfunction@@TYPENAME@@""); }\n\
+                { error (""error saving meshfunction@@LABEL@@""); }\n\
               retval = 0;\n\
             }\n\
         }\n\
@@ -69,9 +69,10 @@
   return retval;\n\
 }";
 
-STRING =  strrep (STRING, "@@TYPENAME@@", typename);
+STRING = strrep (STRING, "@@TYPENAME@@", typename);
+STRING = strrep (STRING, "@@LABEL@@", label);
 
-fid = fopen (["save_", typename, ".cc"], "w");
+fid = fopen (["save_", label, ".cc"], "w");
 if (is_valid_file_id (fid))
   fputs (fid, STRING);
   output = fclose (fid);