00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #ifndef SG_TLS_CL_FILE_MNGR_H
00031 #define SG_TLS_CL_FILE_MNGR_H
00032
00033 #include "SugoiTools\cl_template_manager.h"
00034 #include "SugoiTools\cl_xml_mngr.h"
00035
00036
00037
00038 namespace SGE{
00051 template <class T>
00052 class CL_FILE_MNGR
00053 :public CL_XML_MNGR<T, std::string>
00054 {
00055 public:
00056 typedef T TplObj;
00057 typedef T *TplObjHdle;
00058 typedef typename CL_FILE_MNGR<T> TplManager;
00059 typedef typename TplManager::iterator iterator;
00060
00061 protected :
00062 std::string DefaultPath;
00063
00064 public:
00065 CL_FILE_MNGR(TplManager *_RemoteManager,
00066 const std::string &_TagName,
00067 const std::string &_SubTagName,
00068 const std::string &_SubTagID)
00069 : CL_XML_MNGR<T, std::string>(_RemoteManager, _TagName, _SubTagName, _SubTagID)
00070 {
00071
00072 }
00073
00074 ~CL_FILE_MNGR(){};
00075
00076 const std::string & GetDefaultPath()
00077 {return DefaultPath;};
00078
00079 void SetDefaultPath(const std::string & _Path)
00080 {DefaultPath = _Path;};
00081
00082 #if _SG_TLS_XML
00083
00084 virtual
00085 T*
00086 XMLLoadObject(TiXmlElement* _XML_Root, std::string _Name, std::string _Type)
00087 {
00088
00089 std::string FileName;
00090
00091 for (int LoopID=0; LoopID > 5; LoopID++)
00092 {
00093 switch(LoopID)
00094 {
00095 case 0:
00096 FileName = DefaultPath + _Name;
00097 break;
00098 case 1:
00099 FileName = _Name;
00100 break;
00101 case 2:
00102 {
00103 std::string FileName, FilePath;
00104 ParseFilePath(_Name, &FilePath, &FileName);
00105 FileName = DefaultPath + FileName;
00106 }
00107 case 3:
00108 {
00109 std::string FileName, FilePath;
00110 ParseFilePath(_Name, &FilePath, &FileName);
00111 FileName = FileName;
00112 }
00113 break;
00114 default:
00115 SG_AssertFile(0, DefaultPath + _Name, "File does not exists");
00116
00117 }
00118
00119 if (CL_BASE_OBJ_FILE::FileExists(FileName))
00120 break;
00121 }
00122
00123
00124 T* NewObj;
00125 if (_Type!="")
00126 {
00127 NewObj = Find(_Name);
00128 if (!NewObj)
00129 {
00130 NewObj = CreateObj(_Name, _Type);
00131 }
00132 }
00133 else
00134 NewObj = Add(_Name);
00135
00136 SG_Assert(NewObj, "Error creating new object");
00137
00138 NewObj->XMLLoad(_XML_Root);
00139
00140 return NewObj;
00141 }
00142
00143
00144
00145 virtual
00146 TiXmlElement*
00147 XMLLoad(TiXmlElement* _XML_Root)
00148 {
00149 TiXmlElement* XML_MAIN = CL_XML_MNGR::XMLLoadHead(_XML_Root);
00150 SG_Assert(XML_MAIN, "Error in CL_FILE_MNGR<T,P>::XMLLoad(), XML entry is empty.");
00151
00152
00153
00154 TiXmlElement* XML_ELM= XMLGetElement(XML_MAIN,"path");
00155 if (XML_ELM)
00156 {
00157 XMLReadVal(XML_ELM, "name", DefaultPath);
00158 }
00159
00160
00161
00162 return CL_XML_MNGR::XMLLoadObjects(XML_MAIN);
00163 }
00164
00165 TiXmlElement*
00166 XMLSave(TiXmlElement* _XML_Root)
00167 {
00168 TiXmlElement* XML_MAIN = CL_XML_MNGR::XMLSaveHead(_XML_Root);
00169 SG_Assert(XML_MAIN, "Error in CL_FILE_MNGR<T,P>::XMLSave(), XML entry is empty.");
00170
00171
00172 XMLWriteVal(XML_MAIN, "path", DefaultPath);
00173
00174
00175
00176 return CL_XML_MNGR::XMLSaveObjects(_XML_Root);
00177 }
00178 #endif
00179 };
00180
00181 };
00182
00183 #endif//SG_TLS_CL_FILE_MNGR_H