VPTissue Reference Manual
XmlExporter.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2011-2016 Universiteit Antwerpen
3  *
4  * Licensed under the EUPL, Version 1.1 or as soon they will be approved by
5  * the European Commission - subsequent versions of the EUPL (the "Licence");
6  * You may not use this work except in compliance with the Licence.
7  * You may obtain a copy of the Licence at: http://ec.europa.eu/idabc/eupl5
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the Licence is distributed on an "AS IS" basis,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the Licence for the specific language governing
13  * permissions and limitations under the Licence.
14  */
20 #include "../../cpp_simptshell/exporters/XmlExporter.h"
21 
22 #include "fileformats/PTreeFile.h"
23 #include "sim/Sim.h"
24 
25 #include <fstream>
26 
27 namespace SimPT_Shell {
28 
29 using namespace std;
30 using namespace SimPT_Sim::Util;
31 using namespace SimPT_Sim;
32 
33 bool XmlExporter::Export(shared_ptr<Sim> sim, const string& file_path, bool overwrite)
34 {
35  if (!overwrite && ifstream(file_path).good()) {
36  return false; // Don't overwrite
37  }
38 
39  bool status = false;
40  try {
41  PTreeFile::WriteXml(file_path, sim->ToPtree());
42  }
43  catch(...) {
44  status = false;
45  }
46  return status;
47 }
48 
50 {
51  return "xml";
52 }
53 
54 } // namespace
STL namespace.
static bool Export(std::shared_ptr< SimPT_Sim::Sim > sim, const std::string &filename, bool overwrite=true)
Export state to xml.
Definition: XmlExporter.cpp:33
Interface for PTreeFile.
Namespace for miscellaneous utilities.
Definition: PTreeFile.cpp:44
Namespace for SimPT shell package.
Definition: Client.cpp:50
Namespace for the core simulator.
Sim, the actual simulator.
static std::string GetFileExtension()
File extension associated with this export format.
Definition: XmlExporter.cpp:49