00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include <stdexcept>
00019 #include <iostream>
00020 #include "arts.h"
00021 #include "matpackI.h"
00022 #include "file.h"
00023 #include "array.h"
00024
00025 int main()
00026 {
00027 try
00028 {
00029
00030 define_wsv_group_names();
00031
00032
00033 extern const ArrayOfString wsv_group_names;
00034
00035 ofstream ofs;
00036 open_output_file(ofs,"auto_workspace.h");
00037
00038 ofs << "/*! \\file auto_workspace.h\n"
00039 << " \\brief Defines the enum type that acts as a\n"
00040 << " handle for workspace variables groups.\n\n"
00041
00042 << " Also defined here is a special pointer class that can hold\n"
00043 << " a pointer to any workspace variable.\n\n"
00044
00045 << " This file was generated automatically by make_auto_workspace_h.cc.\n"
00046
00047 << " <b>DO NOT EDIT!</b>\n\n"
00048
00049 << " \\date "
00050 << __DATE__ << ", "
00051 << __TIME__ << " */\n\n";
00052
00053 ofs << "#ifndef auto_workspace_h\n"
00054 << "#define auto_workspace_h\n\n";
00055
00056 ofs << "#include <iostream>\n"
00057 << "#include \"matpackII.h\"\n"
00058 << "#include \"m_general.h\"\n"
00059 << "#include \"supergeneric.h\"\n"
00060 << "#include \"ppath.h\"\n"
00061 << "#include \"gas_abs_lookup.h\"\n\n"
00062 << "#include \"optproperties.h\"\n\n"
00063 << "#include \"gridded_fields.h\"\n\n"
00064 << "#include \"jacobian.h\"\n\n"
00065 << "#include \"agenda_class.h\"\n\n"
00066 << "#include \"mc_interp.h\"\n\n"
00067 << "#include \"mc_antenna.h\"\n\n";
00068
00070
00071
00072 ofs << "class WorkspaceMemoryHandler {\n"
00073 << "private:\n"
00074 << " // List of function pointers to allocation routines\n"
00075 << " void *(*allocfp[" << wsv_group_names.nelem () << "])();\n"
00076 << " // List of function pointers to deallocation routines\n"
00077 << " void (*deallocfp[" << wsv_group_names.nelem () << "])(void *);\n\n"
00078 << " // List of function pointers to duplication routines\n"
00079 << " void *(*duplicatefp[" << wsv_group_names.nelem () << "])(void *);\n\n"
00080 << " // Allocation and deallocation routines for workspace groups\n";
00081 for (Index i = 0; i < wsv_group_names.nelem (); ++i)
00082 {
00083 ofs << " static void *allocate_wsvg_" << wsv_group_names[i] << "()\n"
00084 << " { return (void *)new " << wsv_group_names[i] << "; }\n\n"
00085 << " static void deallocate_wsvg_" << wsv_group_names[i] << "(void *vp)\n"
00086 << " { delete (" << wsv_group_names[i] << " *)vp; }\n\n"
00087 << " static void *duplicate_wsvg_" << wsv_group_names[i] << "(void *vp)\n"
00088 << " { return (new " << wsv_group_names[i] << "(*("
00089 << wsv_group_names[i] << " *)vp)); }\n\n";
00090 }
00091
00092 ofs << "public:\n"
00093 << " /** Default constructor. Initialize allocation and "
00094 << "deallocation\n"
00095 << " function pointer lists.\n"
00096 << " */\n"
00097 << " WorkspaceMemoryHandler ()\n"
00098 << " {\n";
00099
00100 for (Index i = 0; i < wsv_group_names.nelem (); ++i)
00101 {
00102 ofs << " allocfp[" << i << "] = allocate_wsvg_"
00103 << wsv_group_names[i] << ";\n"
00104 << " deallocfp[" << i << "] = deallocate_wsvg_"
00105 << wsv_group_names[i] << ";\n"
00106 << " duplicatefp[" << i << "] = duplicate_wsvg_"
00107 << wsv_group_names[i] << ";\n";
00108 }
00109
00110 ofs << " }\n\n"
00111 << " /** Getaway function to call the allocation function for the\n"
00112 << " WSV group with the given Index.\n"
00113 << " */\n"
00114 << " void *allocate (Index wsvg)\n"
00115 << " {\n"
00116 << " return allocfp[wsvg]();\n"
00117 << " }\n\n"
00118 << " /** Getaway function to call the deallocation function for the\n"
00119 << " WSV group with the given Index.\n"
00120 << " */\n"
00121 << " void deallocate (Index wsvg, void *vp)\n"
00122 << " {\n"
00123 << " deallocfp[wsvg](vp);\n"
00124 << " }\n\n"
00125 << " /** Getaway function to call the duplication function for the\n"
00126 << " WSV group with the given Index.\n"
00127 << " */\n"
00128 << " void *duplicate (Index wsvg, void *vp)\n"
00129 << " {\n"
00130 << " return duplicatefp[wsvg](vp);\n"
00131 << " }\n\n";
00132
00133 ofs << "};\n\n";
00134
00136
00137
00138 ofs << "#endif // auto_workspace_h\n";
00139 }
00140 catch (runtime_error x)
00141 {
00142 cout << "Something went wrong. Message text:\n";
00143 cout << x.what() << '\n';
00144 return 1;
00145 }
00146
00147 return 0;
00148 }