ARTS  1.0.222
make_auto_wsv_groups_h.cc
Go to the documentation of this file.
1 /* Copyright (C) 2001 Stefan Buehler <sbuehler@uni-bremen.de>
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 "arts.h"
20 #include "matpackI.h"
21 #include "file.h"
22 #include "array.h"
23 
24 int main()
25 {
26  try
27  {
28  // Initialize the group names.
30 
31  // Make the names visible.
32  extern const ArrayOfString wsv_group_names;
33 
34  const Index n_wsv_groups = wsv_group_names.nelem();
35 
36  ofstream ofs;
37  open_output_file(ofs,"auto_wsv_groups.h");
38 
39  ofs << "/*! \\file auto_wsv_groups.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_wsv_groups_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_wsv_groups_h\n"
55  << "#define auto_wsv_groups_h\n\n";
56 
57  ofs << "#include \"los.h\"\n"
58  << "#include \"absorption.h\"\n\n";
59 
60  ofs << "/*! This is only used for a consistency check. You can get the\n"
61  << " number of groups from wsv_group_names.nelem(). */\n"
62  << "#define N_WSV_GROUPS " << n_wsv_groups << "\n\n";
63 
64  ofs << "/*! The enum type that identifies wsv groups.\n"
65  << " This is used to group workspace variables of the same type\n"
66  << " together, so that generic methods can operate on any of them. */\n";
67 
68  ofs << "enum WsvGroup{\n";
69  // Now write the group handles one by one:
70  for (Index i=0; i<n_wsv_groups; ++i)
71  {
72  ofs << " " << wsv_group_names[i] << "_,\n";
73  }
74  ofs << "};\n\n";
75 
76 
77  // Now write the declaration of the WsvP class.
78 
79  ofs << "/*! Base class for the different Wsv pointers.\n"
80  << " This contains a virtual function for the\n"
81  << " conversion operator for each group.\n\n"
82  << " \\author Stefan Buehler */\n";
83 
84  ofs << "class WsvP {\n"
85  << "public:\n";
86  for (Index i=0; i<n_wsv_groups; ++i)
87  {
88  ofs << " virtual operator "
89  << wsv_group_names[i]
90  << "*(){safety();return NULL;};\n";
91  }
92 
93  ofs << "\nvirtual ~WsvP(){};\n";
94 
95  ofs << "\nprivate:\n";
96 
97  ofs << "/*! Safety check. This is called by all the virtual conversion\n"
98  << " operators. It just stops the program with an error message. This\n"
99  << " should never happen, because conversion should only be attempted\n"
100  << " to the correct type, for which an overloaded conversion operator\n"
101  << " exists. */\n";
102 
103  ofs << " void safety() {\n"
104  << " cerr << \"Internal error: Tried to convert a WsvP \"\n"
105  << " << \"pointer to the wrong type.\\n\";\n"
106  << " exit(1);\n"
107  << " };\n";
108 
109  ofs << "};\n\n";
110 
111 
112  ofs << "#endif // auto_wsv_groups_h\n";
113  }
114  catch (runtime_error x)
115  {
116  cout << "Something went wrong. Message text:\n";
117  cout << x.what() << '\n';
118  return 1;
119  }
120 
121  return 0;
122 }
main
int main()
Definition: make_auto_wsv_groups_h.cc:24
array.h
This file contains the definition of Array.
matpackI.h
Array< String >
wsv_group_names
ArrayOfString wsv_group_names
Definition: groups.cc:36
define_wsv_group_names
void define_wsv_group_names()
Define the array of workspace variable group names.
Definition: groups.cc:51
open_output_file
void open_output_file(ofstream &file, const String &name)
Open a file for writing.
Definition: file.cc:91
Index
INDEX Index
The type to use for all integer numbers and indices.
Definition: arts.h:153
file.h
This file contains basic functions to handle ASCII and binary (HDF) data files.
Array::nelem
Index nelem() const
Number of elements.
Definition: array.h:115
arts.h
The global header file for ARTS.