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

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

		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);
		}
		else
			ptEl = doc.FirstChildElement(tag);

		const char* t = ptEl->GetText();
		if(t) txt = t;

		return txt;
	}
Exemplo n.º 2
0
  /*
   * \brief This function is called from the constructors to check verion of the read document
   *        and to read the game state of this storage
   */
  void readDocument() {
    if (!m_XMLDoc.FirstChildElement("snapshot")) { 
      throw Ogre::Exception(Ogre::Exception::ERR_INVALIDPARAMS,
			    "XMLdoc has no snapshot node",
			    __FILE__);
    }

    tinyxml2::XMLElement *pElem = m_XMLDoc.FirstChildElement("snapshot");
    m_eCurrentGameState
      = XMLHelper::EnumAttribute<CGameState::EGameStates>(
					      pElem,
					      "game_state",
					      CGameState::GS_MAIN_MENU);
    
    if (m_eCurrentGameState >= CGameState::EGameStates::GS_COUNT) {
      throw Ogre::Exception(Ogre::Exception::ERR_INVALIDPARAMS,
			    "Game state " + Ogre::StringConverter::toString(m_eCurrentGameState) + " is not valid!", __FILE__);
    }
    m_iVersion = XMLHelper::IntAttribute(pElem, "version", -1);

    if (m_iVersion != SNAPSHOT_VERSION) {
      throw Ogre::Exception(Ogre::Exception::ERR_INVALIDPARAMS,
			    "Snapshot version " + Ogre::StringConverter::toString(m_iVersion)
			    + " does not match with the required verion of " 
			    + Ogre::StringConverter::toString(SNAPSHOT_VERSION),
			    __FILE__);
    }
  }
Exemplo n.º 3
0
void TestingAnalysis::from_XML(const tinyxml2::XMLDocument& document)
{
    std::ostringstream buffer;

    const tinyxml2::XMLElement* root_element = document.FirstChildElement("TestingAnalysis");

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

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

    // Display

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

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

       try
       {
          set_display(new_display_string != "0");
       }
       catch(const std::logic_error& e)
       {
          std::cout << e.what() << std::endl;
       }
    }
}
Exemplo n.º 4
0
void NormalizedSquaredError::from_XML(const tinyxml2::XMLDocument& document)
{
   const tinyxml2::XMLElement* root_element = document.FirstChildElement("NormalizedSquaredError");

   if(!root_element)
   {
      return;
   }

   const tinyxml2::XMLElement* display_element = root_element->FirstChildElement("Display");

   if(display_element)
   {
      const 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;		 
      }
   }
}
void IndependentParametersError::from_XML(const tinyxml2::XMLDocument& document)
{
    const tinyxml2::XMLElement* root_element = document.FirstChildElement("IndependentParametersError");

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

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

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

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

     if(display_element)
     {
        const 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;
        }
     }
  }
}
Exemplo n.º 6
0
void NumericalIntegration::from_XML(const tinyxml2::XMLDocument& document)
{
   const tinyxml2::XMLElement* root_element = document.FirstChildElement("NumericalIntegration");

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

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

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

   // Numerical integration method
   {
       const tinyxml2::XMLElement* element = root_element->FirstChildElement("NumericalIntegrationMethod");

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

          try
          {
             set_numerical_integration_method(new_numerical_integration_method);
          }
          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;
          }
       }
   }
}
Exemplo n.º 7
0
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;
        }
     }
  }
}
Exemplo n.º 8
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;
	}
