Game Develop C++ Platform: XmlFilesHelper.h Source File

| Game Develop C++ Platform Platform for developing native games based on OpenGL and SFML with Game Develop

- Main Page
- Modules
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Groups Pages
XmlFilesHelper.h
Go to the documentation of this file.
1
6 #ifndef XMLFILESHELPER_H
7 #define XMLFILESHELPER_H
8
9 #include "GDCpp/tinyxml/tinyxml.h"
10 #include <string>
11 #include <boost/shared_ptr.hpp>
12 #include <map>
13
14
20 class XmlFile
21 {
22 public :
23
27 XmlFile(std::string filename) : doc(filename.c_str()), modified(false) { doc.LoadFile(); };
28
32 ~XmlFile() { if (modified) doc.SaveFile(); }
33
37 void MarkAsModified() { modified = true; }
38
42 TiXmlDocument & GetTinyXmlDocument() { return doc; };
43
47 const TiXmlDocument & GetTinyXmlDocument() const { return doc; };
48
49 private :
50 TiXmlDocument doc;
51 bool modified;
52 };
53
59 class XmlFilesManager
60 {
61 static std::map<std::string, boost::shared_ptr<XmlFile> > openedFiles;
62
63 public:
64
68 static void LoadFile(std::string filename)
69 {
70 if ( openedFiles.find(filename) == openedFiles.end() )
71 openedFiles[filename] = boost::shared_ptr<XmlFile>(new XmlFile(filename));
72 }
73
77 static void UnloadFile(std::string filename)
78 {
79 if ( openedFiles.find(filename) != openedFiles.end() )
80 openedFiles.erase(filename);
81 }
82
87 static boost::shared_ptr<XmlFile> GetFile(std::string filename, bool isGoingToModifyFile = true)
88 {
89 boost::shared_ptr<XmlFile> file = openedFiles.find(filename) != openedFiles.end() ? openedFiles[filename] : boost::shared_ptr<XmlFile>(new XmlFile(filename));
90 if ( isGoingToModifyFile ) file->MarkAsModified();
91
92 return file;
93 }
94
95
96 static std::map<std::string, boost::shared_ptr<XmlFile> > GetOpenedFilesList() { return openedFiles; }
97 };
98
99 #endif // XMLFILESHELPER_H
100