1 | /* |
---|
2 | * $Id: XML_generate_file.cpp 124 2009-06-17 12:11:25Z rosiere $ |
---|
3 | * |
---|
4 | * [ Description ] |
---|
5 | * |
---|
6 | */ |
---|
7 | |
---|
8 | #include "Behavioural/include/XML.h" |
---|
9 | #include "Common/include/ErrorMorpheo.h" |
---|
10 | #include "Common/include/Filename.h" |
---|
11 | #include <fstream> |
---|
12 | |
---|
13 | namespace morpheo { |
---|
14 | namespace behavioural { |
---|
15 | |
---|
16 | #undef FUNCTION |
---|
17 | #define FUNCTION "XML::generate_file" |
---|
18 | void XML::generate_file (std::string dirname, std::string encoding) |
---|
19 | { |
---|
20 | log_printf(FUNC,Behavioural,FUNCTION,"Begin"); |
---|
21 | |
---|
22 | header (encoding); |
---|
23 | |
---|
24 | std::string filename = morpheo::filename(dirname, |
---|
25 | _name, |
---|
26 | "", |
---|
27 | _filename_extension, |
---|
28 | _simulation_file_with_date, |
---|
29 | _simulation_file_with_pid , |
---|
30 | true); |
---|
31 | |
---|
32 | msg_printf(INFORMATION,_("Generate file \"%s\"."),filename.c_str()); |
---|
33 | |
---|
34 | std::ofstream file; |
---|
35 | file.open(filename.c_str() ,std::ios::out | std::ios::trunc); |
---|
36 | |
---|
37 | if (!file) |
---|
38 | throw ERRORMORPHEO(FUNCTION,toString(_("Error opening \"%s\" file.\n"),filename.c_str())); |
---|
39 | |
---|
40 | file << get_body(); |
---|
41 | |
---|
42 | file.close(); |
---|
43 | |
---|
44 | log_printf(FUNC,Behavioural,FUNCTION,"End"); |
---|
45 | }; |
---|
46 | |
---|
47 | void XML::generate_file (std::string dirname) |
---|
48 | { |
---|
49 | log_printf(FUNC,Behavioural,FUNCTION,"Begin"); |
---|
50 | generate_file(dirname,"UTF-8"); |
---|
51 | log_printf(FUNC,Behavioural,FUNCTION,"End"); |
---|
52 | }; |
---|
53 | |
---|
54 | }; // end namespace behavioural |
---|
55 | }; // end namespace morpheo |
---|