void NeuralParametersNorm::from_XML(const tinyxml2::XMLDocument& document)
{
    const tinyxml2::XMLElement* root_element = document.FirstChildElement("NeuralParametersNorm");

    if(!root_element)
    {
        std::ostringstream buffer;

        buffer << "OpenNN Exception: NeuralParametersNorm class.\n"
               << "void from_XML(const tinyxml2::XMLDocument&) method.\n"
               << "Neural parameters norm element is NULL.\n";

        throw std::logic_error(buffer.str());
    }

  // Neural parameters norm weight
  {
     const tinyxml2::XMLElement* element = root_element->FirstChildElement("NeuralParametersNormWeight");

     if(element)
     {
        try
        {
           const double new_neural_parameters_norm_weight = atof(element->GetText());

           set_neural_parameters_norm_weight(new_neural_parameters_norm_weight);
        }
        catch(const std::logic_error& e)
        {
           std::cout << e.what() << std::endl;
        }
     }
  }

  // Display
  {
     const tinyxml2::XMLElement* element = root_element->FirstChildElement("Display");

     if(element)
     {
        try
        {
           const std::string new_display_string = element->GetText();

           set_display(new_display_string != "0");
        }
        catch(const std::logic_error& e)
        {
           std::cout << e.what() << std::endl;
        }
     }
  }
}
Ejemplo n.º 2
0
	/**
	*	@brief This is the default constructor for the XMLLoader. This sets up the root
	*	node and initalises the tinyxml2::XMLElement to start on the first save slot 
	*/
	XMLLoader(){
		string path = "Assets/save_data";
		string ext = ".sav";
		ext = ".xml";
		string result = path + ext;

		//xmlDoc.LoadFile(result.c_str());

		//Why does this load the old save_data all the time
		if(xmlDoc.LoadFile(result.c_str()) == tinyxml2::XML_ERROR_FILE_NOT_FOUND)
			GenerateSaveFile();
		
		tinyxml2::XMLNode *pRoot = xmlDoc.FirstChild();
		//cout << string_to_int(s) << endl;
		
		saveGame = pRoot->FirstChildElement("SaveGame");
		if (saveGame == nullptr) throw tinyxml2::XML_ERROR_FILE_READ_ERROR;

		
		loadSaveSlots();
		/*
		tinyxml2::XMLElement * slot = saveGame->FirstChildElement("SaveSlot1");
		if (slot == nullptr) throw tinyxml2::XML_ERROR_FILE_READ_ERROR;

		tinyxml2::XMLElement * level = slot->FirstChildElement("Levels");
		if (level == nullptr) throw tinyxml2::XML_ERROR_FILE_READ_ERROR;

		tinyxml2::XMLElement * level_bool = level->FirstChildElement("LVL3");
		if (level_bool == nullptr) throw tinyxml2::XML_ERROR_FILE_READ_ERROR;
		string l_data = level_bool->GetText();
		cout << string_to_int(l_data) << endl;
		*/
		/*
		loadSaveSlots();
		*/
		/*
		const string image_ext = texture->Attribute("EXT");
		const string file_name = image_name + '.' + image_ext;*/
	}
Ejemplo n.º 3
0
/** Unfortunately, TinyXML2 does not provide good ways of reporting XML parsing
 * errors.  We could try to use GetErrorStr1() and GetErrorStr2(), but those
 * just return pointers to parts of the document, and it is not OK to print
 * parts of the document without carefully escaping special characters in it,
 * which is probably not worthwhile. */
static void throwIfError(const tinyxml2::XMLDocument & doc)
{
    if(!doc.Error()) { return; }

    std::string msg("XML error.");

    // doc.ErrorName is not available in Ubuntu's libtinyxml2-dev/trusty-backports package
    // (2.1.0).  But it would be nice to use it eventually once everyone has upgraded:
    // std::string msg("XML error: ");
    // msg += doc.ErrorName();
    // msg += ".";
    throw std::runtime_error(msg);
}
Ejemplo n.º 4
0
void funcPrintDifferenceinSequence(structRna xRna[], const bool* boolDifferenceFlag, const int iNumberofInput)
{
	//tinyxml2::XMLNode* pTextElementRef = HTML_Document.NewElement("FONT");
	funcEndline();
/*	pTextElementRef->InsertEndChild( HTML_Document.NewText("Map : Asterisks for difference sequences"));
	funcEndline();
	for(int xCurrentPos = 0 ; xCurrentPos < xRna[0].sSequenceBetweenCDS.size() ; ++xCurrentPos ){
		if(boolDifferenceFlag[xCurrentPos] == true)
		{
			tinyxml2::XMLNode* pTextElementRef = HTML_Document.NewText("*");

			pNOBRElementRef->InsertEndChild(pTextElementRef);
		}else 
		{
			tinyxml2::XMLNode* pTextElementRef = HTML_Document.NewText("&nbsp;&nbsp;");

			pNOBRElementRef->InsertEndChild(pTextElementRef);
		};
	}
	funcEndline();

	pNOBRElementRef->InsertEndChild(pTextElementRef);
	funcEndline();
*/	for(int xToPrint=0; xToPrint < iNumberofInput; ++xToPrint){
		for(int xCurrentPos=0 ; xCurrentPos < xRna[0].sSequenceBetweenCDS.size() ; ++xCurrentPos){
			tinyxml2::XMLNode* pTextElementRef = HTML_Document.NewElement("FONT");

			std::string tempChar;
			tempChar = xRna[xToPrint].sSequenceBetweenCDS[xCurrentPos];
			pTextElementRef->InsertEndChild(HTML_Document.NewText(tempChar.c_str() ));
			pTextElementRef->ToElement()->SetAttribute("color", (boolDifferenceFlag[xCurrentPos]) ? "red" : "black");

			pNOBRElementRef->InsertEndChild(pTextElementRef);
		}
		funcEndline();
	}


}
Ejemplo n.º 5
0
	// прочитать группу Тегов c Загруженного файла XML
	// "локация тегов" - вектор "вглубь" структуры
	vector<string> rd_Xml_tags_Txt_reader::get_Tags_Txt__From_Xml_Doc(
		tinyxml2::XMLDocument& doc, const vector<const char*>& location, const char* tag)
	{
		vector<string> vTxt;
		unsigned loc_Sze = location.size();

		tinyxml2::XMLElement* ptEl_location;
		tinyxml2::XMLElement* ptEl;
		tinyxml2::XMLElement* ptEl_last;

		if(loc_Sze)
		{
			ptEl_location = doc.FirstChildElement(location[0]);
			for(unsigned n = 1; n < loc_Sze; n++)
			{
				ptEl_location = ptEl_location->FirstChildElement(location[n]);
			}
			ptEl = ptEl_location->FirstChildElement(tag);
			ptEl_last = ptEl_location->LastChildElement(tag);
		}
		else
		{
			ptEl = doc.FirstChildElement(tag);
			ptEl_last = doc.LastChildElement(tag);
		}

		const char* data;
		for(; ptEl; ptEl = ptEl->NextSiblingElement())
		{
			data = ptEl->GetText();
			if(data) vTxt.push_back( data );
			else vTxt.push_back( string() );
			if(ptEl == ptEl_last) break;
		}

		vTxt.shrink_to_fit();
		return vTxt;
	}
