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