[2] | 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" |
---|
[88] | 9 | #include "Common/include/ErrorMorpheo.h" |
---|
[124] | 10 | #include "Common/include/Filename.h" |
---|
[3] | 11 | #include <fstream> |
---|
[2] | 12 | |
---|
| 13 | namespace morpheo { |
---|
| 14 | namespace behavioural { |
---|
| 15 | |
---|
[43] | 16 | #undef FUNCTION |
---|
| 17 | #define FUNCTION "XML::generate_file" |
---|
[88] | 18 | void XML::generate_file (std::string dirname, std::string encoding) |
---|
[3] | 19 | { |
---|
[43] | 20 | log_printf(FUNC,Behavioural,FUNCTION,"Begin"); |
---|
| 21 | |
---|
[3] | 22 | header (encoding); |
---|
| 23 | |
---|
[124] | 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); |
---|
[3] | 31 | |
---|
[88] | 32 | msg_printf(INFORMATION,_("Generate file \"%s\"."),filename.c_str()); |
---|
[3] | 33 | |
---|
[71] | 34 | std::ofstream file; |
---|
[88] | 35 | file.open(filename.c_str() ,std::ios::out | std::ios::trunc); |
---|
[3] | 36 | |
---|
[88] | 37 | if (!file) |
---|
| 38 | throw ERRORMORPHEO(FUNCTION,toString(_("Error opening \"%s\" file.\n"),filename.c_str())); |
---|
| 39 | |
---|
[3] | 40 | file << get_body(); |
---|
| 41 | |
---|
| 42 | file.close(); |
---|
[43] | 43 | |
---|
| 44 | log_printf(FUNC,Behavioural,FUNCTION,"End"); |
---|
[3] | 45 | }; |
---|
| 46 | |
---|
[88] | 47 | void XML::generate_file (std::string dirname) |
---|
[2] | 48 | { |
---|
[43] | 49 | log_printf(FUNC,Behavioural,FUNCTION,"Begin"); |
---|
[88] | 50 | generate_file(dirname,"UTF-8"); |
---|
[43] | 51 | log_printf(FUNC,Behavioural,FUNCTION,"End"); |
---|
[2] | 52 | }; |
---|
| 53 | |
---|
| 54 | }; // end namespace behavioural |
---|
| 55 | }; // end namespace morpheo |
---|