Exemplo n.º 9
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;
        }
    }
}
Exemplo n.º 10
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));
	}
}
Exemplo n.º 11
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;
        }
     }
  }
}
Exemplo n.º 12
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;
}
Exemplo n.º 13
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;
        }
      }
    }
  }
}
Exemplo n.º 14
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;
}
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;
//           }
//        }
//    }

}
Exemplo n.º 16
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;
}
Exemplo n.º 17
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;
          }
       }
   }
}
Exemplo n.º 18
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);
}
Exemplo n.º 19
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++;
		}
	}


}
Exemplo n.º 20
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;
        }
     }
  }
}
Exemplo n.º 21
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;
        }
     }
  }
}
Exemplo n.º 22
0
//==============================================================================
void transformElementNamesToLowerCases(tinyxml2::XMLDocument& doc)
{
  auto firstEle = doc.FirstChildElement();
  if (firstEle)
    transformElementNamesToLowerCasesRecurse(firstEle);
}
Exemplo n.º 23
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();
         }
     }

   }
}
Exemplo n.º 24
0
void MissingValues::from_XML(const tinyxml2::XMLDocument& document)
{
    std::ostringstream buffer;

    // Missing values element

    const tinyxml2::XMLElement* missing_values_element = document.FirstChildElement("MissingValues");

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

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

    // Instances number

    const tinyxml2::XMLElement* instances_number_element = missing_values_element->FirstChildElement("InstancesNumber");

    if(!instances_number_element)
    {
        buffer << "OpenNN Exception: MissingValues class.\n"
               << "void from_XML(const tinyxml2::XMLDocument&) method.\n"
               << "Pointer to instances number is NULL.\n";

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

    instances_number = atoi(instances_number_element->GetText());

    // Variables number

    const tinyxml2::XMLElement* variables_number_element = missing_values_element->FirstChildElement("VariablesNumber");

    if(!variables_number_element)
    {
        buffer << "OpenNN Exception: MissingValues class.\n"
               << "void from_XML(const tinyxml2::XMLDocument&) method.\n"
               << "Pointer to variables number is NULL.\n";

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

    variables_number = atoi(variables_number_element->GetText());

    // Scrubbing method

    const tinyxml2::XMLElement* scrubbing_method_element = missing_values_element->FirstChildElement("ScrubbingMethod");

    if(!scrubbing_method_element)
    {
        buffer << "OpenNN Exception: MissingValues class.\n"
               << "void from_XML(const tinyxml2::XMLDocument&) method.\n"
               << "Pointer to scrubbing method element is NULL.\n";

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

    const std::string scrubbing_method_string = scrubbing_method_element->GetText();

    set_scrubbing_method(scrubbing_method_string);

    // Missing values number

    const tinyxml2::XMLElement* missing_values_number_element = missing_values_element->FirstChildElement("MissingValuesNumber");

    if(!missing_values_number_element)
    {
        buffer << "OpenNN Exception: MissingValues class.\n"
               << "void from_XML(const tinyxml2::XMLDocument&) method.\n"
               << "Pointer to missing values number is NULL.\n";

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

    const size_t missing_values_number = atoi(missing_values_number_element->GetText());

    set_missing_values_number(missing_values_number);

    if(missing_values_number <= 0)
    {
        return;
    }

    // Items

    unsigned index = 0;

    const tinyxml2::XMLElement* start_element = missing_values_number_element;

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

        if(!item_element)
        {
            buffer << "OpenNN Exception: MissingValues 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: MissingValues class.\n"
                   << "void from_XML(const tinyxml2::XMLElement*) method.\n"
                   << "Index " << index << " is not correct.\n";

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

        // Instance index

        const tinyxml2::XMLElement* instance_index_element = item_element->FirstChildElement("InstanceIndex");

        if(!instance_index_element)
        {
            buffer << "OpenNN Exception: MissingValues class.\n"
                   << "void from_XML(const tinyxml2::XMLElement*) method.\n"
                   << "Pointer to instance index element is NULL.\n";

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

        const size_t instance_index = atoi(instance_index_element->GetText());

        items[i].instance_index = instance_index;

        // Variable index

        const tinyxml2::XMLElement* variable_index_element = item_element->FirstChildElement("VariableIndex");

        if(!instance_index_element)
        {
            buffer << "OpenNN Exception: MissingValues class.\n"
                   << "void from_XML(const tinyxml2::XMLElement*) method.\n"
                   << "Pointer to variable index element is NULL.\n";

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

        const size_t variable_index = atoi(variable_index_element->GetText());

        items[i].variable_index = variable_index;
    }
}
Exemplo n.º 25
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;
           }
        }
    }
}
Exemplo n.º 26
0
bool Header::build(tinyxml2::XMLDocument &doc, tinyxml2::XMLElement *parent, const int number) const
{
    if(!isBuildable() || !m_destinationNames.isBuildable())
    return false;

    XMLElement *elm = doc.NewElement(HEADER_BALISE_NAME.c_str());
    if(elm == 0)
    return false;

    XMLElement* src = doc.NewElement(SRC_BALISE_NAME.c_str());
    if(src == 0)
    return false;

    XMLElement* cmd = doc.NewElement(CMD_BALISE_NAME.c_str());
    if(cmd == 0)
    return false;

    {
        string str(escapeCharacters(m_sourceName));
        src->SetText(str.c_str());
        str = escapeCharacters(m_commandName);
        cmd->SetText(str.c_str());
    }

    elm->InsertEndChild(src);

    if(!m_destinationNames.build(doc, elm))
    return false;

    elm->InsertEndChild(cmd);

    XMLElement *antecedant(0);
    antecedant = (parent != 0 ? parent->FirstChildElement(HEADER_BALISE_NAME.c_str()) : doc.FirstChildElement(HEADER_BALISE_NAME.c_str()));
    for(int i(0), c(number - 1); i < c && antecedant != 0; ++i)
    antecedant = antecedant->NextSiblingElement(HEADER_BALISE_NAME.c_str());


    if(parent != 0)
    {
        if(antecedant != 0)
        parent->InsertAfterChild(antecedant, elm);
        else
        parent->InsertEndChild(elm);
    }
    else
    {
        if(antecedant != 0)
        doc.InsertAfterChild(antecedant, elm);
        else
        doc.InsertEndChild(elm);
    }

    return true;
}