bool FileProcess::LoadLogicClass(std::string strFile) { //////////////////////////////////////////////////// tinyxml2::XMLDocument* doc = new tinyxml2::XMLDocument(); if (NULL == doc) { return false; } doc->LoadFile(strFile.c_str()); tinyxml2::XMLElement* root = doc->RootElement(); auto classElement = root->FirstChildElement("Class"); std::string strIObjectPath = classElement->Attribute("Path"); auto nodeElement = classElement->FirstChildElement(); if (nodeElement) { while (true) { std::string strID = nodeElement->Attribute("Id"); std::string sqlToWrite = "CREATE TABLE `" + strID + "` (\n"; sqlToWrite += "\t`ID` varchar(128) NOT NULL,\n"; sqlToWrite += "\tPRIMARY KEY (`ID`)\n"; sqlToWrite += ") ENGINE=InnoDB DEFAULT CHARSET=utf8;\n"; fwrite(sqlToWrite.c_str(), sqlToWrite.length(), 1, mysqlClassWriter); // 读取父节点内容 if (!LoadClass(strRelativePath + strIObjectPath, strID)) { return false; } // 读取自己节点内容 std::string strPath = nodeElement->Attribute("Path"); if (!LoadClass(strRelativePath + strPath, strID)) { return false; } fwrite("\n", 1, 1, mysqlClassWriter); if (nodeElement == classElement->LastChildElement()) { break; } nodeElement++; } } delete doc; return true; }
bool FileProcess::LoadClass(std::string strFile, std::string strTable) { tinyxml2::XMLDocument* doc = new tinyxml2::XMLDocument(); if (NULL == doc) { return false; } doc->LoadFile(strFile.c_str()); auto ff = doc->Value(); tinyxml2::XMLElement* root = doc->RootElement(); auto classElement = root->FirstChildElement("Propertys"); if (classElement) { auto nodeElement = classElement->FirstChildElement("Property"); if (nodeElement) { while (true) { if (!nodeElement || (std::string)(nodeElement->Attribute("Save")) != "1") { if (!nodeElement) { break; } nodeElement = nodeElement->NextSiblingElement(); continue; } std::string strID = nodeElement->Attribute("Id"); auto chrDesc = nodeElement->Attribute("Desc"); std::string strDesc = chrDesc; auto descLength = strlen(chrDesc); if (bConvertIntoUTF8 && IsTextUTF8(chrDesc, descLength)) { if (descLength > 0) { char* chrArrDesc = new char[descLength]; Utf8ToGbk((char*)chrDesc, chrArrDesc); strDesc = chrArrDesc; delete[] chrArrDesc; } } ////////////////////////////////////////////////////////////////////////// std::string strType = nodeElement->Attribute("Type"); std::string toWrite = ""; if (strType == "string") { toWrite = "ALTER TABLE `" + strTable + "` ADD `" + strID + "` varchar(128) DEFAULT '' COMMENT '" + strDesc + "';"; } else if (strType == "int") { toWrite = "ALTER TABLE `" + strTable + "` ADD `" + strID + "` bigint(11) DEFAULT '0' COMMENT '" + strDesc + "';"; } else if (strType == "object") { toWrite = "ALTER TABLE `" + strTable + "` ADD `" + strID + "` varchar(128) DEFAULT '' COMMENT '" + strDesc + "';"; } else if (strType == "float") { toWrite = "ALTER TABLE `" + strTable + "` ADD `" + strID + "` float(11,3) DEFAULT '0' COMMENT '" + strDesc + "';"; } else { toWrite = "ALTER TABLE `" + strTable + "` ADD `" + strID + "` varchar(128) DEFAULT '' COMMENT '" + strDesc + "';"; } toWrite += "\n"; fwrite(toWrite.c_str(), toWrite.length(), 1, mysqlWriter); if (!nodeElement) { break; } nodeElement = nodeElement->NextSiblingElement(); } } } auto xRecordsNode = root->FirstChildElement("Records"); if (xRecordsNode) { auto nodeElement = xRecordsNode->FirstChildElement("Record"); if (nodeElement) { while (true) { if (!nodeElement || (std::string)(nodeElement->Attribute("Save")) != "1") { if (!nodeElement) { break; } nodeElement = nodeElement->NextSiblingElement(); continue; } std::string strID = nodeElement->Attribute("Id"); auto chrDesc = nodeElement->Attribute("Desc"); std::string strDesc = chrDesc; auto descLength = strlen(chrDesc); if (bConvertIntoUTF8 && IsTextUTF8(chrDesc, descLength)) { if (descLength > 0) { char* chrArrDesc = new char[descLength]; Utf8ToGbk((char*)chrDesc, chrArrDesc); strDesc = chrArrDesc; delete[] chrArrDesc; } } std::string toWrite = "ALTER TABLE `" + strTable + "` ADD `" + strID + "` BLOB COMMENT '" + strDesc + "';"; toWrite += "\n"; fwrite(toWrite.c_str(), toWrite.length(), 1, mysqlWriter); if (nodeElement == classElement->LastChildElement()) { break; } nodeElement = nodeElement->NextSiblingElement(); } } } delete doc; return true; }
XMLObject* RBFFactory::create(tinyxml2::XMLElement *xml){ auto rbf = new RBFSystem(); int i = 10; for(auto c = xml->FirstChildElement() ; c != 0 ; c = c->NextSiblingElement() ) { auto n = c->Value(); if(std::strcmp(n,"TrendFunction") == 0){ rbf->_trend._c[0] = c->FloatAttribute("c0"); rbf->_trend._c[1] = c->FloatAttribute("c1"); rbf->_trend._c[2] = c->FloatAttribute("c2"); rbf->_trend._c[3] = c->FloatAttribute("c3"); }else if(std::strcmp(n,"minPosition") == 0){ rbf->_min.x = c->FloatAttribute("x"); rbf->_min.y = c->FloatAttribute("y"); rbf->_min.z = c->FloatAttribute("z"); }else if(std::strcmp(n,"maxPosition") == 0){ rbf->_max.x = c->FloatAttribute("x"); rbf->_max.y = c->FloatAttribute("y"); rbf->_max.z = c->FloatAttribute("z"); }else if(std::strcmp(n,"centers") == 0){ float x,y,z,w,a; for(auto k = c->FirstChildElement() ; k != c->LastChildElement() ; k = k->NextSiblingElement() ) { auto type = k->Value(); x = k->FloatAttribute("x"); y = k->FloatAttribute("y"); z = k->FloatAttribute("z"); w = k->FloatAttribute("weight"); if(std::strcmp(type,"ThinPlateSplineRBF") == 0){ rbf->_kernels.push_back(new ThinPlateSplineRBF(x,y,z,w)); } else if(std::strcmp(type,"Biharmonic") == 0){ rbf->_kernels.push_back(new Biharmonic(x,y,z,w)); } else if(std::strcmp(type,"Triharmonic") == 0){ rbf->_kernels.push_back(new Triharmonic(x,y,z,w)); } else if(std::strcmp(type,"GausianRBF") == 0){ a = k->FloatAttribute("a"); rbf->_kernels.push_back(new GausianRBF(x,y,z,w,a)); } else if(std::strcmp(type,"MultiQuadricRBF") == 0){ a = k->FloatAttribute("a"); rbf->_kernels.push_back(new MultiQuadricRBF(x,y,z,w,a)); } else if(std::strcmp(type,"InverseMultiQuadricRBF") == 0){ a = k->FloatAttribute("a"); rbf->_kernels.push_back(new InverseMultiQuadricRBF(x,y,z,w,a)); } } }else{ std::cerr << "Unkown xml child attribute for RBF System:" << n << std::endl; } } return rbf; }