#include "SDK.h"
class Object
{
protected:
Object() {}
public:
virtual ~Object() {}
static void Register(ClassInfo *ci);
static Object *CreateObject(std::string name);
static std::map<std::string, ClassInfo *> *classInfoMap;
};
class ClassInfo
{
public:
ClassInfo(const std::string className, ObjectConstructorFn ctor);
ClassInfo();
Object *CreateObject() const;
public:
std::string m_className;
ObjectConstructorFn m_objectConstructor;
};
std::map<std::string, ClassInfo *> *Object::classInfoMap = new std::map<std::string, ClassInfo *>();
void Object::Register(ClassInfo *ci)
{
if (NULL != ci && classInfoMap->find(ci->m_className) == classInfoMap->end())
{
classInfoMap->insert(std::map<std::string, ClassInfo *>::value_type(ci->m_className, ci));
}
}
Object *Object::CreateObject(std::string name)
{
std::map<std::string, ClassInfo *>::const_iterator iter = classInfoMap->find(name);
if (iter != classInfoMap->end())
{
return iter->second->CreateObject();
}
return NULL;
}
ClassInfo::ClassInfo(const std::string className, ObjectConstructorFn ctor) : m_className(className), m_objectConstructor(ctor)
{
Object::Register(this);
}
ClassInfo::ClassInfo()
{
}
Object *ClassInfo::CreateObject() const
{
return m_objectConstructor ? (*m_objectConstructor)() : 0;
}
class facility_target : public Object
{
DECLARE_CLASS()
public:
facility_target() {}
~facility_target() {}
public:
string name;
string type;
string createPara;
double Cartesian_X = 0.0;
double Cartesian_Y = 0.0;
double Cartesian_Z = 0.0;
double Cartesian_HighAboveGround = 0.0;
double Cylindrical_Radius = 0.0;
double Cylindrical_Longitude = 0.0;
double Cylindrical_Z = 0.0;
double Cylindrical_HighAboveGround = 0.0;
double Geocentric_Latitude = 0.0;
double Geocentric_Longitude = 0.0;
double Geocentric_Z = 0.0;
double Geocentric_HighAboveGround = 0.0;
double Geodetic_Latitude = 0.0;
double Geodetic_Longitude = 0.0;
double Geodetic_Z = 0.0;
double Geodetic_HighAboveGround = 0.0;
double Spherical_Latitude = 0.0;
double Spherical_Longitude = 0.0;
double Spherical_Z = 0.0;
double Spherical_HighAboveGround = 0.0;
};
IMPLEMENT_CLASS("facility_target", facility_target)
static Object *m_object;
static facility_target *m_facility_target;
static Object *m_aircraft;
static Object *m_groundvehicle;
static Object *m_launchvehicle;
static Object *m_ship;
static Object *m_missile;
static Object *m_sensor;
static Object *m_satellite;
void createClass()
{
XMLDocument *doc = new XMLDocument;
if (doc->LoadFile("test1.xml") != XML_SUCCESS)
{
return;
}
XMLElement *root = doc->RootElement();
XMLElement *model = root->FirstChildElement();
string strName;
string createType;
while (model)
{
const XMLAttribute *attrModel = model->FirstAttribute();
if (!strcmp(attrModel->Value(), "地面设施"))
{
m_facility_target = new facility_target;
m_facility_target->name = attrModel->Value();
}
XMLElement *attr = model->FirstChildElement();
while (attr)
{
if (!strcmp(attr->Name(), "Attributes"))
{
XMLElement *param = attr->FirstChildElement();
while(param)
{
const XMLAttribute *attrPar = param->FirstAttribute();
if(!strcmp(attrPar->Value(), "createPara"))
createType = attrPar->Next()->Value();
param = param->NextSiblingElement();
}
param = attr->FirstChildElement();
while (param)
{
const XMLAttribute *attrParam = param->FirstAttribute();
if (!strcmp(attrModel->Next()->Value(), "facility_target"))
{
if (!strcmp(attrParam->Value(), "type"))
m_facility_target->type = attrParam->Next()->Value();
if (!strcmp(attrParam->Value(), "createPara"))
m_facility_target->createPara = attrParam->Next()->Value();
if (!strcmp(attrParam->Value(), "X") && createType == "Cartesian")
m_facility_target->Cartesian_X = strtod(attrParam->Next()->Value(),NULL);
if (!strcmp(attrParam->Value(), "Y") && createType == "Cartesian")
m_facility_target->Cartesian_Y = strtod(attrParam->Next()->Value(),NULL);
if (!strcmp(attrParam->Value(), "Z") && createType == "Cartesian")
m_facility_target->Cartesian_Z = strtod(attrParam->Next()->Value(),NULL);
if (!strcmp(attrParam->Value(), "HighAboveGround") && createType == "Cartesian")
m_facility_target->Cartesian_HighAboveGround = strtod(attrParam->Next()->Value(),NULL);
if (!strcmp(attrParam->Value(), "Radius") && createType == "Cylindrical")
m_facility_target->Cylindrical_Radius = strtod(attrParam->Next()->Value(),NULL);
if (!strcmp(attrParam->Value(), "Longitude") && createType == "Cylindrical")
m_facility_target->Cylindrical_Longitude = strtod(attrParam->Next()->Value(),NULL);
if (!strcmp(attrParam->Value(), "Z") && createType == "Cylindrical")
m_facility_target->Cylindrical_Z = strtod(attrParam->Next()->Value(),NULL);
if (!strcmp(attrParam->Value(), "HighAboveGround") && createType == "Cylindrical")
m_facility_target->Cylindrical_HighAboveGround = strtod(attrParam->Next()->Value(),NULL);
if (!strcmp(attrParam->Value(), "Latitude") && createType == "Geocentric")
m_facility_target->Geocentric_Latitude = strtod(attrParam->Next()->Value(),NULL);
if (!strcmp(attrParam->Value(), "Longitude") && createType == "Geocentric")
m_facility_target->Geocentric_Longitude = strtod(attrParam->Next()->Value(),NULL);
if (!strcmp(attrParam->Value(), "Z") && createType == "Geocentric")
m_facility_target->Geocentric_Z = strtod(attrParam->Next()->Value(),NULL);
if (!strcmp(attrParam->Value(), "HighAboveGround") && createType == "Geocentric")
m_facility_target->Geocentric_HighAboveGround = strtod(attrParam->Next()->Value(),NULL);
if (!strcmp(attrParam->Value(), "Latitude") && createType == "Geodetic")
m_facility_target->Geodetic_Latitude = strtod(attrParam->Next()->Value(),NULL);
if (!strcmp(attrParam->Value(), "Longitude") && createType == "Geodetic")
m_facility_target->Geodetic_Longitude = strtod(attrParam->Next()->Value(),NULL);
if (!strcmp(attrParam->Value(), "Z") && createType == "Geodetic")
m_facility_target->Geodetic_Z = strtod(attrParam->Next()->Value(),NULL);
if (!strcmp(attrParam->Value(), "HighAboveGround") && createType == "Geodetic")
m_facility_target->Geodetic_HighAboveGround = strtod(attrParam->Next()->Value(),NULL);
if (!strcmp(attrParam->Value(), "Latitude") && createType == "Spherical")
m_facility_target->Spherical_Latitude = strtod(attrParam->Next()->Value(),NULL);
if (!strcmp(attrParam->Value(), "Longitude") && createType == "Spherical")
m_facility_target->Spherical_Longitude = strtod(attrParam->Next()->Value(),NULL);
if (!strcmp(attrParam->Value(), "Z") && createType == "Spherical")
m_facility_target->Spherical_Z = strtod(attrParam->Next()->Value(),NULL);
if (!strcmp(attrParam->Value(), "HighAboveGround") && createType == "Spherical")
m_facility_target->Spherical_HighAboveGround = strtod(attrParam->Next()->Value(),NULL);
}
param = param->NextSiblingElement();
}
}
attr = attr->NextSiblingElement();
}
model = model->NextSiblingElement();
}
}
int main()
{
createClass();
cout << m_facility_target->Cylindrical_Longitude << endl;
cout << m_facility_target->Cylindrical_HighAboveGround << endl;
cout << m_facility_target->Cylindrical_Z << endl;
cout << m_facility_target->createPara << endl;
cout << m_facility_target->Cylindrical_Radius << endl;
cout << m_facility_target->type << endl;
system("pause");
return 0;
}