comparison inst/private/generate_mf_header.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 61830a4f9ab9
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_header (typename) 21 function output = generate_mf_header (typename, label)
22 22
23 STRING ="\n\ 23 STRING ="\n\
24 #ifndef _MESHFUNCTION_@@TYPENAME@@_OCTAVE_\n\ 24 #ifndef _MESHFUNCTION_@@LABEL@@_OCTAVE_\n\
25 #define _MESHFUNCTION_@@TYPENAME@@_OCTAVE_\n\ 25 #define _MESHFUNCTION_@@LABEL@@_OCTAVE_\n\
26 \n\ 26 \n\
27 #include <dolfin.h>\n\ 27 #include <dolfin.h>\n\
28 #include <octave/oct.h>\n\ 28 #include <octave/oct.h>\n\
29 #include <fem-fenics/dolfin_compat.h>\n\ 29 #include <fem-fenics/dolfin_compat.h>\n\
30 \n\ 30 \n\
31 class meshfunction_@@TYPENAME@@ : public octave_base_value\n\ 31 class meshfunction_@@LABEL@@ : public octave_base_value\n\
32 {\n\ 32 {\n\
33 public:\n\ 33 public:\n\
34 \n\ 34 \n\
35 meshfunction_@@TYPENAME@@ (void)\n\ 35 meshfunction_@@LABEL@@ (void)\n\
36 : octave_base_value () {}\n\ 36 : octave_base_value () {}\n\
37 \n\ 37 \n\
38 meshfunction_@@TYPENAME@@ (dolfin::MeshFunction <@@TYPENAME@@> const & _mf)\n\ 38 meshfunction_@@LABEL@@ (dolfin::MeshFunction <@@TYPENAME@@ > const & _mf)\n\
39 : octave_base_value (), pmf (new dolfin::MeshFunction <@@TYPENAME@@> (_mf)) {}\n\ 39 : octave_base_value (), pmf (new dolfin::MeshFunction <@@TYPENAME@@ > (_mf)) {}\n\
40 \n\ 40 \n\
41 meshfunction_@@TYPENAME@@ (SHARED_PTR <dolfin::Mesh const> mesh,\n\ 41 meshfunction_@@LABEL@@ (SHARED_PTR <dolfin::Mesh const> mesh,\n\
42 std::string const & filename)\n\ 42 std::string const & filename)\n\
43 : octave_base_value (),\n\ 43 : octave_base_value (),\n\
44 pmf (new dolfin::MeshFunction <@@TYPENAME@@> (mesh, filename)) {}\n\ 44 pmf (new dolfin::MeshFunction <@@TYPENAME@@ > (mesh, filename)) {}\n\
45 \n\ 45 \n\
46 bool\n\ 46 bool\n\
47 is_defined (void) const\n\ 47 is_defined (void) const\n\
48 { return true; }\n\ 48 { return true; }\n\
49 \n\ 49 \n\
50 void\n\ 50 void\n\
51 print (std::ostream& os, bool pr_as_read_syntax = false) const\n\ 51 print (std::ostream& os, bool pr_as_read_syntax = false) const\n\
52 { os << ""MeshFunction <@@TYPENAME@@>: ""\n\ 52 { os << ""MeshFunction <@@TYPENAME@@ >: ""\n\
53 << get_pmf ()->str (false) << std::endl; }\n\ 53 << get_pmf ()->str (@@VERBOSE@@) << std::endl; }\n\
54 \n\ 54 \n\
55 dolfin::MeshFunction <@@TYPENAME@@> const &\n\ 55 dolfin::MeshFunction <@@TYPENAME@@ > const &\n\
56 get_mf (void) const\n\ 56 get_mf (void) const\n\
57 { return *pmf; }\n\ 57 { return *pmf; }\n\
58 \n\ 58 \n\
59 SHARED_PTR <dolfin::MeshFunction <@@TYPENAME@@> const> const &\n\ 59 SHARED_PTR <dolfin::MeshFunction <@@TYPENAME@@ > const> const &\n\
60 get_pmf (void) const\n\ 60 get_pmf (void) const\n\
61 { return pmf; }\n\ 61 { return pmf; }\n\
62 \n\ 62 \n\
63 private:\n\ 63 private:\n\
64 \n\ 64 \n\
65 SHARED_PTR <dolfin::MeshFunction <@@TYPENAME@@> const> pmf;\n\ 65 SHARED_PTR <dolfin::MeshFunction <@@TYPENAME@@ > const> pmf;\n\
66 \n\ 66 \n\
67 DECLARE_OCTAVE_ALLOCATOR;\n\ 67 DECLARE_OCTAVE_ALLOCATOR;\n\
68 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA;\n\ 68 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA;\n\
69 };\n\ 69 };\n\
70 \n\ 70 \n\
71 static bool meshfunction_@@TYPENAME@@_type_loaded = false;\n\ 71 static bool meshfunction_@@LABEL@@_type_loaded = false;\n\
72 \n\ 72 \n\
73 DEFINE_OCTAVE_ALLOCATOR (meshfunction_@@TYPENAME@@);\n\ 73 DEFINE_OCTAVE_ALLOCATOR (meshfunction_@@LABEL@@);\n\
74 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (meshfunction_@@TYPENAME@@,\n\ 74 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (meshfunction_@@LABEL@@,\n\
75 ""meshfunction_@@TYPENAME@@"", ""meshfunction_@@TYPENAME@@"");\n\ 75 ""meshfunction_@@LABEL@@"", ""meshfunction_@@LABEL@@"");\n\
76 \n\ 76 \n\
77 #endif"; 77 #endif";
78 78
79 STRING = strrep (STRING, "@@TYPENAME@@", typename); 79 STRING = strrep (STRING, "@@TYPENAME@@", typename);
80 STRING = strrep (STRING, "@@LABEL@@", label);
81 verbose = "false";
82 if (strcmp (typename, "double"))
83 verbose = "true";
84 endif
85 STRING = strrep (STRING, "@@VERBOSE@@", verbose);
80 86
81 fid = fopen (["meshfunction_", typename, ".h"], "w"); 87 fid = fopen (["meshfunction_", label, ".h"], "w");
82 if (is_valid_file_id (fid)) 88 if (is_valid_file_id (fid))
83 fputs (fid, STRING); 89 fputs (fid, STRING);
84 output = fclose (fid); 90 output = fclose (fid);
85 else 91 else
86 error ("cannot open file"); 92 error ("cannot open file");