Ejemplo n.º 6
0
static tinyxml2::XMLError LoadFile(tinyxml2::XMLDocument &doc, const std::string &path)
{
    FILE *f = fopen(path.c_str(),"rb");
    if (!f)
        return tinyxml2::XML_ERROR_FILE_NOT_FOUND;

    // is file ok? if "path" is a folder then reading from it will cause ferror() to return a non-zero value
    fgetc(f);
    int errorcode = ferror(f);
    fclose(f);

    // if file is ok, try to load it
    return (errorcode == 0) ? doc.LoadFile(path.c_str()) : tinyxml2::XML_ERROR_FILE_NOT_FOUND;
}
int parseDoc()
{
	XMLNode * root = doc.FirstChild();
	if(root == nullptr)
	{
		return XML_ERROR_FILE_READ_ERROR;
	}
	XMLElement * tuixml = root->FirstChildElement("tuixml");
	if(tuixml == nullptr)
	{
		return XML_ERROR_PARSING_ELEMENT;
	}
	XMLElement * temp = tuixml->FirstChildElement();
	layers.push_back(layer);
	createElementLayers(temp);
}
Ejemplo n.º 8
0
bool
Inventory::_WriteProlog(tinyxml2::XMLDocument& document) const
{
	Configuration* config = Configuration::Get();

	tinyxml2::XMLDeclaration* declaration = document.NewDeclaration();
	document.LinkEndChild(declaration);
	tinyxml2::XMLElement* request = document.NewElement("REQUEST");
	document.LinkEndChild(request);
	tinyxml2::XMLElement* deviceID = document.NewElement("DEVICEID");
	deviceID->LinkEndChild(document.NewText(config->DeviceID().c_str()));
	request->LinkEndChild(deviceID);
	tinyxml2::XMLElement* query = document.NewElement("QUERY");
	query->LinkEndChild(document.NewText("PROLOG"));
	request->LinkEndChild(query);

	return true;
}
Ejemplo n.º 9
0
// Загрузка данных в XML документ.
XMLError MainWindow::LoadXMLFromFile(QString& a_StrPath, tinyxml2::XMLDocument& a_xmlDoc)
{
    DialogFileError we;
    XMLError eErrOut;
    //
    eErrOut = XMLCheckResult(a_xmlDoc.LoadFile(a_StrPath.toStdString().c_str()));
    if(eErrOut)
    {
        LOG(LOG_CAT_W, "File error: " << a_StrPath.toStdString());
        we.exec();
    }
    else
    {
        LOG(LOG_CAT_I, "File loaded: " << a_StrPath.toStdString());
    }
    return eErrOut;
}
Ejemplo n.º 10
0
static void openXMLFile(tinyxml2::XMLDocument & doc, const char* const filename)
{
	int const result = doc.LoadFile(filename);
	switch(result)
	{
		case tinyxml2::XML_SUCCESS:
			break;
		case tinyxml2::XML_ERROR_FILE_NOT_FOUND:
			throw std::runtime_error("File not found");
		case tinyxml2::XML_ERROR_FILE_COULD_NOT_BE_OPENED:
			throw std::runtime_error("File not found");
		default:
		{
			std::ostringstream oss;
			oss << "Parse error = " << result;
			throw std::runtime_error(oss.str());
		}
	};
}
Ejemplo n.º 11
0
Archivo: Mz.cpp Proyecto: cpzhang/zen
void addTextureStageState(tinyxml2::XMLDocument& doc, tinyxml2::XMLElement* ele, u32 stage, D3DTEXTURESTAGESTATETYPE tp, u32 vl)
{
	DWORD va = 0;
	if (tp == D3DTSS_COLOROP)
	{
		if (stage == 0)
		{
			va = D3DTOP_MODULATE;
		} 
		else
		{
			va = D3DTOP_DISABLE;
		}
	}
	else if (tp == D3DTSS_ALPHAOP)
	{
		if (stage == 0)
		{
			va = D3DTOP_SELECTARG1;
		} 
		else
		{
			va = D3DTOP_DISABLE;
		}
	}
	else if(tp == D3DTSS_TEXCOORDINDEX)
	{
		va = stage;
	}
	else
	{
		va = Material::tTextureStageStateDefault_[tp];
	}
	if(va != vl)
	{
		tinyxml2::XMLElement* a = doc.NewElement("TextureStageState");
		a->SetAttribute("stage", stage);
		a->SetAttribute("type", tp);
		a->SetAttribute("value", vl);
		ele->LinkEndChild(a);
	}
}
Ejemplo n.º 12
0
void TileMap::load(tinyxml2::XMLDocument & doc)
{
	std::string data;
	tinyxml2::XMLElement * element = doc.FirstChildElement("map");
	element->FirstChildElement("width")->QueryIntText(&m_width);
	element->FirstChildElement("height")->QueryIntText(&m_height);
	element->FirstChildElement("tile_size")->QueryIntText(&m_tileSize);
	data = element->FirstChildElement("data")->GetText();
	std::cout << "width: " << m_width << " height: " << m_height << "\n";


	std::istringstream ss(data);
	std::string token;
	while (std::getline(ss, token, ','))
	{
		if (m_tiles.size() == 0 || m_tiles.back().size() >= static_cast<unsigned>(m_width))
			m_tiles.emplace_back();
		m_tiles.back().push_back(std::stoi(token));
	}
}
Ejemplo n.º 13
0
void RegularizationTerm::from_XML(const tinyxml2::XMLDocument& document)
{
    // Display warnings

    const tinyxml2::XMLElement* display_element = document.FirstChildElement("Display");

    if(display_element)
    {
        std::string new_display_string = display_element->GetText();

        try
        {
            set_display(new_display_string != "0");
        }
        catch(const std::logic_error& e)
        {
            std::cout << e.what() << std::endl;
        }
    }
}
Ejemplo n.º 14
0
void Sphere::Serialization( tinyxml2::XMLDocument& xmlDoc , tinyxml2::XMLElement* pRootElement )
{
	{
		pRootElement->SetAttribute( "type" , GetName() );
	}

	{
		pRootElement->SetAttribute( "radius" , m_Radius );
	}

	{
		char* pText = new char[50];
		sprintf( pText , "%f,%f,%f" , mWorldPos.x , mWorldPos.y , mWorldPos.z );

		tinyxml2::XMLElement* pTransformElement = xmlDoc.NewElement( "transform" );

		pTransformElement->SetAttribute( "position" , pText );

		pRootElement->InsertEndChild( pTransformElement );

		SAFE_DELETE( pText );
	}
}
Ejemplo n.º 15
0
void openXMLFile(
  tinyxml2::XMLDocument& doc, const char* const filename,
  const common::ResourceRetrieverPtr& _retriever)
{
    common::ResourceRetrieverPtr retriever;
    if(_retriever)
      retriever = _retriever;
    else
      retriever = std::make_shared<common::LocalResourceRetriever>();

    const common::ResourcePtr resource = retriever->retrieve(filename);
    if(!resource)
    {
      dtwarn << "[openXMLFile] Failed opening URI '"
             << filename << "'.\n";
      throw std::runtime_error("Failed opening URI.");
    }

    // C++11 guarantees that std::string has contiguous storage.
    const size_t size = resource->getSize();
    std::string content;
    content.resize(size);
    if(resource->read(&content.front(), size, 1) != 1)
    {
      dtwarn << "[openXMLFile] Failed reading from URI '"
             << filename << "'.\n";
      throw std::runtime_error("Failed reading from URI.");
    }

    int const result = doc.Parse(&content.front());
    if(result != tinyxml2::XML_SUCCESS)
    {
      dtwarn << "[openXMLFile] Failed parsing XML: TinyXML2 returned error"
                " code " << result << ".\n";
      throw std::runtime_error("Failed parsing XML.");
    }
}
void KappaCoefficientOptimizationThreshold::from_XML(const tinyxml2::XMLDocument& document)
{
    const tinyxml2::XMLElement* root_element = document.FirstChildElement("KappaCoefficientOptimizationThreshold");

    if(!root_element)
    {
        std::ostringstream buffer;

        buffer << "OpenNN Exception: KappaCoefficientOptimizationThreshold class.\n"
               << "void from_XML(const tinyxml2::XMLDocument&) method.\n"
               << "KappaCoefficientOptimizationThreshold element is NULL.\n";

        throw std::logic_error(buffer.str());
    }

    // Minimum threshold
    {
        const tinyxml2::XMLElement* element = root_element->FirstChildElement("MinimumThreshold");

        if(element)
        {
           const double new_minimum_threshold = atof(element->GetText());

           try
           {
              set_minimum_threshold(new_minimum_threshold);
           }
           catch(const std::logic_error& e)
           {
              std::cout << e.what() << std::endl;
           }
        }
    }

    // Maximum threshold
    {
        const tinyxml2::XMLElement* element = root_element->FirstChildElement("MaximumThreshold");

        if(element)
        {
           const double new_maximum_threshold = atof(element->GetText());

           try
           {
              set_maximum_threshold(new_maximum_threshold);
           }
           catch(const std::logic_error& e)
           {
              std::cout << e.what() << std::endl;
           }
        }
    }

    // Step
    {
        const tinyxml2::XMLElement* element = root_element->FirstChildElement("Step");

        if(element)
        {
           const double new_step = atof(element->GetText());

           try
           {
              set_step(new_step);
           }
           catch(const std::logic_error& e)
           {
              std::cout << e.what() << std::endl;
           }
        }
    }

    // Reserve function data
    {
        const tinyxml2::XMLElement* element = root_element->FirstChildElement("ReserveFunctionData");

        if(element)
        {
            const std::string new_reserve_function_data = element->GetText();

            try
            {
                set_reserve_function_data(new_reserve_function_data != "0");
            }
            catch(const std::logic_error& e)
            {
               std::cout << e.what() << std::endl;
            }
        }
    }

    // Display
//    {
//        const tinyxml2::XMLElement* element = root_element->FirstChildElement("Display");

//        if(element)
//        {
//           const std::string new_display = element->GetText();

//           try
//           {
//              set_display(new_display != "0");
//           }
//           catch(const std::logic_error& e)
//           {
//              std::cout << e.what() << std::endl;
//           }
//        }
//    }

}
Ejemplo n.º 17
0
void ProbabilisticLayer::from_XML(const tinyxml2::XMLDocument& document)
{
    std::ostringstream buffer;

    const tinyxml2::XMLElement* probabilistic_layer_element = document.FirstChildElement("ProbabilisticLayer");

    if(!probabilistic_layer_element)
    {
        buffer << "OpenNN Exception: ProbabilisticLayer class.\n"
               << "void from_XML(const tinyxml2::XMLDocument&) method.\n"
               << "Probabilistic layer element is NULL.\n";

        throw std::logic_error(buffer.str());
    }

  // Probabilistic neurons number
  {
     const tinyxml2::XMLElement* element = probabilistic_layer_element->FirstChildElement("ProbabilisticNeuronsNumber");

     if(element)
     {
        const char* text = element->GetText();

        if(text)
        {
           try
           {
              set_probabilistic_neurons_number(atoi(text));
           }
           catch(const std::logic_error& e)
           {
              std::cout << e.what() << std::endl;
           }
        }
     }
  }

  // Probabilistic method
  {
     const tinyxml2::XMLElement* element = probabilistic_layer_element->FirstChildElement("ProbabilisticMethod");

     if(element)
     {
        const char* text = element->GetText();

        if(text)
        {
           try
           {
              std::string new_probabilistic_method(text);

              set_probabilistic_method(new_probabilistic_method);
           }
           catch(const std::logic_error& e)
           {
              std::cout << e.what() << std::endl;
           }
        }
     }
  }

    // Decision threshold
    {
       const tinyxml2::XMLElement* element = probabilistic_layer_element->FirstChildElement("DecisionThreshold");

       if(element)
       {
          const char* text = element->GetText();

          if(text)
          {
             try
             {
                  set_decision_threshold(atof(text));
             }
             catch(const std::logic_error& e)
             {
                std::cout << e.what() << std::endl;
             }
          }
       }
    }

  // Display
  {
     const tinyxml2::XMLElement* display_element = probabilistic_layer_element->FirstChildElement("Display");

     if(display_element)
     {
        std::string new_display_string = display_element->GetText();

        try
        {
           set_display(new_display_string != "0");
        }
        catch(const std::logic_error& e)
        {
           std::cout << e.what() << std::endl;
        }
     }
  }
}
Ejemplo n.º 18
0
void BoundingLayer::from_XML(const tinyxml2::XMLDocument& document)
{
      // Control sentence 
//      {
//         const char* text = bounding_layer_element->GetText();     

//         const std::string string(text);

//         if(string != "BoundingLayer")
//         {
//            std::ostringstream buffer;

//            buffer << "OpenNN Exception: BoundingLayer class.\n" 
//                   << "void from_XML(const tinyxml2::XMLDocument&) method.\n"
//                   << "Unkown root element: " << text << ".\n";

//   	        throw std::logic_error(buffer.str());
//         }
//      }

  // Lower bounds
  {
     const tinyxml2::XMLElement* lower_bounds_element = document.FirstChildElement("LowerBounds");

     if(lower_bounds_element)
     {
        const char* lower_bounds_text = lower_bounds_element->GetText();

        if(lower_bounds_text)
        {
           Vector<double> new_lower_bounds;
           new_lower_bounds.parse(lower_bounds_text);

           try
           {
              set_lower_bounds(new_lower_bounds);
           }
           catch(const std::logic_error& e)
           {
              std::cout << e.what() << std::endl;
           }
        }
     }
  }

  // Upper bounds
  {
     const tinyxml2::XMLElement* upper_bounds_element = document.FirstChildElement("UpperBounds");

     if(upper_bounds_element)
     {
        const char* upper_bounds_text = upper_bounds_element->GetText();

        if(upper_bounds_text)
        {
           Vector<double> new_upper_bounds;
           new_upper_bounds.parse(upper_bounds_text);

           try
           {
              set_upper_bounds(new_upper_bounds);
           }
           catch(const std::logic_error& e)
           {
              std::cout << e.what() << std::endl;
           }
        }
     }
  }

  // Display
  {
     const tinyxml2::XMLElement* display_element = document.FirstChildElement("Display");

     if(display_element)
     {
        std::string new_display_string = display_element->GetText();

        try
        {
           set_display(new_display_string != "0");
        }
        catch(const std::logic_error& e)
        {
           std::cout << e.what() << std::endl;
        }
     }
  }
}
Ejemplo n.º 19
0
	/**
	*	@brief This generates a new saveData.xml for the game insertting all the approprate
	*	formatting for reading later.
	*	@see SaveSlot
	*/
	void GenerateSaveFile(){
		cLog::inst()->print(3, "XML Loader", "Generating new save_data.xml");

		//create and insert the root node of the .xml document
		tinyxml2::XMLNode *pRoot = xmlDoc.NewElement("Root");
		xmlDoc.InsertFirstChild(pRoot);

		tinyxml2::XMLElement *saveGame = xmlDoc.NewElement("SaveGame");
		for (int i = 0; i < 3; i++)
		{
			string d = "SaveSlot" + std::to_string(i + 1);
			const char * c = d.c_str();
			tinyxml2::XMLElement * saveSlot = xmlDoc.NewElement(c);

			//Inserts IntValue to the .xml file
			tinyxml2::XMLElement * pElement = xmlDoc.NewElement("TimePlayed");
			pElement->SetText(0);
			saveSlot->InsertEndChild(pElement);

			pElement = xmlDoc.NewElement("CurrentGold");
			pElement->SetText(0);
			saveSlot->InsertEndChild(pElement);

			pElement = xmlDoc.NewElement("Levels");
			for (int i = 0; i < 7; i++)
			{
				string d = "LVL" + std::to_string(i + 1);
				const char * c = d.c_str();
				tinyxml2::XMLElement * pListElement = xmlDoc.NewElement(c);
				pListElement->SetText(1);

				pElement->InsertEndChild(pListElement);
			}

			saveSlot->InsertEndChild(pElement);

			//Insert Achievement Tracking into the saveData.sav
			pElement = xmlDoc.NewElement("Achievements");
			for (int i = 0; i < 21; i++)
			{
				string d = "ACH" + std::to_string(i + 1);
				const char * c = d.c_str();
				tinyxml2::XMLElement * pListElement = xmlDoc.NewElement(c);
				pListElement->SetText(0);

				pElement->InsertEndChild(pListElement);
			}

			saveSlot->InsertEndChild(pElement);

			//Insert Stat Tracking into the saveData.sav
			pElement = xmlDoc.NewElement("Statistics");
			for (int i = 0; i < 10; i++)
			{
				string d = "STAT" + std::to_string(i + 1);
				const char * c = d.c_str();
				tinyxml2::XMLElement * pListElement = xmlDoc.NewElement(c);
				pListElement->SetText(0);

				pElement->InsertEndChild(pListElement);
			}

			saveSlot->InsertEndChild(pElement);

			saveGame->InsertEndChild(saveSlot);
		}
		pRoot->InsertEndChild(saveGame);

		tinyxml2::XMLError eResult = xmlDoc.SaveFile("Assets/save_data.xml");

	}
