UnitManager.cpp
1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include "UnitManager.h"
#include "../Common/Toolbox.h"
using namespace TREPS::Common;
namespace TREPS
{
namespace UnitManager
{
UnitManagerClass::UnitManagerClass(void) : app(NULL), loader(NULL)
{
this->app = ApplicationClass::getInstance();
}
UnitManagerClass::~UnitManagerClass(void)
{
if (this->loader != NULL)
{
this->loader->close();
delete this->loader;
this->loader = NULL;
}
}
bool UnitManagerClass::init(const char *file_path)
{
//create xml loader
if (this->loader == NULL)
this->loader = new XMLManagerClass();
this->loader->close();
if (!this->loader->isExist(file_path))
{
LOG4CXX_INFO(this->app->getLog()->getPtr(),"Cannot find units file : " << file_path);
return false;
}
//load file
if (!this->loader->loadFile(file_path))
{
LOG4CXX_INFO(this->app->getLog()->getPtr(),"Cannot load units file : " << file_path);
return false;
}
//xsd validation
if (!this->loader->isValid(TREPS_UNITS_XSD))
{
LOG4CXX_INFO(this->app->getLog()->getPtr(),"Invalid units file : " << file_path);
return false;
}
return true;
}
}
}