ARTS  2.2.66
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 <stdexcept>
19 #include <iostream>
20 #include "arts.h"
21 #include "matpackI.h"
22 #include "file.h"
23 #include "array.h"
24 #include "global_data.h"
25 
26 int main()
27 {
28  try
29  {
30  // Initialize the group names.
32 
33  // Make the names visible.
35 
36  ofstream ofs;
37  open_output_file(ofs,"auto_workspace.h");
38 
39  ofs << "/*! \\file auto_workspace.h\n"
40  << " \\brief Defines the enum type that acts as a\n"
41  << " handle for workspace variables groups.\n\n"
42 
43  << " Also defined here is a special pointer class that can hold\n"
44  << " a pointer to any workspace variable.\n\n"
45 
46  << " This file was generated automatically by make_auto_workspace_h.cc.\n"
47 
48  << " <b>DO NOT EDIT!</b>\n\n"
49 
50  << " \\date "
51  << __DATE__ << ", "
52  << __TIME__ << " */\n\n";
53 
54  ofs << "#ifndef auto_workspace_h\n"
55  << "#define auto_workspace_h\n\n";
56 
57  ofs << "#include <iostream>\n"
58  << "#include \"matpackII.h\"\n"
59  << "#include \"m_general.h\"\n"
60  << "#include \"supergeneric.h\"\n"
61  << "#include \"ppath.h\"\n"
62  << "#include \"gas_abs_lookup.h\"\n"
63  << "#include \"optproperties.h\"\n"
64  << "#include \"gridded_fields.h\"\n"
65  << "#include \"jacobian.h\"\n"
66  << "#include \"agenda_class.h\"\n"
67  << "#include \"mc_interp.h\"\n"
68  << "#include \"mc_antenna.h\"\n"
69  << "#include \"cia.h\"\n"
70  << "#include \"linemixingrecord.h\"\n"
71  << "\n";
72 
74  // WorkspaceMemoryHandler class
75  //
76  ofs << "class WorkspaceMemoryHandler {\n"
77  << "private:\n"
78  << " // List of function pointers to allocation routines\n"
79  << " void *(*allocfp[" << wsv_group_names.nelem () << "])();\n"
80  << " // List of function pointers to deallocation routines\n"
81  << " void (*deallocfp[" << wsv_group_names.nelem () << "])(void *);\n\n"
82  << " // List of function pointers to duplication routines\n"
83  << " void *(*duplicatefp[" << wsv_group_names.nelem () << "])(void *);\n\n"
84  << " // Allocation and deallocation routines for workspace groups\n";
85  for (Index i = 0; i < wsv_group_names.nelem (); ++i)
86  {
87  ofs << " static void *allocate_wsvg_" << wsv_group_names[i] << "()\n"
88  << " { return (void *)new " << wsv_group_names[i] << "; }\n\n"
89  << " static void deallocate_wsvg_" << wsv_group_names[i] << "(void *vp)\n"
90  << " { delete (" << wsv_group_names[i] << " *)vp; }\n\n"
91  << " static void *duplicate_wsvg_" << wsv_group_names[i] << "(void *vp)\n"
92  << " { return (new " << wsv_group_names[i] << "(*("
93  << wsv_group_names[i] << " *)vp)); }\n\n";
94  }
95 
96  ofs << "public:\n"
97  << " /** Default constructor. Initialize allocation and "
98  << "deallocation\n"
99  << " function pointer lists.\n"
100  << " */\n"
101  << " WorkspaceMemoryHandler ()\n"
102  << " {\n";
103 
104  for (Index i = 0; i < wsv_group_names.nelem (); ++i)
105  {
106  ofs << " allocfp[" << i << "] = allocate_wsvg_"
107  << wsv_group_names[i] << ";\n"
108  << " deallocfp[" << i << "] = deallocate_wsvg_"
109  << wsv_group_names[i] << ";\n"
110  << " duplicatefp[" << i << "] = duplicate_wsvg_"
111  << wsv_group_names[i] << ";\n";
112  }
113 
114  ofs << " }\n\n"
115  << " /** Getaway function to call the allocation function for the\n"
116  << " WSV group with the given Index.\n"
117  << " */\n"
118  << " void *allocate (Index wsvg)\n"
119  << " {\n"
120  << " return allocfp[wsvg]();\n"
121  << " }\n\n"
122  << " /** Getaway function to call the deallocation function for the\n"
123  << " WSV group with the given Index.\n"
124  << " */\n"
125  << " void deallocate (Index wsvg, void *vp)\n"
126  << " {\n"
127  << " deallocfp[wsvg](vp);\n"
128  << " }\n\n"
129  << " /** Getaway function to call the duplication function for the\n"
130  << " WSV group with the given Index.\n"
131  << " */\n"
132  << " void *duplicate (Index wsvg, void *vp)\n"
133  << " {\n"
134  << " return duplicatefp[wsvg](vp);\n"
135  << " }\n\n";
136 
137  ofs << "};\n\n";
138  //
140 
141 
142  ofs << "#endif // auto_workspace_h\n";
143  }
144  catch (runtime_error x)
145  {
146  cout << "Something went wrong. Message text:\n";
147  cout << x.what() << '\n';
148  return 1;
149  }
150 
151  return 0;
152 }
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:35
Index nelem() const
Number of elements.
Definition: array.h:176
This file contains basic functions to handle ASCII files.
int main()
This file contains the definition of Array.
The global header file for ARTS.
void open_output_file(ofstream &file, const String &name)
Open a file for writing.
Definition: file.cc:103
void define_wsv_group_names()
Define the array of workspace variable group names.
Definition: groups.cc:84
const ArrayOfString wsv_group_names
The names associated with Wsv groups as Strings.
Definition: global_data.h:94