Ejemplo n.º 20
0
bool Library::load(const tinyxml2::XMLDocument &doc)
{
    const tinyxml2::XMLElement * const rootnode = doc.FirstChildElement();

    if (rootnode == NULL)
        return false;

    if (strcmp(rootnode->Name(),"def") != 0)
        return false;

    for (const tinyxml2::XMLElement *node = rootnode->FirstChildElement(); node; node = node->NextSiblingElement()) {
        if (strcmp(node->Name(),"memory")==0 || strcmp(node->Name(),"resource")==0) {
            if (strcmp(node->Name(), "memory")==0)
                while (!ismemory(++allocid));
            else
                while (!isresource(++allocid));
            for (const tinyxml2::XMLElement *memorynode = node->FirstChildElement(); memorynode; memorynode = memorynode->NextSiblingElement()) {
                if (strcmp(memorynode->Name(),"alloc")==0) {
                    _alloc[memorynode->GetText()] = allocid;
                    const char *init = memorynode->Attribute("init");
                    if (init && strcmp(init,"false")==0) {
                        returnuninitdata.insert(memorynode->GetText());
                    }
                } else if (strcmp(memorynode->Name(),"dealloc")==0)
                    _dealloc[memorynode->GetText()] = allocid;
                else if (strcmp(memorynode->Name(),"use")==0)
                    use.insert(memorynode->GetText());
                else
                    return false;
            }
        }

        else if (strcmp(node->Name(),"function")==0) {
            const char *name = node->Attribute("name");
            if (name == NULL)
                return false;

            for (const tinyxml2::XMLElement *functionnode = node->FirstChildElement(); functionnode; functionnode = functionnode->NextSiblingElement()) {
                if (strcmp(functionnode->Name(),"noreturn")==0)
                    _noreturn[name] = (strcmp(functionnode->GetText(), "true") == 0);
                else if (strcmp(functionnode->Name(),"leak-ignore")==0)
                    leakignore.insert(name);
                else if (strcmp(functionnode->Name(), "arg") == 0 && functionnode->Attribute("nr") != NULL) {
                    const int nr = atoi(functionnode->Attribute("nr"));
                    bool notnull = false;
                    bool notuninit = false;
                    bool formatstr = false;
                    bool strz = false;
                    for (const tinyxml2::XMLElement *argnode = functionnode->FirstChildElement(); argnode; argnode = argnode->NextSiblingElement()) {
                        if (strcmp(argnode->Name(), "not-null") == 0)
                            notnull = true;
                        else if (strcmp(argnode->Name(), "not-uninit") == 0)
                            notuninit = true;
                        else if (strcmp(argnode->Name(), "formatstr") == 0)
                            formatstr = true;
                        else if (strcmp(argnode->Name(), "strz") == 0)
                            strz = true;
                        else
                            return false;
                    }
                    argumentChecks[name][nr].notnull = notnull;
                    argumentChecks[name][nr].notuninit = notuninit;
                    argumentChecks[name][nr].formatstr = formatstr;
                    argumentChecks[name][nr].strz = strz;
                } else if (strcmp(functionnode->Name(), "ignorefunction") == 0) {
                    _ignorefunction[name] = (strcmp(functionnode->GetText(), "true") == 0);
                } else
                    return false;
            }
        }

        else if (strcmp(node->Name(),"files")==0) {
            for (const tinyxml2::XMLElement *functionnode = node->FirstChildElement(); functionnode; functionnode = functionnode->NextSiblingElement()) {
                if (strcmp(functionnode->Name(), "file") == 0) {
                    _markupExtensions.insert(functionnode->Attribute("ext"));
                    const char * report = functionnode->Attribute("reporterrors");
                    if (report)
                        _reporterrors[functionnode->Attribute("ext")] = strcmp(report, "true")==0;
                } else
                    return false;
            }
        }

        else if (strcmp(node->Name(), "keywords") == 0) {
            for (const tinyxml2::XMLElement *functionnode = node->FirstChildElement(); functionnode; functionnode = functionnode->NextSiblingElement()) {
                if (strcmp(functionnode->Name(), "library") == 0) {
                    const char * const extension = functionnode->Attribute("extension");
                    for (const tinyxml2::XMLElement *librarynode = functionnode->FirstChildElement(); librarynode; librarynode = librarynode->NextSiblingElement()) {
                        if (strcmp(librarynode->Name(), "keyword") == 0) {
                            _keywords[extension].push_back(librarynode->Attribute("name"));
                        } else
                            return false;
                    }
                } else
                    return false;
            }
        }

        else if (strcmp(node->Name(), "exported") == 0) {
            for (const tinyxml2::XMLElement *functionnode = node->FirstChildElement(); functionnode; functionnode = functionnode->NextSiblingElement()) {
                if (strcmp(functionnode->Name(), "exporter") == 0) {
                    const char * prefix = (functionnode->Attribute("prefix"));
                    if (!prefix)
                        return false;

                    for (const tinyxml2::XMLElement *enode = functionnode->FirstChildElement(); enode; enode = enode->NextSiblingElement()) {
                        if (strcmp(enode->Name(), "prefix") == 0) {
                            _exporters[prefix].addPrefix(enode->Attribute("name"));
                        } else if (strcmp(enode->Name(), "suffix") == 0) {
                            _exporters[prefix].addSuffix(enode->Attribute("name"));
                        } else
                            return false;
                    }
                } else
                    return false;
            }
        }

        else if (strcmp(node->Name(), "imported") == 0) {
            for (const tinyxml2::XMLElement *functionnode = node->FirstChildElement(); functionnode; functionnode = functionnode->NextSiblingElement()) {
                if (strcmp(functionnode->Name(), "library") == 0) {
                    const char * const extension = functionnode->Attribute("extension");
                    for (const tinyxml2::XMLElement *librarynode = functionnode->FirstChildElement(); librarynode; librarynode = librarynode->NextSiblingElement()) {
                        if (strcmp(librarynode->Name(), "importer") == 0) {
                            _importers[extension].push_back(librarynode->Attribute("name"));
                        } else
                            return false;
                    }
                }
            }
        }

        else if (strcmp(node->Name(), "reflection") == 0) {
            for (const tinyxml2::XMLElement *functionnode = node->FirstChildElement(); functionnode; functionnode = functionnode->NextSiblingElement()) {
                if (strcmp(functionnode->Name(), "library") == 0) {
                    const char * const extension = functionnode->Attribute("extension");
                    for (const tinyxml2::XMLElement *librarynode = functionnode->FirstChildElement(); librarynode; librarynode = librarynode->NextSiblingElement()) {
                        if (strcmp(librarynode->Name(), "call") == 0) {
                            const char * const argString = librarynode->Attribute("arg");
                            if (argString) {
                                _reflection[extension][librarynode->Attribute("name")]
                                    = atoi(argString);
                            }
                        } else
                            return false;
                    }
                } else
                    return false;
            }
        }

        else if (strcmp(node->Name(), "codeblocks") == 0) {
            for (const tinyxml2::XMLElement *functionnode = node->FirstChildElement(); functionnode; functionnode = functionnode->NextSiblingElement()) {
                if (strcmp(functionnode->Name(), "library") == 0) {
                    const char * const extension = functionnode->Attribute("extension");
                    for (const tinyxml2::XMLElement *librarynode = functionnode->FirstChildElement(); librarynode; librarynode = librarynode->NextSiblingElement()) {
                        if (strcmp(librarynode->Name(), "block") == 0) {
                            _executableblocks[extension].addBlock(librarynode->Attribute("name"));
                        } else if (strcmp(librarynode->Name(), "structure") == 0) {
                            const char * start = librarynode->Attribute("start");
                            if (start)
                                _executableblocks[extension].setStart(start);
                            const char * end = librarynode->Attribute("end");
                            if (end)
                                _executableblocks[extension].setEnd(end);
                            const char * offset = librarynode->Attribute("offset");
                            if (offset)
                                _executableblocks[extension].setOffset(atoi(offset));
                        } else
                            return false;
                    }
                }
            }

        } else
            return false;
    }
    return true;
}
Ejemplo n.º 21
0
bool Library::load(const tinyxml2::XMLDocument &doc)
{
    const tinyxml2::XMLElement * const rootnode = doc.FirstChildElement();

    if (rootnode == NULL)
        return false;

    if (strcmp(rootnode->Name(),"def") != 0)
        return false;

    for (const tinyxml2::XMLElement *node = rootnode->FirstChildElement(); node; node = node->NextSiblingElement()) {
        if (strcmp(node->Name(),"memory")==0 || strcmp(node->Name(),"resource")==0) {
            if (strcmp(node->Name(), "memory")==0)
                while (!ismemory(++allocid));
            else
                while (!isresource(++allocid));
            for (const tinyxml2::XMLElement *memorynode = node->FirstChildElement(); memorynode; memorynode = memorynode->NextSiblingElement()) {
                if (strcmp(memorynode->Name(),"alloc")==0) {
                    _alloc[memorynode->GetText()] = allocid;
                    const char *init = memorynode->Attribute("init");
                    if (init && strcmp(init,"false")==0) {
                        returnuninitdata.insert(memorynode->GetText());
                    }
                } else if (strcmp(memorynode->Name(),"dealloc")==0)
                    _dealloc[memorynode->GetText()] = allocid;
                else if (strcmp(memorynode->Name(),"use")==0)
                    use.insert(memorynode->GetText());
                else
                    return false;
            }
        }

        else if (strcmp(node->Name(),"function")==0) {
            const char *name = node->Attribute("name");
            if (name == NULL)
                return false;

            for (const tinyxml2::XMLElement *functionnode = node->FirstChildElement(); functionnode; functionnode = functionnode->NextSiblingElement()) {
                if (strcmp(functionnode->Name(),"noreturn")==0)
                    _noreturn[name] = (strcmp(functionnode->GetText(), "true") == 0);
                else if (strcmp(functionnode->Name(),"leak-ignore")==0)
                    leakignore.insert(name);
                else if (strcmp(functionnode->Name(), "arg") == 0 && functionnode->Attribute("nr") != NULL) {
                    const int nr = atoi(functionnode->Attribute("nr"));
                    bool notbool = false;
                    bool notnull = false;
                    bool notuninit = false;
                    bool formatstr = false;
                    bool strz = false;
                    std::string valid;
                    for (const tinyxml2::XMLElement *argnode = functionnode->FirstChildElement(); argnode; argnode = argnode->NextSiblingElement()) {
                        if (strcmp(argnode->Name(), "not-bool") == 0)
                            notbool = true;
                        else if (strcmp(argnode->Name(), "not-null") == 0)
                            notnull = true;
                        else if (strcmp(argnode->Name(), "not-uninit") == 0)
                            notuninit = true;
                        else if (strcmp(argnode->Name(), "formatstr") == 0)
                            formatstr = true;
                        else if (strcmp(argnode->Name(), "strz") == 0)
                            strz = true;
                        else if (strcmp(argnode->Name(), "valid") == 0) {
                            // Validate the validation expression
                            const char *p = argnode->GetText();
                            if (!std::isdigit(*p))
                                return false;
                            for (; *p; p++) {
                                if (std::isdigit(*p))
                                    continue;
                                if (*p == '-' && std::isdigit(*(p-1)))
                                    continue;
                                if (*p == ',' && *(p+1) != ',')
                                    continue;
                                return false;
                            }

                            // Set validation expression
                            valid = argnode->GetText();
                        }

                        else
                            return false;
                    }
                    argumentChecks[name][nr].notbool   = notbool;
                    argumentChecks[name][nr].notnull   = notnull;
                    argumentChecks[name][nr].notuninit = notuninit;
                    argumentChecks[name][nr].formatstr = formatstr;
                    argumentChecks[name][nr].strz      = strz;
                    argumentChecks[name][nr].valid     = valid;
                } else if (strcmp(functionnode->Name(), "ignorefunction") == 0) {
                    _ignorefunction.insert(name);
                } else
                    return false;
            }
        }

        else if (strcmp(node->Name(), "markup") == 0) {
            const char * const extension = node->Attribute("ext");
            if (!extension)
                return false;
            _markupExtensions.insert(extension);

            const char * const reporterrors = node->Attribute("reporterrors");
            _reporterrors[extension] = (reporterrors && strcmp(reporterrors, "true") == 0);
            const char * const aftercode = node->Attribute("aftercode");
            _processAfterCode[extension] = (aftercode && strcmp(aftercode, "true") == 0);

            for (const tinyxml2::XMLElement *markupnode = node->FirstChildElement(); markupnode; markupnode = markupnode->NextSiblingElement()) {
                if (strcmp(markupnode->Name(), "keywords") == 0) {
                    for (const tinyxml2::XMLElement *librarynode = markupnode->FirstChildElement(); librarynode; librarynode = librarynode->NextSiblingElement()) {
                        if (strcmp(librarynode->Name(), "keyword") == 0)
                            _keywords[extension].insert(librarynode->Attribute("name"));
                        else
                            return false;
                    }
                }

                else if (strcmp(markupnode->Name(), "exported") == 0) {
                    for (const tinyxml2::XMLElement *exporter = markupnode->FirstChildElement(); exporter; exporter = exporter->NextSiblingElement()) {
                        if (strcmp(exporter->Name(), "exporter") != 0)
                            return false;

                        const char * const prefix = exporter->Attribute("prefix");
                        if (!prefix)
                            return false;

                        for (const tinyxml2::XMLElement *e = exporter->FirstChildElement(); e; e = e->NextSiblingElement()) {
                            if (strcmp(e->Name(), "prefix") == 0)
                                _exporters[prefix].addPrefix(e->GetText());
                            else if (strcmp(e->Name(), "suffix") == 0)
                                _exporters[prefix].addSuffix(e->GetText());
                            else
                                return false;
                        }
                    }
                }

                else if (strcmp(markupnode->Name(), "imported") == 0) {
                    for (const tinyxml2::XMLElement *librarynode = markupnode->FirstChildElement(); librarynode; librarynode = librarynode->NextSiblingElement()) {
                        if (strcmp(librarynode->Name(), "importer") == 0)
                            _importers[extension].insert(librarynode->GetText());
                        else
                            return false;
                    }
                }

                else if (strcmp(markupnode->Name(), "reflection") == 0) {
                    for (const tinyxml2::XMLElement *reflectionnode = markupnode->FirstChildElement(); reflectionnode; reflectionnode = reflectionnode->NextSiblingElement()) {
                        if (strcmp(reflectionnode->Name(), "call") != 0)
                            return false;

                        const char * const argString = reflectionnode->Attribute("arg");
                        if (!argString)
                            return false;

                        _reflection[extension][reflectionnode->GetText()] = atoi(argString);
                    }
                }

                else if (strcmp(markupnode->Name(), "codeblocks") == 0) {
                    for (const tinyxml2::XMLElement *blocknode = markupnode->FirstChildElement(); blocknode; blocknode = blocknode->NextSiblingElement()) {
                        if (strcmp(blocknode->Name(), "block") == 0)
                            _executableblocks[extension].addBlock(blocknode->Attribute("name"));

                        else if (strcmp(blocknode->Name(), "structure") == 0) {
                            const char * start = blocknode->Attribute("start");
                            if (start)
                                _executableblocks[extension].setStart(start);
                            const char * end = blocknode->Attribute("end");
                            if (end)
                                _executableblocks[extension].setEnd(end);
                            const char * offset = blocknode->Attribute("offset");
                            if (offset)
                                _executableblocks[extension].setOffset(atoi(offset));
                        }

                        else
                            return false;
                    }
                }

                else
                    return false;
            }
        }

        else
            return false;
    }
    return true;
}
Ejemplo n.º 22
0
void Outputs::from_XML(const tinyxml2::XMLDocument& document)
{
    std::ostringstream buffer;

    const tinyxml2::XMLElement* outputs_element = document.FirstChildElement("Outputs");

    if(!outputs_element)
    {
        buffer << "OpenNN Exception: Outputs class.\n"
               << "void from_XML(const tinyxml2::XMLDocument&) method.\n"
               << "Outputs element is NULL.\n";

        throw std::logic_error(buffer.str());
    }

    // Outputs number

   const tinyxml2::XMLElement* outputs_number_element = outputs_element->FirstChildElement("OutputsNumber");

   if(!outputs_number_element)
   {
       buffer << "OpenNN Exception: Outputs class.\n"
              << "void from_XML(const tinyxml2::XMLDocument&) method.\n"
              << "Outputs number element is NULL.\n";

       throw std::logic_error(buffer.str());
   }

   const size_t outputs_number = atoi(outputs_number_element->GetText());

   set(outputs_number);

   unsigned index = 0; // size_t does not work

   const tinyxml2::XMLElement* start_element = outputs_number_element;

   for(size_t i = 0; i < outputs_number; i++)
   {
      const tinyxml2::XMLElement* item_element = start_element->NextSiblingElement("Item");
      start_element = item_element;

      if(!item_element)
      {
          buffer << "OpenNN Exception: Outputs class.\n"
                 << "void from_XML(const tinyxml2::XMLElement*) method.\n"
                 << "Item " << i+1 << " is NULL.\n";

          throw std::logic_error(buffer.str());
      }

     item_element->QueryUnsignedAttribute("Index", &index);

     if(index != i+1)
     {
         buffer << "OpenNN Exception: Outputs class.\n"
                << "void from_XML(const tinyxml2::XMLElement*) method.\n"
                << "Index " << index << " is not correct.\n";

         throw std::logic_error(buffer.str());
     }

     // Name

     const tinyxml2::XMLElement* name_element = item_element->FirstChildElement("Name");

     if(name_element)
     {
         if(name_element->GetText())
         {
            items[index-1].name = name_element->GetText();
         }
     }

     // Units

     const tinyxml2::XMLElement* units_element = item_element->FirstChildElement("Units");

     if(units_element)
     {
         if(units_element->GetText())
         {
            items[index-1].units = units_element->GetText();
         }
     }


     // Description

     const tinyxml2::XMLElement* description_element = item_element->FirstChildElement("Description");

     if(description_element)
     {
         if(description_element->GetText())
         {
            items[index-1].description = description_element->GetText();
         }
     }

   }
}
Ejemplo n.º 23
0
void PlugIn::from_XML(const tinyxml2::XMLDocument& document) {
  // Independent variables number
  {
    const tinyxml2::XMLElement* element =
        document.FirstChildElement("IndependentVariablesNumber");

    if (element) {
      const char* text = element->GetText();

      if (text) {
        try {
          set_independent_variables_number(atoi(text));
        }
        catch (const std::logic_error & e) {
          std::cout << e.what() << std::endl;
        }
      }
    }
  }

  // Dependent variables number
  {
    const tinyxml2::XMLElement* element =
        document.FirstChildElement("DependentVariablesNumber");

    if (element) {
      const char* text = element->GetText();

      if (text) {
        try {
          set_dependent_variables_number(atoi(text));
        }
        catch (const std::logic_error & e) {
          std::cout << e.what() << std::endl;
        }
      }
    }
  }

  // Input method
  {
    const tinyxml2::XMLElement* input_method_element =
        document.FirstChildElement("InputMethod");

    if (input_method_element) {
      const char* input_method_text = input_method_element->GetText();

      if (input_method_text) {
        try {
          set_input_method(input_method_text);
        }
        catch (const std::logic_error & e) {
          std::cout << e.what() << std::endl;
        }
      }
    }
  }

  // Template file_name
  {
    const tinyxml2::XMLElement* template_file_name_element =
        document.FirstChildElement("TemplateFileName");

    if (template_file_name_element) {
      const char* template_file_name_text =
          template_file_name_element->GetText();

      if (template_file_name_text) {
        try {
          set_template_file_name(template_file_name_text);
        }
        catch (const std::logic_error & e) {
          std::cout << e.what() << std::endl;
        }
      }
    }
  }

  // Input file_name
  {
    const tinyxml2::XMLElement* input_file_name_element =
        document.FirstChildElement("InputFileName");

    if (input_file_name_element) {
      const char* input_file_name_text = input_file_name_element->GetText();

      if (input_file_name_text) {
        try {
          set_input_file_name(input_file_name_text);
        }
        catch (const std::logic_error & e) {
          std::cout << e.what() << std::endl;
        }
      }
    }
  }

  // Batch file_name
  {
    const tinyxml2::XMLElement* script_file_name_element =
        document.FirstChildElement("BatchFileName");

    if (script_file_name_element) {
      const char* script_file_name_text = script_file_name_element->GetText();

      if (script_file_name_text) {
        try {
          set_script_file_name(script_file_name_text);
        }
        catch (const std::logic_error & e) {
          std::cout << e.what() << std::endl;
        }
      }
    }
  }

  // Output file_name
  {
    const tinyxml2::XMLElement* output_file_name_element =
        document.FirstChildElement("OutputFileName");

    if (output_file_name_element) {
      const char* output_file_name_text = output_file_name_element->GetText();

      if (output_file_name_text) {
        try {
          set_output_file_name(output_file_name_text);
        }
        catch (const std::logic_error & e) {
          std::cout << e.what() << std::endl;
        }
      }
    }
  }
  /*
    // Input flags
    {
       tinyxml2::XMLElement* input_flags_element =
  document->FirstChildElement("InputFlags");
  
       if(input_flags_element)
       {
          const char* input_flags_text = input_flags_element->GetText();
  
          if(input_flags_text)
          {
             Vector<std::string> new_input_flags;
             new_input_flags.parse(input_flags_text);
  
             try
             {
                set_input_flags(new_input_flags);
             }
             catch(const std::logic_error& e)
             {
                std::cout << e.what() << std::endl;
             }
          }
       }
    }
  */
  // Display
  {
    const tinyxml2::XMLElement* display_element =
        document.FirstChildElement("Display");

    if (display_element) {
      const char* display_text = display_element->GetText();

      if (display_text) {
        try {
          std::string display_string(display_text);

          set_display(display_string != "0");
        }
        catch (const std::logic_error & e) {
          std::cout << e.what() << std::endl;
        }
      }
    }
  }
}
Ejemplo n.º 24
0
void ScalingLayer::from_XML(const tinyxml2::XMLDocument& document)
{
    std::ostringstream buffer;

    const tinyxml2::XMLElement* scaling_layer_element = document.FirstChildElement("ScalingLayer");

    if(!scaling_layer_element)
    {
        buffer << "OpenNN Exception: ScalingLayer class.\n"
               << "void from_XML(const tinyxml2::XMLDocument&) method.\n"
               << "Scaling layer element is NULL.\n";

        throw std::logic_error(buffer.str());
    }

    // Scaling neurons number

   const tinyxml2::XMLElement* scaling_neurons_number_element = scaling_layer_element->FirstChildElement("ScalingNeuronsNumber");

   if(!scaling_neurons_number_element)
   {
       buffer << "OpenNN Exception: ScalingLayer class.\n"
              << "void from_XML(const tinyxml2::XMLDocument&) method.\n"
              << "Scaling neurons number element is NULL.\n";

       throw std::logic_error(buffer.str());
   }

   const size_t scaling_neurons_number = atoi(scaling_neurons_number_element->GetText());

   set(scaling_neurons_number);

   unsigned index = 0; // size_t does not work

   const tinyxml2::XMLElement* start_element = scaling_neurons_number_element;

   for(size_t i = 0; i < scaling_neurons_number; i++)
   {
       const tinyxml2::XMLElement* statistics_element = start_element->NextSiblingElement("Statistics");
       start_element = statistics_element;

       if(!statistics_element)
       {
           buffer << "OpenNN Exception: ScalingLayer class.\n"
                  << "void from_XML(const tinyxml2::XMLDocument&) method.\n"
                  << "Statistics of scaling neuron " << i+1 << " is NULL.\n";

           throw std::logic_error(buffer.str());
       }

      statistics_element->QueryUnsignedAttribute("Index", &index);

      if(index != i+1)
      {
          buffer << "OpenNN Exception: ScalingLayer class.\n"
                 << "void from_XML(const tinyxml2::XMLDocument&) method.\n"
                 << "Index " << index << " is not correct.\n";

          throw std::logic_error(buffer.str());
      }

      // Minimum

      const tinyxml2::XMLElement* minimum_element = statistics_element->FirstChildElement("Minimum");

      if(!minimum_element)
      {
         buffer << "OpenNN Exception: ScalingLayer class.\n"
                << "void from_XML(const tinyxml2::XMLDocument&) method.\n"
                << "Minimum element " << i+1 << " is NULL.\n";

         throw std::logic_error(buffer.str());
      }

      if(minimum_element->GetText())
      {
          statistics[i].minimum = atof(minimum_element->GetText());
      }

      // Maximum

      const tinyxml2::XMLElement* maximum_element = statistics_element->FirstChildElement("Maximum");

      if(!maximum_element)
      {
         buffer << "OpenNN Exception: ScalingLayer class.\n"
                << "void from_XML(const tinyxml2::XMLDocument&) method.\n"
                << "Maximum element " << i+1 << " is NULL.\n";

         throw std::logic_error(buffer.str());
      }

      if(maximum_element->GetText())
      {
          statistics[i].maximum = atof(maximum_element->GetText());
      }

      // Mean

      const tinyxml2::XMLElement* mean_element = statistics_element->FirstChildElement("Mean");

      if(!mean_element)
      {
         buffer << "OpenNN Exception: ScalingLayer class.\n"
                << "void from_XML(const tinyxml2::XMLDocument&) method.\n"
                << "Mean element " << i+1 << " is NULL.\n";

         throw std::logic_error(buffer.str());
      }

      if(mean_element->GetText())
      {
          statistics[i].mean = atof(mean_element->GetText());
      }

      // Standard deviation

      const tinyxml2::XMLElement* standard_deviation_element = statistics_element->FirstChildElement("StandardDeviation");

      if(!standard_deviation_element)
      {
         buffer << "OpenNN Exception: ScalingLayer class.\n"
                << "void from_XML(const tinyxml2::XMLDocument&) method.\n"
                << "Standard deviation element " << i+1 << " is NULL.\n";

         throw std::logic_error(buffer.str());
      }

      if(standard_deviation_element->GetText())
      {
          statistics[i].standard_deviation = atof(standard_deviation_element->GetText());
      }
   }

  // Scaling method
  {
     const tinyxml2::XMLElement* scaling_method_element = scaling_layer_element->FirstChildElement("ScalingMethod");

     if(scaling_method_element)
     {
        std::string new_method = scaling_method_element->GetText();

        try
        {
           set_scaling_method(new_method);
        }
        catch(const std::logic_error& e)
        {
           std::cout << e.what() << std::endl;
        }
     }
  }

  // Display
  {
     const tinyxml2::XMLElement* display_element = scaling_layer_element->FirstChildElement("Display");

     if(display_element)
     {
        std::string new_display_string = display_element->GetText();

        try
        {
           set_display(new_display_string != "0");
        }
        catch(const std::logic_error& e)
        {
           std::cout << e.what() << std::endl;
        }
     }
  }
}
Ejemplo n.º 25
0
void TileMap::load(tinyxml2::XMLDocument & doc, ResourceManager & m_resources)
{
	int twidth, theight;
	std::string tileset;
	std::string data;
	
	tinyxml2::XMLElement * element = doc.FirstChildElement("map");
	element->FirstChildElement("width")->QueryIntText(&m_width);
	element->FirstChildElement("height")->QueryIntText(&m_height);
	element->FirstChildElement("tile_size")->QueryIntText(&m_tileSize);


	tileset = element->FirstChildElement("tileset")->Attribute("id");
	twidth = element->FirstChildElement("tileset")->IntAttribute("width");
	theight = element->FirstChildElement("tileset")->IntAttribute("height");
	data = element->FirstChildElement("data")->GetText();


	m_vertexArray.setPrimitiveType(sf::PrimitiveType::Quads);
	m_vertexArray.resize(m_width * m_height * 4);
	
	m_tileset = m_resources.get<sf::Texture>(tileset);


	std::istringstream ss(data);
	std::string token;
	int posX = 0;
	int posY = 0;
	while (std::getline(ss, token, ','))
	{
		int tileId = std::stoi(token);
		if (m_tiles.size() == 0 || m_tiles.back().size() >= static_cast<unsigned>(m_width))
			m_tiles.emplace_back();
		m_tiles.back().push_back(tileId);

		int tx = (tileId - 1) % twidth;
		int ty = (tileId - 1) / theight;

		
		sf::Vertex * vertex = &m_vertexArray[(posY * m_width + posX) * 4];
		vertex[0].position = sf::Vector2f(posX * m_tileSize, posY * m_tileSize);
		vertex[1].position = sf::Vector2f((posX + 1) * m_tileSize, posY * m_tileSize);
		vertex[2].position = sf::Vector2f((posX + 1) * m_tileSize, (posY + 1) * m_tileSize);
		vertex[3].position = sf::Vector2f(posX * m_tileSize, (posY + 1) * m_tileSize);
		


		if (tileId)
		{
			vertex[0].texCoords = sf::Vector2f(tx * m_tileSize, ty * m_tileSize);
			vertex[1].texCoords = sf::Vector2f((tx + 1) * m_tileSize, ty * m_tileSize);
			vertex[2].texCoords = sf::Vector2f((tx + 1) * m_tileSize, (ty + 1) * m_tileSize);
			vertex[3].texCoords = sf::Vector2f(tx * m_tileSize, (ty + 1) * m_tileSize);
		}
		else
		{
			vertex[0].color = sf::Color::Transparent;
			vertex[1].color = sf::Color::Transparent;
			vertex[2].color = sf::Color::Transparent;
			vertex[3].color = sf::Color::Transparent;
		}

		posX++;
		if (posX >= m_width)
		{
			posX = 0;
			posY++;
		}
	}


}
Ejemplo n.º 26
0
void process_loadout_xml(tinyxml2::XMLDocument& doc, bool devkit) 
{
    using namespace tinyxml2;
    const XMLNode* node = NULL;

    LOG << "Parsing XML file. DevKit solution: " << devkit ;

    if (devkit) {
        // Finds the first loadout element
        node = doc.FirstChildElement("solution");
        if (node == NULL) {
            LOG_WARN << "Invalid DevKit solution file." 
                     << "Trying parse as XML loadout file";
            devkit = false;

            // Try to parse as normal XML
            node = doc.FirstChildElement("loadout");
            if (node == NULL) {
                LOG_WARN << "Invalid loadout file."; 
                return;
            }
            goto end_devkit; // Try to parse as normal XML
        } 

        node = node->FirstChildElement("loadout");
        if (node == NULL) {
            LOG_WARN << "Invalid DevKit solution file.";
            return;
        }

        node = node->FirstChildElement("loadout");
        if (node == NULL) {
            LOG_WARN << "Invalid DevKit solution file."; 
            return;
        }

        end_devkit:
            ;
    } else {
        node = doc.FirstChildElement("loadout");
        if (node == NULL) {
            LOG_WARN << "Invalid loadout file.";
            return;
        }
    }
    // Node points to <loadout>

    node = node->FirstChildElement("hardware");
    if (node == NULL) {
        LOG_WARN << "Invalid loadout file.";
        return;
    }

    std::string defname = "disk";
    unsigned fd_counter = 0;

    for ( auto dev = node->FirstChildElement(); dev != NULL; 
            dev = dev->NextSiblingElement()) {
        std::string name = dev->Name();
        if (name != "device")
            continue;

        if (dev->Attribute("type", "GenericClock")) {
            auto gclock = std::make_shared<Generic_Clock>();
            dcpu->attachHardware (gclock);
        } else if (dev->Attribute("type", "GenericKeyboard")) {
            auto gkeyboard = std::make_shared<keyboard::GKeyboard>();
            dcpu->attachHardware (gkeyboard);
            auto keyb_win = 
                std::make_shared<windows::KeyboardWindow>(gkeyboard);
            wins.push_back(keyb_win);
        // Monitors -----------------------------------------------------------
        } else if (dev->Attribute("type", "LEM1802")) {
            auto monitor = std::make_shared<lem::Lem1802>();
            dcpu->attachHardware (monitor);
            monitors.push_back(monitor);
            
            auto window = std::make_shared<windows::MonitorWindow>(monitor, 
                "LEM 1802", FRAMERATE);
            wins.push_back(window);
            window->setSplashImage("assets/lem_splash.png");
        } else if (dev->Attribute("type", "LEM1803")) {
            auto monitor = std::make_shared<lem::Lem1803>();
            dcpu->attachHardware (monitor);
            monitors.push_back(monitor);
            
            auto window = std::make_shared<windows::MonitorWindow>(monitor, 
                "LEM 1803", FRAMERATE);
            wins.push_back(window);
            window->setSplashImage("assets/lem_splash.png");
        } else if (dev->Attribute("type", "CGM1084")) {
            auto monitor = std::make_shared<cgm::CGM >();
            dcpu->attachHardware (monitor);
            monitors.push_back(monitor);
            
            auto window = std::make_shared<windows::MonitorWindow>(monitor, 
                "CGM 1084", FRAMERATE);
            wins.push_back(window);
            window->setSplashImage("assets/cgm_splash.png");

        // Audio --------------------------------------------------------------
        } else if (dev->Attribute("type", "SimpleSpeaker")) {
            auto speaker = std::make_shared<speaker::Speaker>();
            dcpu->attachHardware (speaker);
            if (!no_sound) {
                auto gen = std::make_shared<audio::SquareGenerator>();
                sound_streams.push_back(gen);
                gen->prepare();
                gen->play();
                speaker->setFreqCallback(
                        audio::SquareGenerator::WrappeCallback, 
                            (void*)gen.get() );
            }

        // Storage ------------------------------------------------------------
        } else if (dev->Attribute("type", "M35FD")) {
            auto fd = std::make_shared<m35fd::M35FD>();
            fdrives.push_back(fd);
            dcpu->attachHardware (fd);

            std::string fname;
            if (floppy_files.size() <= fd_counter) {
                char tmp[10];
                // Generates filename "diskX.dsk"
                std::string fname = defname;
                snprintf(tmp, 10, "%u", fd_counter);
                fname.append(tmp);
                fname.append(".dsk");
                LOG << fname;
                auto floppy = std::make_shared<m35fd::M35_Floppy>(fname);
                floppies.push_back(floppy);
            } else {
                fname = floppy_files.front();
                auto floppy = std::make_shared<m35fd::M35_Floppy>(fname);
                floppies.push_back(floppy);
            }
            fd_counter++;

        }
        

    }

    LOG << "Custom loadout";
    custom_loadout = true;
}
Ejemplo n.º 27
0
void TrainingRateAlgorithm::from_XML(const tinyxml2::XMLDocument& document)
{
   const tinyxml2::XMLElement* root_element = document.FirstChildElement("TrainingRateAlgorithm");

   if(!root_element)
   {
       std::ostringstream buffer;

       buffer << "OpenNN Exception: TrainingRateAlgorithm class.\n"
              << "void from_XML(const tinyxml2::XMLDocument&) method.\n"
              << "Training rate algorithm element is NULL.\n";

       throw std::logic_error(buffer.str());
   }

   // Training rate method
   {
       const tinyxml2::XMLElement* element = root_element->FirstChildElement("TrainingRateMethod");

       if(element)
       {
          std::string new_training_rate_method = element->GetText();

          try
          {
             set_training_rate_method(new_training_rate_method);
          }
          catch(const std::logic_error& e)
          {
             std::cout << e.what() << std::endl;
          }
       }
   }

   // Bracketing factor
   {
       const tinyxml2::XMLElement* element = root_element->FirstChildElement("BracketingFactor");

       if(element)
       {
          const double new_bracketing_factor = atof(element->GetText());

          try
          {
             set_bracketing_factor(new_bracketing_factor);
          }
          catch(const std::logic_error& e)
          {
             std::cout << e.what() << std::endl;
          }
       }
   }
/*
   // First training rate
   {
       const tinyxml2::XMLElement* element = root_element->FirstChildElement("FirstTrainingRate");

       if(element)
       {
          const double new_first_training_rate = atof(element->GetText());

          try
          {
             set_first_training_rate(new_first_training_rate);
          }
          catch(const std::logic_error& e)
          {
             std::cout << e.what() << std::endl;
          }
       }
   }
*/
   // Training rate tolerance 
   {
       const tinyxml2::XMLElement* element = root_element->FirstChildElement("TrainingRateTolerance");

       if(element)
       {
          const double new_training_rate_tolerance = atof(element->GetText());

          try
          {
             set_training_rate_tolerance(new_training_rate_tolerance);
          }
          catch(const std::logic_error& e)
          {
             std::cout << e.what() << std::endl;
          }
       }
   }

   // Warning training rate 
   {
       const tinyxml2::XMLElement* element = root_element->FirstChildElement("WarningTrainingRate");

       if(element)
       {
          const double new_warning_training_rate = atof(element->GetText());

          try
          {
             set_warning_training_rate(new_warning_training_rate);
          }
          catch(const std::logic_error& e)
          {
             std::cout << e.what() << std::endl;
          }
       }
   }

   // Error training rate
   {
       const tinyxml2::XMLElement* element = root_element->FirstChildElement("ErrorTrainingRate");

       if(element)
       {
          const double new_error_training_rate = atof(element->GetText());

          try
          {
             set_error_training_rate(new_error_training_rate);
          }
          catch(const std::logic_error& e)
          {
             std::cout << e.what() << std::endl;
          }
       }
   }

   // Display warnings
   {
       const tinyxml2::XMLElement* element = root_element->FirstChildElement("Display");

       if(element)
       {
          const std::string new_display = element->GetText();

          try
          {
             set_display(new_display != "0");
          }
          catch(const std::logic_error& e)
          {
             std::cout << e.what() << std::endl;
          }
       }
   }
}
Ejemplo n.º 28
0
Library::Error Library::load(const tinyxml2::XMLDocument &doc)
{
    const tinyxml2::XMLElement * const rootnode = doc.FirstChildElement();

    if (rootnode == nullptr)
        return Error(BAD_XML);

    if (strcmp(rootnode->Name(),"def") != 0)
        return Error(BAD_ELEMENT, rootnode->Name());

    for (const tinyxml2::XMLElement *node = rootnode->FirstChildElement(); node; node = node->NextSiblingElement()) {
        std::string nodename = node->Name();
        if (nodename == "memory" || nodename == "resource") {
            // get allocationId to use..
            int allocationId = 0;
            for (const tinyxml2::XMLElement *memorynode = node->FirstChildElement(); memorynode; memorynode = memorynode->NextSiblingElement()) {
                if (strcmp(memorynode->Name(),"dealloc")==0) {
                    const std::map<std::string,int>::const_iterator it = _dealloc.find(memorynode->GetText());
                    if (it != _dealloc.end()) {
                        allocationId = it->second;
                        break;
                    }
                }
            }
            if (allocationId == 0) {
                if (strcmp(node->Name(), "memory")==0)
                    while (!ismemory(++allocid));
                else
                    while (!isresource(++allocid));
                allocationId = allocid;
            }

            // add alloc/dealloc/use functions..
            for (const tinyxml2::XMLElement *memorynode = node->FirstChildElement(); memorynode; memorynode = memorynode->NextSiblingElement()) {
                if (strcmp(memorynode->Name(),"alloc")==0) {
                    _alloc[memorynode->GetText()] = allocationId;
                    const char *init = memorynode->Attribute("init");
                    if (init && strcmp(init,"false")==0) {
                        returnuninitdata.insert(memorynode->GetText());
                    }
                } else if (strcmp(memorynode->Name(),"dealloc")==0)
                    _dealloc[memorynode->GetText()] = allocationId;
                else if (strcmp(memorynode->Name(),"use")==0)
                    use.insert(memorynode->GetText());
                else
                    return Error(BAD_ELEMENT, memorynode->Name());
            }
        }

        else if (nodename == "define") {
            const char *name = node->Attribute("name");
            if (name == nullptr)
                return Error(MISSING_ATTRIBUTE, "name");
            const char *value = node->Attribute("value");
            if (value == nullptr)
                return Error(MISSING_ATTRIBUTE, "value");
            defines.push_back(std::string("#define ") +
                              name +
                              " " +
                              value +
                              "\n");
        }

        else if (nodename == "function") {
            const char *name_char = node->Attribute("name");
            if (name_char == nullptr)
                return Error(MISSING_ATTRIBUTE, "name");
            std::string name = name_char;

            for (const tinyxml2::XMLElement *functionnode = node->FirstChildElement(); functionnode; functionnode = functionnode->NextSiblingElement()) {
                std::string functionnodename = functionnode->Name();
                if (functionnodename == "noreturn")
                    _noreturn[name] = (strcmp(functionnode->GetText(), "true") == 0);
                else if (functionnodename == "pure")
                    functionpure.insert(name);
                else if (functionnodename == "const") {
                    functionconst.insert(name);
                    functionpure.insert(name); // a constant function is pure
                } else if (functionnodename == "leak-ignore")
                    leakignore.insert(name);
                else if (functionnodename == "arg" && functionnode->Attribute("nr") != nullptr) {
                    const bool bAnyArg = strcmp(functionnode->Attribute("nr"),"any")==0;
                    const int nr = (bAnyArg) ? -1 : atoi(functionnode->Attribute("nr"));
                    bool notbool = false;
                    bool notnull = false;
                    bool notuninit = false;
                    bool formatstr = false;
                    bool strz = false;
                    std::string& valid = argumentChecks[name][nr].valid;
                    std::list<ArgumentChecks::MinSize>& minsizes = argumentChecks[name][nr].minsizes;
                    for (const tinyxml2::XMLElement *argnode = functionnode->FirstChildElement(); argnode; argnode = argnode->NextSiblingElement()) {
                        std::string argnodename = argnode->Name();
                        if (argnodename == "not-bool")
                            notbool = true;
                        else if (argnodename == "not-null")
                            notnull = true;
                        else if (argnodename == "not-uninit")
                            notuninit = true;
                        else if (argnodename == "formatstr")
                            formatstr = true;
                        else if (argnodename == "strz")
                            strz = true;
                        else if (argnodename == "valid") {
                            // Validate the validation expression
                            const char *p = argnode->GetText();
                            bool error = false;
                            bool range = false;
                            for (; *p; p++) {
                                if (std::isdigit(*p))
                                    error |= (*(p+1) == '-');
                                else if (*p == ':')
                                    error |= range;
                                else if (*p == '-')
                                    error |= (!std::isdigit(*(p+1)));
                                else if (*p == ',')
                                    range = false;
                                else
                                    error = true;

                                range |= (*p == ':');
                            }
                            if (error)
                                return Error(BAD_ATTRIBUTE_VALUE, argnode->GetText());

                            // Set validation expression
                            valid = argnode->GetText();
                        }

                        else if (argnodename == "minsize") {
                            const char *typeattr = argnode->Attribute("type");
                            if (!typeattr)
                                return Error(MISSING_ATTRIBUTE, "type");

                            ArgumentChecks::MinSize::Type type;
                            if (strcmp(typeattr,"strlen")==0)
                                type = ArgumentChecks::MinSize::STRLEN;
                            else if (strcmp(typeattr,"argvalue")==0)
                                type = ArgumentChecks::MinSize::ARGVALUE;
                            else if (strcmp(typeattr,"sizeof")==0)
                                type = ArgumentChecks::MinSize::SIZEOF;
                            else if (strcmp(typeattr,"mul")==0)
                                type = ArgumentChecks::MinSize::MUL;
                            else
                                return Error(BAD_ATTRIBUTE_VALUE, typeattr);

                            const char *argattr  = argnode->Attribute("arg");
                            if (!argattr)
                                return Error(MISSING_ATTRIBUTE, "arg");
                            if (strlen(argattr) != 1 || argattr[0]<'0' || argattr[0]>'9')
                                return Error(BAD_ATTRIBUTE_VALUE, argattr);

                            minsizes.push_back(ArgumentChecks::MinSize(type,argattr[0]-'0'));
                            if (type == ArgumentChecks::MinSize::MUL) {
                                const char *arg2attr  = argnode->Attribute("arg2");
                                if (!arg2attr)
                                    return Error(MISSING_ATTRIBUTE, "arg2");
                                if (strlen(arg2attr) != 1 || arg2attr[0]<'0' || arg2attr[0]>'9')
                                    return Error(BAD_ATTRIBUTE_VALUE, arg2attr);
                                minsizes.back().arg2 = arg2attr[0] - '0';
                            }
                        }

                        else
                            return Error(BAD_ATTRIBUTE, argnode->Name());
                    }
                    argumentChecks[name][nr].notbool   = notbool;
                    argumentChecks[name][nr].notnull   = notnull;
                    argumentChecks[name][nr].notuninit = notuninit;
                    argumentChecks[name][nr].formatstr = formatstr;
                    argumentChecks[name][nr].strz      = strz;
                } else if (functionnodename == "ignorefunction") {
                    _ignorefunction.insert(name);
                } else if (functionnodename == "formatstr") {
                    const tinyxml2::XMLAttribute* scan = functionnode->FindAttribute("scan");
                    const tinyxml2::XMLAttribute* secure = functionnode->FindAttribute("secure");
                    _formatstr[name] = std::make_pair(scan && scan->BoolValue(), secure && secure->BoolValue());
                } else
                    return Error(BAD_ELEMENT, functionnode->Name());
            }
        }

        else if (nodename == "reflection") {
            for (const tinyxml2::XMLElement *reflectionnode = node->FirstChildElement(); reflectionnode; reflectionnode = reflectionnode->NextSiblingElement()) {
                if (strcmp(reflectionnode->Name(), "call") != 0)
                    return Error(BAD_ELEMENT, reflectionnode->Name());

                const char * const argString = reflectionnode->Attribute("arg");
                if (!argString)
                    return Error(MISSING_ATTRIBUTE, "arg");

                _reflection[reflectionnode->GetText()] = atoi(argString);
            }
        }

        else if (nodename == "markup") {
            const char * const extension = node->Attribute("ext");
            if (!extension)
                return Error(MISSING_ATTRIBUTE, "ext");
            _markupExtensions.insert(extension);

            const char * const reporterrors = node->Attribute("reporterrors");
            _reporterrors[extension] = (reporterrors && strcmp(reporterrors, "true") == 0);
            const char * const aftercode = node->Attribute("aftercode");
            _processAfterCode[extension] = (aftercode && strcmp(aftercode, "true") == 0);

            for (const tinyxml2::XMLElement *markupnode = node->FirstChildElement(); markupnode; markupnode = markupnode->NextSiblingElement()) {
                std::string markupnodename = markupnode->Name();
                if (markupnodename == "keywords") {
                    for (const tinyxml2::XMLElement *librarynode = markupnode->FirstChildElement(); librarynode; librarynode = librarynode->NextSiblingElement()) {
                        if (strcmp(librarynode->Name(), "keyword") == 0) {
                            const char* nodeName = librarynode->Attribute("name");
                            if (nodeName == nullptr)
                                return Error(MISSING_ATTRIBUTE, "name");
                            _keywords[extension].insert(nodeName);
                        } else
                            return Error(BAD_ELEMENT, librarynode->Name());
                    }
                }

                else if (markupnodename == "exported") {
                    for (const tinyxml2::XMLElement *exporter = markupnode->FirstChildElement(); exporter; exporter = exporter->NextSiblingElement()) {
                        if (strcmp(exporter->Name(), "exporter") != 0)
                            return Error(BAD_ELEMENT, exporter->Name());

                        const char * const prefix = exporter->Attribute("prefix");
                        if (!prefix)
                            return Error(MISSING_ATTRIBUTE, "prefix");

                        for (const tinyxml2::XMLElement *e = exporter->FirstChildElement(); e; e = e->NextSiblingElement()) {
                            if (strcmp(e->Name(), "prefix") == 0)
                                _exporters[prefix].addPrefix(e->GetText());
                            else if (strcmp(e->Name(), "suffix") == 0)
                                _exporters[prefix].addSuffix(e->GetText());
                            else
                                return Error(BAD_ELEMENT, e->Name());
                        }
                    }
                }

                else if (markupnodename == "imported") {
                    for (const tinyxml2::XMLElement *librarynode = markupnode->FirstChildElement(); librarynode; librarynode = librarynode->NextSiblingElement()) {
                        if (strcmp(librarynode->Name(), "importer") == 0)
                            _importers[extension].insert(librarynode->GetText());
                        else
                            return Error(BAD_ELEMENT, librarynode->Name());
                    }
                }

                else if (markupnodename == "codeblocks") {
                    for (const tinyxml2::XMLElement *blocknode = markupnode->FirstChildElement(); blocknode; blocknode = blocknode->NextSiblingElement()) {
                        if (strcmp(blocknode->Name(), "block") == 0) {
                            const char * blockName = blocknode->Attribute("name");
                            if (blockName)
                                _executableblocks[extension].addBlock(blockName);
                        } else if (strcmp(blocknode->Name(), "structure") == 0) {
                            const char * start = blocknode->Attribute("start");
                            if (start)
                                _executableblocks[extension].setStart(start);
                            const char * end = blocknode->Attribute("end");
                            if (end)
                                _executableblocks[extension].setEnd(end);
                            const char * offset = blocknode->Attribute("offset");
                            if (offset)
                                _executableblocks[extension].setOffset(atoi(offset));
                        }

                        else
                            return Error(BAD_ELEMENT, blocknode->Name());
                    }
                }

                else
                    return Error(BAD_ELEMENT, markupnode->Name());
            }
        }

        else if (nodename == "podtype") {
            const char * const name = node->Attribute("name");
            if (!name)
                return Error(MISSING_ATTRIBUTE, "name");
            PodType podType = {0};
            const char * const size = node->Attribute("sizeof");
            if (size)
                podType.size = atoi(size);
            const char * const sign = node->Attribute("sign");
            if (sign)
                podType.sign = *sign;
            podtypes[name] = podType;
        }

        else
            return Error(BAD_ELEMENT, node->Name());
    }
    return Error(OK);
}
Ejemplo n.º 29
0
void SimulatedAnnealingOrder::from_XML(const tinyxml2::XMLDocument& document)
{
    const tinyxml2::XMLElement* root_element = document.FirstChildElement("SimulatedAnnealingOrder");

    if(!root_element)
    {
        std::ostringstream buffer;

        buffer << "OpenNN Exception: IncrementalOrder class.\n"
               << "void from_XML(const tinyxml2::XMLDocument&) method.\n"
               << "SimulatedAnnealingOrder element is NULL.\n";

        throw std::logic_error(buffer.str());
    }

    // Minimum order
    {
        const tinyxml2::XMLElement* element = root_element->FirstChildElement("MinimumOrder");

        if(element)
        {
           const size_t new_minimum_order = atoi(element->GetText());

           try
           {
              minimum_order = new_minimum_order;
           }
           catch(const std::logic_error& e)
           {
              std::cout << e.what() << std::endl;
           }
        }
    }

    // Maximum order
    {
        const tinyxml2::XMLElement* element = root_element->FirstChildElement("MaximumOrder");

        if(element)
        {
           const size_t new_maximum_order = atoi(element->GetText());

           try
           {
              maximum_order = new_maximum_order;
           }
           catch(const std::logic_error& e)
           {
              std::cout << e.what() << std::endl;
           }
        }
    }

    // Parameters assays number
    {
        const tinyxml2::XMLElement* element = root_element->FirstChildElement("TrialsNumber");

        if(element)
        {
           const size_t new_trials_number = atoi(element->GetText());

           try
           {
              set_trials_number(new_trials_number);
           }
           catch(const std::logic_error& e)
           {
              std::cout << e.what() << std::endl;
           }
        }
    }

    // Performance calculation method
    {
        const tinyxml2::XMLElement* element = root_element->FirstChildElement("PerformanceCalculationMethod");

        if(element)
        {
           const std::string new_performance_calculation_method = element->GetText();

           try
           {
              set_performance_calculation_method(new_performance_calculation_method);
           }
           catch(const std::logic_error& e)
           {
              std::cout << e.what() << std::endl;
           }
        }
    }

    // Cooling rate
    {
        const tinyxml2::XMLElement* element = root_element->FirstChildElement("CoolingRate");

        if(element)
        {
           const double new_cooling_rate = atof(element->GetText());

           try
           {
              set_cooling_rate(new_cooling_rate);
           }
           catch(const std::logic_error& e)
           {
              std::cout << e.what() << std::endl;
           }
        }
    }

    // Reserve parameters data
    {
        const tinyxml2::XMLElement* element = root_element->FirstChildElement("ReserveParametersData");

        if(element)
        {
           const std::string new_reserve_parameters_data = element->GetText();

           try
           {
              set_reserve_parameters_data(new_reserve_parameters_data != "0");
           }
           catch(const std::logic_error& e)
           {
              std::cout << e.what() << std::endl;
           }
        }
    }

    // Reserve performance data
    {
        const tinyxml2::XMLElement* element = root_element->FirstChildElement("ReservePerformanceHistory");

        if(element)
        {
           const std::string new_reserve_performance_data = element->GetText();

           try
           {
              set_reserve_performance_data(new_reserve_performance_data != "0");
           }
           catch(const std::logic_error& e)
           {
              std::cout << e.what() << std::endl;
           }
        }
    }

    // Reserve selection performance data
    {
        const tinyxml2::XMLElement* element = root_element->FirstChildElement("ReserveSelectionPerformanceHistory");

        if(element)
        {
           const std::string new_reserve_selection_performance_data = element->GetText();

           try
           {
              set_reserve_selection_performance_data(new_reserve_selection_performance_data != "0");
           }
           catch(const std::logic_error& e)
           {
              std::cout << e.what() << std::endl;
           }
        }
    }

    // Reserve minimal parameters
    {
        const tinyxml2::XMLElement* element = root_element->FirstChildElement("ReserveMinimalParameters");

        if(element)
        {
           const std::string new_reserve_minimal_parameters = element->GetText();

           try
           {
              set_reserve_minimal_parameters(new_reserve_minimal_parameters != "0");
           }
           catch(const std::logic_error& e)
           {
              std::cout << e.what() << std::endl;
           }
        }
    }

    // Display
    {
        const tinyxml2::XMLElement* element = root_element->FirstChildElement("Display");

        if(element)
        {
           const std::string new_display = element->GetText();

           try
           {
              set_display(new_display != "0");
           }
           catch(const std::logic_error& e)
           {
              std::cout << e.what() << std::endl;
           }
        }
    }

    // Selection performance goal
    {
        const tinyxml2::XMLElement* element = root_element->FirstChildElement("SelectionPerformanceGoal");

        if(element)
        {
           const double new_selection_performance_goal = atof(element->GetText());

           try
           {
              set_selection_performance_goal(new_selection_performance_goal);
           }
           catch(const std::logic_error& e)
           {
              std::cout << e.what() << std::endl;
           }
        }
    }

    // Maximum iterations number
    {
        const tinyxml2::XMLElement* element = root_element->FirstChildElement("MaximumIterationsNumber");

        if(element)
        {
           const size_t new_maximum_iterations_number = atoi(element->GetText());

           try
           {
              set_maximum_iterations_number(new_maximum_iterations_number);
           }
           catch(const std::logic_error& e)
           {
              std::cout << e.what() << std::endl;
           }
        }
    }

    // Maximum time
    {
        const tinyxml2::XMLElement* element = root_element->FirstChildElement("MaximumTime");

        if(element)
        {
           const double new_maximum_time = atoi(element->GetText());

           try
           {
              set_maximum_time(new_maximum_time);
           }
           catch(const std::logic_error& e)
           {
              std::cout << e.what() << std::endl;
           }
        }
    }

    // Tolerance
    {
        const tinyxml2::XMLElement* element = root_element->FirstChildElement("Tolerance");

        if(element)
        {
           const double new_tolerance = atof(element->GetText());

           try
           {
              set_tolerance(new_tolerance);
           }
           catch(const std::logic_error& e)
           {
              std::cout << e.what() << std::endl;
           }
        }
    }

    // Minimum temperature
    {
        const tinyxml2::XMLElement* element = root_element->FirstChildElement("MinimumTemperature");

        if(element)
        {
           const double new_minimum_temperature = atof(element->GetText());

           try
           {
              set_minimum_temperature(new_minimum_temperature);
           }
           catch(const std::logic_error& e)
           {
              std::cout << e.what() << std::endl;
           }
        }
    }
}
Ejemplo n.º 30
0
/// Creates an XML parsing exception from the error in the
/// given XML document.
XMLParseException::XMLParseException(const tinyxml2::XMLDocument& doc)
	: XMLParseException(
		doc.ErrorName(),
		doc.GetErrorStr1() ? doc.GetErrorStr1() : "",
		doc.GetErrorStr2() ? doc.GetErrorStr2() : "")
{ }