interface/cpp_conversion.cc: add missing includes
[isl.git] / interface / cpp_conversion.cc
blob8c8df6bdfecd4b1eace870e54187ed3199365252
1 /*
2 * Copyright 2018 Sven Verdoolaege
4 * Use of this software is governed by the MIT license
6 * Written by Sven Verdoolaege.
7 */
9 #include <stdio.h>
10 #include <map>
11 #include <string>
13 #include "cpp.h"
14 #include "cpp_conversion.h"
16 /* Print a function called "function" for converting objects of
17 * type "name" from the "from" bindings to the "to" bindings.
19 static void convert(const char *name, const char *from, const char *to,
20 const char *function)
22 printf("%s%s %s(%s%s obj) {\n", to, name, function, from, name);
23 printf("\t""return %s""manage(obj.copy());\n", to);
24 printf("}\n");
25 printf("\n");
28 /* Print functions for converting objects of "clazz"
29 * between the default and the checked C++ bindings.
31 * The conversion from default to checked is called "check".
32 * The inverse conversion is called "uncheck".
33 * For example, to "set", the following two functions are generated:
35 * checked::set check(set obj) {
36 * return checked::manage(obj.copy());
37 * }
39 * set uncheck(checked::set obj) {
40 * return manage(obj.copy());
41 * }
43 static void print(const isl_class &clazz)
45 string name = cpp_generator::type2cpp(clazz.name);
47 convert(name.c_str(), "", "checked::", "check");
48 convert(name.c_str(), "checked::", "", "uncheck");
51 /* Generate conversion functions for converting objects between
52 * the default and the checked C++ bindings.
53 * Do this for each exported class.
55 void cpp_conversion_generator::generate()
57 map<string, isl_class>::iterator ci;
59 printf("namespace isl {\n\n");
60 for (ci = classes.begin(); ci != classes.end(); ++ci)
61 print(ci->second);
62 printf("} // namespace isl\n");