comparison inst/private/generate_mf_constructor.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 41b76530fe5e
comparison
equal deleted inserted replaced
260:1e2a9be8083a 261:f22588ae37af
16 16
17 ## -*- texinfo -*- 17 ## -*- texinfo -*-
18 ## function for internal usage only 18 ## function for internal usage only
19 ## @end deftypefn 19 ## @end deftypefn
20 20
21 function output = generate_mf_constructor (typename) 21 function output = generate_mf_constructor (label)
22 22
23 STRING ="\n\ 23 STRING ="\n\
24 #include <dolfin.h>\n\ 24 #include <dolfin.h>\n\
25 #include <fem-fenics/mesh.h>\n\ 25 #include <fem-fenics/mesh.h>\n\
26 #include ""meshfunction_@@TYPENAME@@.h""\n\ 26 #include ""meshfunction_@@LABEL@@.h""\n\
27 #include <fem-fenics/dolfin_compat.h>\n\ 27 #include <fem-fenics/dolfin_compat.h>\n\
28 \n\ 28 \n\
29 DEFUN_DLD (MeshFunction_@@TYPENAME@@, args, nargout, ""MF = MeshFunction_@@TYPENAME@@ (MESH, FILENAME)"")\n\ 29 DEFUN_DLD (MeshFunction_@@LABEL@@, args, nargout, ""MF = MeshFunction_@@LABEL@@ (MESH, FILENAME)"")\n\
30 {\n\ 30 {\n\
31 \n\ 31 \n\
32 int nargin = args.length ();\n\ 32 int nargin = args.length ();\n\
33 octave_value retval;\n\ 33 octave_value retval;\n\
34 \n\ 34 \n\
41 mesh::register_type ();\n\ 41 mesh::register_type ();\n\
42 mesh_type_loaded = true;\n\ 42 mesh_type_loaded = true;\n\
43 mlock ();\n\ 43 mlock ();\n\
44 }\n\ 44 }\n\
45 \n\ 45 \n\
46 if (! meshfunction_@@TYPENAME@@_type_loaded)\n\ 46 if (! meshfunction_@@LABEL@@_type_loaded)\n\
47 {\n\ 47 {\n\
48 meshfunction_@@TYPENAME@@::register_type ();\n\ 48 meshfunction_@@LABEL@@::register_type ();\n\
49 meshfunction_@@TYPENAME@@_type_loaded = true;\n\ 49 meshfunction_@@LABEL@@_type_loaded = true;\n\
50 mlock ();\n\ 50 mlock ();\n\
51 }\n\ 51 }\n\
52 \n\ 52 \n\
53 if (args(0).type_id () == mesh::static_type_id ()\n\ 53 if (args(0).type_id () == mesh::static_type_id ()\n\
54 && args(1).is_string ())\n\ 54 && args(1).is_string ())\n\
62 SHARED_PTR <dolfin::Mesh const> const &\n\ 62 SHARED_PTR <dolfin::Mesh const> const &\n\
63 pmsh = msh_arg.get_pmsh ();\n\ 63 pmsh = msh_arg.get_pmsh ();\n\
64 filename += "".xdmf"";\n\ 64 filename += "".xdmf"";\n\
65 \n\ 65 \n\
66 try\n\ 66 try\n\
67 { retval = new meshfunction_@@TYPENAME@@ (pmsh, filename); }\n\ 67 { retval = new meshfunction_@@LABEL@@ (pmsh, filename); }\n\
68 catch (std::runtime_error &)\n\ 68 catch (std::runtime_error &)\n\
69 { error (""error reading file""); }\n\ 69 { error (""error reading file""); }\n\
70 }\n\ 70 }\n\
71 }\n\ 71 }\n\
72 else\n\ 72 else\n\
74 }\n\ 74 }\n\
75 \n\ 75 \n\
76 return retval;\n\ 76 return retval;\n\
77 }"; 77 }";
78 78
79 STRING = strrep (STRING, "@@TYPENAME@@", typename); 79 STRING = strrep (STRING, "@@LABEL@@", label);
80 80
81 fid = fopen (["MeshFunction_", typename, ".cc"], "w"); 81 fid = fopen (["MeshFunction_", label, ".cc"], "w");
82 if (is_valid_file_id (fid)) 82 if (is_valid_file_id (fid))
83 fputs (fid, STRING); 83 fputs (fid, STRING);
84 output = fclose (fid); 84 output = fclose (fid);
85 else 85 else
86 error ("cannot open file"); 86 error ("cannot open file");