ARTS  2.3.1285(git:92a29ea9-dirty)
make_auto_workspace_h.cc
Go to the documentation of this file.
1 /* Copyright (C) 2001-2012 Stefan Buehler <sbuehler@ltu.se>
2 
3  This program is free software; you can redistribute it and/or modify it
4  under the terms of the GNU General Public License as published by the
5  Free Software Foundation; either version 2, or (at your option) any
6  later version.
7 
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License
14  along with this program; if not, write to the Free Software
15  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
16  USA. */
17 
18 #include <iostream>
19 #include <stdexcept>
20 #include "array.h"
21 #include "arts.h"
22 #include "file.h"
23 #include "global_data.h"
24 #include "matpackI.h"
25 
26 int main() {
27  try {
28  // Initialize the group names.
30 
31  // Make the names visible.
33 
34  ofstream ofs;
35  open_output_file(ofs, "auto_workspace.h");
36 
37  ofs << "/*! \\file auto_workspace.h\n"
38  << " \\brief Defines the enum type that acts as a\n"
39  << " handle for workspace variables groups.\n\n"
40 
41  << " Also defined here is a special pointer class that can hold\n"
42  << " a pointer to any workspace variable.\n\n"
43 
44  << " This file was generated automatically by make_auto_workspace_h.cc.\n"
45 
46  << " <b>DO NOT EDIT!</b>\n\n"
47 
48  << " \\date " << __DATE__ << ", " << __TIME__ << " */\n\n";
49 
50  ofs << "#ifndef auto_workspace_h\n"
51  << "#define auto_workspace_h\n\n";
52 
53  ofs << "#include <iostream>\n"
54  << "#include \"matpackII.h\"\n"
55  << "#include \"m_general.h\"\n"
56  << "#include \"supergeneric.h\"\n"
57  << "#include \"artstime.h\"\n"
58  << "#include \"ppath.h\"\n"
59  << "#include \"gas_abs_lookup.h\"\n"
60  << "#include \"optproperties.h\"\n"
61  << "#include \"gridded_fields.h\"\n"
62  << "#include \"jacobian.h\"\n"
63  << "#include \"agenda_class.h\"\n"
64  << "#include \"mc_interp.h\"\n"
65  << "#include \"mc_antenna.h\"\n"
66  << "#include \"cia.h\"\n"
67  << "#include \"propagationmatrix.h\"\n"
68  << "#include \"transmissionmatrix.h\"\n"
69  << "#include \"covariance_matrix.h\"\n"
70  << "#include \"telsem.h\"\n"
71  << "#include \"tessem.h\"\n"
72  << "#include \"hitran_xsec.h\"\n"
73  << "#include \"absorptionlines.h\"\n"
74  << "\n";
75 
77  // WorkspaceMemoryHandler class
78  //
79  ofs << "class WorkspaceMemoryHandler {\n"
80  << "private:\n"
81  << " // List of function pointers to allocation routines\n"
82  << " void *(*allocfp[" << wsv_group_names.nelem() << "])();\n"
83  << " // List of function pointers to deallocation routines\n"
84  << " void (*deallocfp[" << wsv_group_names.nelem() << "])(void *);\n\n"
85  << " // List of function pointers to duplication routines\n"
86  << " void *(*duplicatefp[" << wsv_group_names.nelem()
87  << "])(void *);\n\n"
88  << " // Allocation and deallocation routines for workspace groups\n";
89  for (Index i = 0; i < wsv_group_names.nelem(); ++i) {
90  ofs << " static void *allocate_wsvg_" << wsv_group_names[i] << "()\n"
91  << " { return (void *)new " << wsv_group_names[i] << "; }\n\n"
92  << " static void deallocate_wsvg_" << wsv_group_names[i]
93  << "(void *vp)\n"
94  << " { delete (" << wsv_group_names[i] << " *)vp; }\n\n"
95  << " static void *duplicate_wsvg_" << wsv_group_names[i]
96  << "(void *vp)\n"
97  << " { return (new " << wsv_group_names[i] << "(*("
98  << wsv_group_names[i] << " *)vp)); }\n\n";
99  }
100 
101  ofs << "public:\n"
102  << " /** Default constructor. Initialize allocation and "
103  << "deallocation\n"
104  << " function pointer lists.\n"
105  << " */\n"
106  << " WorkspaceMemoryHandler ()\n"
107  << " {\n";
108 
109  for (Index i = 0; i < wsv_group_names.nelem(); ++i) {
110  ofs << " allocfp[" << i << "] = allocate_wsvg_" << wsv_group_names[i]
111  << ";\n"
112  << " deallocfp[" << i << "] = deallocate_wsvg_"
113  << wsv_group_names[i] << ";\n"
114  << " duplicatefp[" << i << "] = duplicate_wsvg_"
115  << wsv_group_names[i] << ";\n";
116  }
117 
118  ofs << " }\n\n"
119  << " /** Getaway function to call the allocation function for the\n"
120  << " WSV group with the given Index.\n"
121  << " */\n"
122  << " void *allocate (Index wsvg)\n"
123  << " {\n"
124  << " return allocfp[wsvg]();\n"
125  << " }\n\n"
126  << " /** Getaway function to call the deallocation function for the\n"
127  << " WSV group with the given Index.\n"
128  << " */\n"
129  << " void deallocate (Index wsvg, void *vp)\n"
130  << " {\n"
131  << " deallocfp[wsvg](vp);\n"
132  << " }\n\n"
133  << " /** Getaway function to call the duplication function for the\n"
134  << " WSV group with the given Index.\n"
135  << " */\n"
136  << " void *duplicate (Index wsvg, void *vp)\n"
137  << " {\n"
138  << " return duplicatefp[wsvg](vp);\n"
139  << " }\n\n";
140 
141  ofs << "};\n\n";
142  //
144 
145  ofs << "#endif // auto_workspace_h\n";
146  } catch (const std::runtime_error &x) {
147  cout << "Something went wrong. Message text:\n";
148  cout << x.what() << '\n';
149  return 1;
150  }
151 
152  return 0;
153 }
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:39
Index nelem() const
Number of elements.
Definition: array.h:194
This file contains basic functions to handle ASCII files.
int main()
This file contains the definition of Array.
The global header file for ARTS.
Implementation of Matrix, Vector, and such stuff.
void open_output_file(ofstream &file, const String &name)
Open a file for writing.
Definition: file.cc:94
void define_wsv_group_names()
Define the array of workspace variable group names.
Definition: groups.cc:77
const ArrayOfString wsv_group_names
The names associated with Wsv groups as Strings.
Definition: global_data.h:92