Example #1
0
void CIRTranslator::MapRemote(TiXmlNode *pRemote, const std::string &szDevice)
{
  CLog::Log(LOGINFO, "* Adding remote mapping for device '%s'", szDevice.c_str());

  std::vector<std::string> remoteNames;

  auto it = m_irRemotesMap.find(szDevice);
  if (it == m_irRemotesMap.end())
    m_irRemotesMap[szDevice].reset(new IRButtonMap);

  std::shared_ptr<IRButtonMap>& buttons = m_irRemotesMap[szDevice];

  TiXmlElement *pButton = pRemote->FirstChildElement();
  while (pButton != nullptr)
  {
    if (!pButton->NoChildren())
    {
      if (pButton->ValueStr() == "altname")
        remoteNames.push_back(pButton->FirstChild()->ValueStr());
      else
        (*buttons)[pButton->FirstChild()->ValueStr()] = pButton->ValueStr();
    }
    pButton = pButton->NextSiblingElement();
  }

  for (const auto& remoteName : remoteNames)
  {
    CLog::Log(LOGINFO, "* Linking remote mapping for '%s' to '%s'", szDevice.c_str(), remoteName.c_str());
    m_irRemotesMap[remoteName] = buttons;
  }
}
void ModelLibrary::LoadAnimsFromXML(TiXmlElement* parent, vector<SAnimation*>* anims, vector<SSound*>* sounds)
{
	TiXmlElement* child;
	for(child = parent->FirstChildElement(); child; child = child->NextSiblingElement())
	{
		if (child->ValueStr() == "sound") 
		{
			SSound* s = new SSound();
			s->filename = child->Attribute(FILENAME);
			child->Attribute(SOUNDLOOP, &s->soundloop);
			sounds->push_back(s);

			Ogre::LogManager::getSingleton().logMessage("XML: SOUND: "+s->filename);
		}
		else if (child->ValueStr() == "animation")
		{
			SAnimation* a = new SAnimation();
			a->name = child->Attribute(ANIMNAME);
			child->Attribute(FRAMES, &a->frames);
			child->Attribute(LOOP, &a->loop);
			anims->push_back(a);

			Ogre::LogManager::getSingleton().logMessage("XML: ANIM: "+a->name);
		}
		else
		{
			Ogre::LogManager::getSingleton().logMessage("XML: subPart : should never get here *giggles*");
			Ogre::LogManager::getSingleton().logMessage("XML: subPart : culporate: "+child->ValueStr());
		};
	}
}
Example #3
0
TiXmlElement *NextSiblingScraperElement(TiXmlElement *element)
{
  for (TiXmlElement *next = element->NextSiblingElement(); next; next = next->NextSiblingElement())
  {
#ifdef HAVE_LIBXSLT
    if (next->ValueStr() == "XSLT")
      return next;
#endif
    if (next->ValueStr() == "RegExp")
      return next;
  }
  return NULL;
}
Example #4
0
TiXmlElement *FirstChildScraperElement(TiXmlElement *element)
{
  for (TiXmlElement *child = element->FirstChildElement(); child; child = child->NextSiblingElement())
  {
#ifdef HAVE_LIBXSLT
    if (child->ValueStr() == "XSLT")
      return child;
#endif
    if (child->ValueStr() == "RegExp")
      return child;
  }
  return NULL;
}
Example #5
0
RobotInterface::ParamList RobotInterface::XMLReader::Private::readParamListTag(TiXmlElement* paramListElem)
{
    if (paramListElem->ValueStr().compare("paramlist") != 0) {
        SYNTAX_ERROR(paramListElem->Row()) << "Expected \"paramlist\". Found" << paramListElem->ValueStr();
    }

    ParamList params;
    Param mainparam;

    if (paramListElem->QueryStringAttribute("name", &mainparam.name()) != TIXML_SUCCESS) {
        SYNTAX_ERROR(paramListElem->Row()) << "\"paramlist\" element should contain the \"name\" attribute";
    }

    params.push_back(mainparam);

    // yDebug() << "Found paramlist [" << params.at(0).name() << "]";

    for (TiXmlElement* childElem = paramListElem->FirstChildElement(); childElem != 0; childElem = childElem->NextSiblingElement()) {
        if (childElem->ValueStr().compare("elem") != 0) {
            SYNTAX_ERROR(childElem->Row()) << "Expected \"elem\". Found" << childElem->ValueStr();
        }

        Param childParam;

        if (childElem->QueryStringAttribute("name", &childParam.name()) != TIXML_SUCCESS) {
            SYNTAX_ERROR(childElem->Row()) << "\"elem\" element should contain the \"name\" attribute";
        }

        const char *valueText = childElem->GetText();
        if (!valueText) {
            SYNTAX_ERROR(childElem->Row()) << "\"elem\" element should have a value [ \"name\" = " << childParam.name() << "]";
        }
        childParam.value() = valueText;

        params.push_back(childParam);
    }

    if (params.empty()) {
        SYNTAX_ERROR(paramListElem->Row()) << "\"paramlist\" cannot be empty";
    }

    // +1 skips the first element, that is the main param
    for (ParamList::iterator it = params.begin() + 1; it != params.end(); ++it) {
        Param &param = *it;
        params.at(0).value() += (params.at(0).value().empty() ? "(" : " ") + param.name();
    }
    params.at(0).value() += ")";

    // yDebug() << params;
    return params;
}
Example #6
0
RobotInterface::Robot& RobotInterface::XMLReader::Private::readRobotTag(TiXmlElement *robotElem)
{
    if (robotElem->ValueStr().compare("robot") != 0) {
        SYNTAX_ERROR(robotElem->Row()) << "Root element should be \"robot\". Found" << robotElem->ValueStr();
    }

    if (robotElem->QueryStringAttribute("name", &robot.name()) != TIXML_SUCCESS) {
        SYNTAX_ERROR(robotElem->Row()) << "\"robot\" element should contain the \"name\" attribute";
    }

#if TINYXML_UNSIGNED_INT_BUG
    if (robotElem->QueryUnsignedAttribute("build", &robot.build()) != TIXML_SUCCESS) {
        // No build attribute. Assuming build="0"
        SYNTAX_WARNING(robotElem->Row()) << "\"robot\" element should contain the \"build\" attribute [unsigned int]. Assuming 0";
    }
#else
    int tmp;
    if (robotElem->QueryIntAttribute("build", &tmp) != TIXML_SUCCESS || tmp < 0) {
        // No build attribute. Assuming build="0"
        SYNTAX_WARNING(robotElem->Row()) << "\"robot\" element should contain the \"build\" attribute [unsigned int]. Assuming 0";
        tmp = 0;
    }
    robot.build() = (unsigned)tmp;
#endif

    if (robotElem->QueryStringAttribute("portprefix", &robot.portprefix()) != TIXML_SUCCESS) {
        SYNTAX_WARNING(robotElem->Row()) << "\"robot\" element should contain the \"portprefix\" attribute. Using \"name\" attribute";
        robot.portprefix() = robot.name();
    }

    // yDebug() << "Found robot [" << robot.name() << "] build [" << robot.build() << "] portprefix [" << robot.portprefix() << "]";

    for (TiXmlElement* childElem = robotElem->FirstChildElement(); childElem != 0; childElem = childElem->NextSiblingElement()) {
        if (childElem->ValueStr().compare("device") == 0 || childElem->ValueStr().compare("devices") == 0) {
            DeviceList childDevices = readDevices(childElem);
            for (DeviceList::const_iterator it = childDevices.begin(); it != childDevices.end(); ++it) {
                robot.devices().push_back(*it);
            }
        } else {
            ParamList childParams = readParams(childElem);
            for (ParamList::const_iterator it = childParams.begin(); it != childParams.end(); ++it) {
                robot.params().push_back(*it);
            }
        }
    }

    return robot;
}
Example #7
0
bool CController::LoadLayout(void)
{
  if (!m_bLoaded)
  {
    std::string strLayoutXmlPath = LibPath();

    CLog::Log(LOGINFO, "Loading controller layout: %s", CURL::GetRedacted(strLayoutXmlPath).c_str());

    CXBMCTinyXML xmlDoc;
    if (!xmlDoc.LoadFile(strLayoutXmlPath))
    {
      CLog::Log(LOGDEBUG, "Unable to load file: %s at line %d", xmlDoc.ErrorDesc(), xmlDoc.ErrorRow());
      return false;
    }

    TiXmlElement* pRootElement = xmlDoc.RootElement();
    if (!pRootElement || pRootElement->NoChildren() || pRootElement->ValueStr() != LAYOUT_XML_ROOT)
    {
      CLog::Log(LOGERROR, "Can't find root <%s> tag", LAYOUT_XML_ROOT);
      return false;
    }

    m_layout->Deserialize(pRootElement, this, m_features);
    if (m_layout->IsValid(true))
    {
      m_bLoaded = true;
    }
    else
    {
      m_layout->Reset();
    }
  }

  return m_bLoaded;
}
Example #8
0
bool html_parse::_parse(TiXmlDocument& doc)
{
    TiXmlElement* rootElement = doc.RootElement();
    if (!rootElement)
    {
        return false;
    }

    std::string rootName = rootElement->ValueStr();
    if (rootName.empty()
        || rootName != "html")
    {
        return false;
    }

    for (TiXmlNode* nodeRoot = rootElement->FirstChildElement();
        nodeRoot != nullptr;
        nodeRoot = nodeRoot->NextSiblingElement())
    {
        html_object* object = new html_object;
        if (!object)
        {
            continue;
        }

        if (object->parse(nodeRoot))
        {
            m_htmlElement.push_back(object);
        }
    }
    return true;
}
Example #9
0
   virtual void process(TiXmlElement* root, int version)
   {
      static_cast<void>(version);
      std::string mngr;
      utilib::get_string_attribute( root, "process_manager", mngr, 
                            ExecuteManager::default_process_mngr );
      ExecuteMngr().set_process_manager(mngr);
      

      // each child element should be a valid command...
      TiXmlElement* node = root->FirstChildElement();

      // special case: if it is an empty element, just execute the last
      // solver
      if ( node == NULL )
      {
         string solver = SolverMngr().get_newest_solver();
         if ( ! solver.empty() )
            ExecuteMngr().run_command(string("solve:") + solver);
         return;
      }
      
      int rank;
      int myRank = ExecuteMngr().rank();

      // step through all the commands
      for( ; node != NULL; node = node->NextSiblingElement() )
      {
         utilib::get_num_attribute( node, "rank", rank, ExecuteManager::local );
         if (( rank == ExecuteManager::local ) || ( rank == myRank ))
            ExecuteMngr().run_command(node->ValueStr(), rank, node);
      }
   }
Example #10
0
void CSkinInfo::SettingOptionsSkinFontsFiller(const CSetting *setting, std::vector< std::pair<std::string, std::string> > &list, std::string &current)
{
  std::string strPath = g_SkinInfo->GetSkinPath("Font.xml");

  CXBMCTinyXML xmlDoc;
  if (!xmlDoc.LoadFile(strPath))
  {
    CLog::Log(LOGERROR, "FillInSkinFonts: Couldn't load %s", strPath.c_str());
    return;
  }

  TiXmlElement* pRootElement = xmlDoc.RootElement();

  std::string strValue = pRootElement->ValueStr();
  if (strValue != "fonts")
  {
    CLog::Log(LOGERROR, "FillInSkinFonts: file %s doesn't start with <fonts>", strPath.c_str());
    return;
  }

  const TiXmlNode *pChild = pRootElement->FirstChild();
  strValue = pChild->ValueStr();
  if (strValue == "fontset")
  {
    while (pChild)
    {
      strValue = pChild->ValueStr();
      if (strValue == "fontset")
      {
        const char* idAttr = ((TiXmlElement*) pChild)->Attribute("id");
        const char* idLocAttr = ((TiXmlElement*) pChild)->Attribute("idloc");
        const char* unicodeAttr = ((TiXmlElement*) pChild)->Attribute("unicode");

        bool isUnicode = (unicodeAttr && stricmp(unicodeAttr, "true") == 0);

        bool isAllowed = true;
        if (g_langInfo.ForceUnicodeFont() && !isUnicode)
          isAllowed = false;

        if (idAttr != NULL && isAllowed)
        {
          if (idLocAttr)
            list.push_back(make_pair(g_localizeStrings.Get(atoi(idLocAttr)), idAttr));
          else
            list.push_back(make_pair(idAttr, idAttr));
        }
      }

      pChild = pChild->NextSibling();
    }
  }
  else
  {
    // Since no fontset is defined, there is no selection of a fontset, so disable the component
    list.push_back(make_pair(g_localizeStrings.Get(13278), ""));
  }
}
Example #11
0
bool Room::LoadFromXml(TiXmlElement *room_node)
{
    TiXmlElement *node = room_node->FirstChildElement();
    for(; node; node = node->NextSiblingElement())
    {
        if (node->ValueStr() == "calaos:input" ||
            node->ValueStr() == "calaos:output" ||
            node->ValueStr() == "calaos:internal" ||
            node->ValueStr() == "calaos:avr" ||
            node->ValueStr() == "calaos:camera" ||
            node->ValueStr() == "calaos:audio")
        {
            IOBase *io = IOFactory::Instance().CreateIO(node);
            if (io) AddIO(io);
        }
    }

    return true;
}
	ObjectSet::ObjectSet(string filename_p) {
		filename = filename_p;

		need_update = false;

		TiXmlDocument doc(filename);
		if (!doc.LoadFile()) {
			Error::addMessage(Error::FILE_NOT_FOUND, LIBGENS_FILE_H_ERROR_READ_FILE_BEFORE + filename + LIBGENS_FILE_H_ERROR_READ_FILE_AFTER);
			return;
		}

		name = filename;
		size_t sep = name.find(LIBGENS_OBJECT_SET_NAME);
		if (sep != std::string::npos) {
			name = name.substr(sep + 8, name.size() - sep - 8);
		}
	
		size_t dot = name.find(LIBGENS_OBJECT_SET_EXTENSION);
		if (dot != string::npos) {
			name = name.substr(0, dot);
		}

		TiXmlHandle hDoc(&doc);
		TiXmlElement* pElem;
		TiXmlHandle hRoot(0);

		pElem=hDoc.FirstChildElement().Element();
		if (!pElem) {
			Error::addMessage(Error::EXCEPTION, LIBGENS_OBJECT_H_ERROR_READ_SET_BEFORE + filename + LIBGENS_OBJECT_H_ERROR_READ_SET_AFTER);
			return;
		}
		
		// Go past SetObject
		pElem=pElem->FirstChildElement();
		for(pElem; pElem; pElem=pElem->NextSiblingElement()) {
			if (pElem->ValueStr() != LIBGENS_OBJECT_SET_LAYER_DEFINE) {
				Object *obj=new Object(pElem->ValueStr());
				obj->readXML(pElem);
				obj->setParentSet(this);
				objects.push_back(obj);
			}
		}
	}
Example #13
0
bool CRssReader::Parse(int iFeed)
{
    TiXmlElement* rootXmlNode = m_xml.RootElement();

    if (!rootXmlNode)
        return false;

    TiXmlElement* rssXmlNode = NULL;

    std::string strValue = rootXmlNode->ValueStr();
    if (strValue.find("rss") != std::string::npos ||
            strValue.find("rdf") != std::string::npos)
        rssXmlNode = rootXmlNode;
    else
    {
        // Unable to find root <rss> or <rdf> node
        return false;
    }

    TiXmlElement* channelXmlNode = rssXmlNode->FirstChildElement("channel");
    if (channelXmlNode)
    {
        TiXmlElement* titleNode = channelXmlNode->FirstChildElement("title");
        if (titleNode && !titleNode->NoChildren())
        {
            std::string strChannel = titleNode->FirstChild()->Value();
            std::wstring strChannelUnicode;
            g_charsetConverter.utf8ToW(strChannel, strChannelUnicode, m_rtlText);
            AddString(strChannelUnicode, RSS_COLOR_CHANNEL, iFeed);

            AddString(L":", RSS_COLOR_CHANNEL, iFeed);
            AddString(L" ", RSS_COLOR_CHANNEL, iFeed);
        }

        GetNewsItems(channelXmlNode,iFeed);
    }

    GetNewsItems(rssXmlNode,iFeed);

    // avoid trailing ' - '
    if (m_strFeed[iFeed].size() > 3 && m_strFeed[iFeed].substr(m_strFeed[iFeed].size() - 3) == L" - ")
    {
        if (m_rtlText)
        {
            m_strFeed[iFeed].erase(0, 3);
            m_strColors[iFeed].erase(0, 3);
        }
        else
        {
            m_strFeed[iFeed].erase(m_strFeed[iFeed].length() - 3);
            m_strColors[iFeed].erase(m_strColors[iFeed].length() - 3);
        }
    }
    return true;
}
Example #14
0
bool ModRules::load(string filename)
{
    std::string xmlBuffer;
    if (! JFileSystem::GetInstance()->readIntoString(filename, xmlBuffer))
    {
        DebugTrace("FATAL: cannot find modrules.xml");
        return false;
    }

    TiXmlDocument doc;
    doc.Parse(xmlBuffer.c_str());

    for (TiXmlNode* node = doc.FirstChild(); node; node = node->NextSibling())
    {
        TiXmlElement* element = node->ToElement();
        if (element != NULL)
        {
            if (element->ValueStr() == "menu")
            {
                menu.parse(element);
            }
            else if (element->ValueStr() == "general")
            {
                 general.parse(element);
            }
            else if (element->ValueStr() == "cards")
            {
                 cards.parse(element);
            }
            else if (element->ValueStr() == "game")
            {
                 game.parse(element);
            }
            else if (element->ValueStr() == "cardgui")
            {
                 cardgui.parse(element);
            }
        }
    }
    return true;
}
Example #15
0
//takes the current <ar> node pointer and gets the word and definition for it
//Then moves the pointer on to the next <ar> node (or 'end' if no more found)
//
//Note, I find the formatting of the definition within the node bizzarre as the
//definition can be split into several blocks, with nodes embedded with the text.
//Not the way I'd define a dictionary schema, but hey, its free and comprehensive
//so I can't really complain.
TiXmlElement* Words2::xdxfNextWord(TiXmlElement* ar, std::string &word, std::string &def)
{
	if (!_doc) return 0;

	TiXmlElement *tmpElement;
	TiXmlText *tmpText;

	TiXmlNode *child = 0;
	for( child = ar->FirstChild(); child; child = child->NextSibling() )
	{
//		std::string text = child->Value();
//		std::cout << "<k>" << text.c_str() << "</k> : " << std::endl;

		if (child->Type() == TiXmlNode::ELEMENT)
		{
			tmpElement = child->ToElement();
			if (tmpElement->ValueStr() == "k")
			{
				++_countXdxfWords;
				word = tmpElement->GetText();	//get the <k>WORD</k>
				pptxt::makeUpper(word);			//force to UPPER case (def tests against it, below)
			}
			//else ignore; dont care about <b> or <c> etc
		}
		else if (word.length() && child->Type() == TiXmlNode::TEXT)
		{
			tmpText = child->ToText();
			def = tmpText->Value();	//get the text (NOT in a <></> tag, wtf?

			//check if the def starts with the dictionary word.
			//Some xdxf dictionary defs I've seen do something like:
			//"abbacy n : the jurisdiction or office of an abbot"
			//where the "abbacy " part is not required for the game,
			//as it's already shown so try and remove it.
			std::string::size_type pos = def.find_first_of(" ");
			std::string prefix = def.substr(0,pos);	//may contain other chars, if so those words will stay
			pptxt::makeUpper(prefix);
			if (word == prefix)
				def = def.substr(pos);

			if (def.length() > MAX_REWORD_DESCRIPTION)
			{
				def.erase(MAX_REWORD_DESCRIPTION);
				def += "...";	//indicate it was cut short
			}
//			std::cout << word.c_str() << " - def: " << tmpstr << std::endl;

			break;	//out of for child loop as we now want next <ar> word and its def
		}
	}

	return ar->NextSiblingElement("ar");
}
Example #16
0
RobotInterface::Device RobotInterface::XMLReader::Private::readDeviceTag(TiXmlElement *deviceElem)
{
    const std::string &valueStr = deviceElem->ValueStr();

    if (valueStr.compare("device") != 0) {
        SYNTAX_ERROR(deviceElem->Row()) << "Expected \"device\". Found" << valueStr;
    }

    Device device;

    if (deviceElem->QueryStringAttribute("name", &device.name()) != TIXML_SUCCESS) {
        SYNTAX_ERROR(deviceElem->Row()) << "\"device\" element should contain the \"name\" attribute";
    }

    // yDebug() << "Found device [" << device.name() << "]";

    if (deviceElem->QueryStringAttribute("type", &device.type()) != TIXML_SUCCESS) {
        SYNTAX_ERROR(deviceElem->Row()) << "\"device\" element should contain the \"type\" attribute";
    }

    device.params().push_back(Param("robotName", robot.portprefix().c_str()));

    for (TiXmlElement* childElem = deviceElem->FirstChildElement(); childElem != 0; childElem = childElem->NextSiblingElement()) {
        if (childElem->ValueStr().compare("action") == 0 ||
            childElem->ValueStr().compare("actions") == 0) {
            ActionList childActions = readActions(childElem);
            for (ActionList::const_iterator it = childActions.begin(); it != childActions.end(); ++it) {
                device.actions().push_back(*it);
            }
        } else {
            ParamList childParams = readParams(childElem);
            for (ParamList::const_iterator it = childParams.begin(); it != childParams.end(); ++it) {
                device.params().push_back(*it);
            }
        }
    }

    // yDebug() << device;
    return device;
}
bool ModelLibrary::Load(Ogre::SceneManager* sc, string filename)
{   
	if (models)
	{
		for(int i = 0; i < models->size(); i++)
		{
			delete (*models)[i];
		}
		delete models;
	}
	
	models = new vector<SModel*>();
	
	TiXmlDocument doc(filename);
	
	if(doc.LoadFile())
	{
		Ogre::LogManager::getSingleton().logMessage("XML: Models loaded");
	}
	else
	{
		Ogre::LogManager::getSingleton().logMessage("XML: Foutje");
		if(doc.Error())
		{
			Ogre::LogManager::getSingleton().logMessage("XML: Fout");
			Ogre::LogManager::getSingleton().logMessage(filename);
			Ogre::LogManager::getSingleton().logMessage(doc.ErrorDesc());
		}
		return false;
	}
	
	TiXmlHandle hDoc(&doc);
	TiXmlElement* pElement;
	TiXmlHandle hRoot(0);
	
	pElement = hDoc.FirstChildElement().Element(); //Get the root element.
	
	// Check if the root element is correct.
	if( !(pElement->ValueStr() == XMLROOT) )
	{
		Ogre::LogManager::getSingleton().logMessage("XML: Wrong root element");
		return false;
	}
	
	hRoot = TiXmlHandle(pElement); // Store the root element.
	
	// Load models.
	ModelLibrary::LoadModelsFromXML(sc, pElement);

	return true;
}
Example #18
0
GeometrySharedPtr parseGeometry(TiXmlElement *g)
{
  GeometrySharedPtr geom;
  if (!g) return geom;

  TiXmlElement *shape = g->FirstChildElement();
  if (!shape)
  {
    logError("Geometry tag contains no child element.");
    return geom;
  }

  std::string type_name = shape->ValueStr();
  if (type_name == "sphere")
  {
    Sphere *s = new Sphere();
    geom.reset(s);
    if (parseSphere(*s, shape))
      return geom;
  }
  else if (type_name == "box")
  {
    Box *b = new Box();
    geom.reset(b);
    if (parseBox(*b, shape))
      return geom;
  }
  else if (type_name == "cylinder")
  {
    Cylinder *c = new Cylinder();
    geom.reset(c);
    if (parseCylinder(*c, shape))
      return geom;
  }
  else if (type_name == "mesh")
  {
    Mesh *m = new Mesh();
    geom.reset(m);
    if (parseMesh(*m, shape))
      return geom;    
  }
  else
  {
    logError("Unknown geometry type '%s'", type_name.c_str());
    return geom;
  }
  
  return GeometrySharedPtr();
}
Example #19
0
	void EMMMaterial::readXML(TiXmlElement *root) {
		string temp_str = "";
		memset(name, 0, 32);
		memset(shader_name, 0, 32);
		root->QueryStringAttribute("name", &temp_str);
		strcpy(name, temp_str.c_str());
		root->QueryStringAttribute("shader_name", &temp_str);
		strcpy(shader_name, temp_str.c_str());

		TiXmlElement *pElem = root->FirstChildElement();
		for (pElem; pElem; pElem = pElem->NextSiblingElement()) {
			string element_name = pElem->ValueStr();

			if (element_name == "EMMParameter") {
				EMMParameter *parameter = new EMMParameter();
				parameter->readXML(pElem);
				parameters.push_back(parameter);
			}
		}
	}
Example #20
0
	bool EMM::load(string filename) {
		name = nameFromFilenameNoExtension(filename, true);

		if (filename.find(".xml") != string::npos) {
			TiXmlDocument doc(filename);
			if (!doc.LoadFile()) {
				return false;
			}

			TiXmlHandle hDoc(&doc);
			TiXmlElement* pElem;
			TiXmlHandle hRoot(0);

			pElem = hDoc.FirstChildElement().Element();
			if (!pElem) {
				return false;
			}

			pElem = pElem->FirstChildElement();
			for (pElem; pElem; pElem = pElem->NextSiblingElement()) {
				string element_name = pElem->ValueStr();

				if (element_name == "EMMMaterial") {
					EMMMaterial *material = new EMMMaterial();
					material->readXML(pElem);
					materials.push_back(material);
				}
			}
		}
		else {
			File file(filename, LIBXENOVERSE_FILE_READ_BINARY);

			if (file.valid() && file.readHeader(LIBXENOVERSE_EMM_SIGNATURE)) {
				read(&file);
				file.close();
			}
			else return false;
		}

		return true;
	}
Example #21
0
bool MechanismControlNode::spawnController(
  robot_srvs::SpawnController::request &req,
  robot_srvs::SpawnController::response &resp)
{
  TiXmlDocument doc;
  doc.Parse(req.xml_config.c_str());

  std::vector<uint8_t> oks;
  std::vector<std::string> names;

  TiXmlElement *config = doc.RootElement();
  if (!config)
  {
    ROS_ERROR("The XML given to SpawnController could not be parsed");
    return false;
  }
  if (config->ValueStr() != "controllers" &&
      config->ValueStr() != "controller")
  {
    ROS_ERROR("The XML given to SpawnController must have either \"controller\" or \
\"controllers\" as the root tag");
    return false;
  }
Example #22
0
void CScraperParser::ParseNext(TiXmlElement* element)
{
  TiXmlElement* pReg = element;
  while (pReg)
  {
    TiXmlElement* pChildReg = FirstChildScraperElement(pReg);
    if (pChildReg)
      ParseNext(pChildReg);
    else
    {
      TiXmlElement* pChildReg = pReg->FirstChildElement("clear");
      if (pChildReg)
        ParseNext(pChildReg);
    }

    int iDest = 1;
    bool bAppend = false;
    const char* szDest = pReg->Attribute("dest");
    if (szDest && strlen(szDest))
    {
      if (szDest[strlen(szDest)-1] == '+')
        bAppend = true;

      iDest = atoi(szDest);
    }

    const char *szInput = pReg->Attribute("input");
    std::string strInput;
    if (szInput)
    {
      strInput = szInput;
      ReplaceBuffers(strInput);
    }
    else
      strInput = m_param[0];

    const char* szConditional = pReg->Attribute("conditional");
    bool bExecute = true;
    if (szConditional)
    {
      bool bInverse=false;
      if (szConditional[0] == '!')
      {
        bInverse = true;
        szConditional++;
      }
      std::string strSetting;
      if (m_scraper && m_scraper->HasSettings())
        strSetting = m_scraper->GetSetting(szConditional);
      bExecute = bInverse != (strSetting == "true");
    }

    if (bExecute)
    {
      if (iDest-1 < MAX_SCRAPER_BUFFERS && iDest-1 > -1)
      {
#ifdef HAVE_LIBXSLT
        if (pReg->ValueStr() == "XSLT")
          ParseXSLT(strInput, m_param[iDest - 1], pReg, bAppend);
        else
#endif
          ParseExpression(strInput, m_param[iDest - 1],pReg,bAppend);
      }
      else
        CLog::Log(LOGERROR,"CScraperParser::ParseNext: destination buffer "
                           "out of bounds, skipping expression");
    }
    pReg = NextSiblingScraperElement(pReg);
  }
}
Example #23
0
bool FSMDescrip::loadFromXML(const std::string& xmlName, bool verbose) {
  logger << Logger::INFO_MSG << "Loading behavior from xml: " << xmlName;
  TiXmlDocument xml(xmlName);
  bool loadOkay = xml.LoadFile();

  if (!loadOkay) {
    logger << Logger::ERR_MSG << "Could not load behavior configuration xml (";
    logger << xmlName << ") due to xml syntax errors.\n";
    logger << "\t" << xml.ErrorDesc();
    return false;
  }

  TiXmlElement* popNode = xml.RootElement();
  if (!popNode) {
    logger << Logger::ERR_MSG << "Root element does not exist.";
    return false;
  }
  if (popNode->ValueStr() != "BFSM") {
    logger << Logger::ERR_MSG << "Root element value should be \"BFSM\".";
    return false;
  }

  std::string absPath;
  os::path::absPath(xmlName, absPath);
  std::string junk;
  os::path::split(absPath, _behaviorFldr, junk);
  logger << Logger::INFO_MSG << "Behavior root: " << _behaviorFldr;

  TiXmlElement* child;
  for (child = popNode->FirstChildElement(); child; child = child->NextSiblingElement()) {
    if (child->ValueStr() == "GoalSet") {
      int i;
      if (!child->Attribute("id", &i)) {
        logger << Logger::ERR_MSG << "GoalSet requires an \"id\" property.";
        return false;
      }
      size_t setID = static_cast<size_t>(i);
      // confirm that the id doesn't already exist
      if (_goalSets.find(setID) != _goalSets.end()) {
        logger << Logger::WARN_MSG << "Found multiple GoalSets with the same id: ";
        logger << setID << ".\n\tGoal definitions will be merged!";
      } else {
        _goalSets[setID] = new GoalSet();
      }
      TiXmlElement* goalNode;
      for (goalNode = child->FirstChildElement(); goalNode;
           goalNode = goalNode->NextSiblingElement()) {
        if (goalNode->ValueStr() == "Goal") {
          Goal* goal = parseGoal(goalNode, _behaviorFldr);
          if (goal == 0x0) {
            logger << Logger::ERR_MSG << "Error parsing a goal description.";
            return false;
          }
          // Make sure that this goal doesn't duplicate previous goal ids
          if (!_goalSets[setID]->addGoal(goal->getID(), goal)) {
            logger << Logger::ERR_MSG << "GoalSet " << setID;
            logger << " has two goals with the identifier: " << goal->getID();
            logger << " (second appears on line " << goalNode->Row() << ").";
            return false;
          }
        } else {
          logger << Logger::WARN_MSG
                 << "Found a child tag of the GoalSet that "
                    "is not a \"Goal\" tag on line "
                 << goalNode->Row()
                 << ". "
                    "It will be ignored.";
        }
      }

    } else if (child->ValueStr() == "State") {
      if (!parseState(child, _behaviorFldr, _states)) {
        return false;
      }
    } else if (child->ValueStr() == "Transition") {
      std::string from;
      Transition* trans = parseTransition(child, _behaviorFldr, from);
      if (trans == 0x0) {
        return false;
      }

      addTransition(from, trans);
    } else if (child->ValueStr() == "VelModifier") {
      VelModifier* vel = parseVelModifier(child, _behaviorFldr);
      if (vel == 0x0) {
        return false;
      } else {
        _velModifiers.push_back(vel);
      }
    } else if (child->ValueStr() == "Task") {
      Task* task = parseTask(child, _behaviorFldr);
      if (task == 0x0) {
        logger << Logger::WARN_MSG << "User-specified Task on line ";
        logger << child->Row()
               << " couldn't be instantiated.  "
                  "It is being ignored.";
      } else {
        _tasks.push_back(task);
      }
    } else if (child->ValueStr() == "EventSystem") {
      if (!EVENT_SYSTEM->parseEvents(child, _behaviorFldr)) {
        return false;
      }
    } else {
      logger << Logger::ERR_MSG << "Unrecognized tag as child of <Population>: <";
      logger << child->ValueStr() << ">.";
      return false;
    }
  }

  return true;
}
Example #24
0
	/// Visit an element.
	virtual bool VisitEnter( const TiXmlElement& element, const TiXmlAttribute* attribute)
	{
		if(element.ValueStr() == "world")
		{
			if(element.Parent() != element.GetDocument()) return false;
			return true;
		}
		else if(element.ValueStr() == "materials")
		{
			return true;
		}
		else if(element.ValueStr() == "material")
		{
            return true;
		}
		else if(element.ValueStr() == "bodies")
		{
			if(element.Parent()->ValueStr() != "world") return false;
			return true;
		}
		else if(element.ValueStr() == "ground")
		{
			if(element.Parent()->ValueStr() != "bodies") return false;
			assert(m_curBody == NULL);

            m_curBody = new World::Ground();
			return true;
		}
		else if(element.ValueStr() == "box")
		{
			if(element.Parent()->ValueStr() != "bodies") return false;
			assert(m_curBody == NULL);

			double hx = 0.5;
			double hy = 0.5;
			double hz = 0.5;
			
			element.Attribute("hx", &hx);
			element.Attribute("hy", &hy);
			element.Attribute("hz", &hz);

            World::Cube* cube = new World::Cube();
            cube->hx = hx;
            cube->hy = hy;
            cube->hz = hz;
            m_curBody = cube;
			return true;
		}
		else if(element.ValueStr() == "sphere")
		{
			if(element.Parent()->ValueStr() != "bodies") return false;
			assert(m_curBody == NULL);

			double r = 1;
			element.Attribute("r", &r);

            World::Sphere* sphere = new World::Sphere();
            sphere->r = r;
            m_curBody = sphere;
			return true;
		}
		else if(element.ValueStr() == "cylinder")
		{
			if(element.Parent()->ValueStr() != "bodies") return false;
			assert(m_curBody == NULL);

			double r = 1;
            double startx, starty, startz;
            double endx, endy, endz;
			element.Attribute("r", &r);

            element.Attribute("sx", &startx);
			element.Attribute("sy", &starty);
			element.Attribute("sz", &startz);

            element.Attribute("ex", &endx);
			element.Attribute("ey", &endy);
			element.Attribute("ez", &endz);

            World::Cylinder* cylinder = new World::Cylinder();
            cylinder->start = vec3(startx, starty, startz);
            cylinder->end = vec3(endx, endy, endz);
            cylinder->r = r;
            m_curBody = cylinder;
			return true;
		}
		else if(element.ValueStr() == "cone")
		{
			if(element.Parent()->ValueStr() != "bodies") return false;
			assert(m_curBody == NULL);
			double r = 0.05;
			double startx, starty, startz;
			double endx, endy, endz;

			element.Attribute("r", &r);
			
			element.Attribute("sx",&startx);
			element.Attribute("sy",&starty);
			element.Attribute("sz",&startz);
			
			element.Attribute("ex", &endx);
			element.Attribute("ey", &endy);
			element.Attribute("ez", &endz);

			World::Cone* cone = new World::Cone();
			cone->start = vec3(startx, starty, startz);
			cone->end = vec3(endx, endy, endz);
			cone->r = r;
			m_curBody = cone;
			return true;
		}
		else if(element.ValueStr() == "pos")
		{
			if(!IsBody(element.Parent())) return false;
			assert(m_curBody != NULL);
			double x = 0;
			double y = 0;
			double z = 0;

			element.Attribute("x", &x);
			element.Attribute("y", &y);
			element.Attribute("z", &z);

			m_curBody->pos = vec3(float(x), float(y), float(z));
			return true;
		}
		else if(element.ValueStr() == "vel")
		{
            return false;
		}
		else if(element.ValueStr() == "ori")
		{
            return false;
		}
		else if(element.ValueStr() == "avel")
		{
            return false;
		}
		else if(element.ValueStr() == "bodymaterial")
		{
            return false;
		}
		else
		{
			return false;
		}

		assert(false); // we should never get here
		return false;
	}
Example #25
0
	/// Visit an element.
	virtual bool VisitExit( const TiXmlElement& element)
	{
		if(element.ValueStr() == "world")
		{
			return true;
		}
		else if(element.ValueStr() == "materials")
		{
			return true;
		}
		else if(element.ValueStr() == "material")
		{
			return true;
		}
		else if(element.ValueStr() == "bodies")
		{
			return true;
		}
		else if(element.ValueStr() == "ground")
		{
			m_world->m_shapes.push_back(m_curBody);
			m_curBody = NULL;
			return true;
		}
		else if(element.ValueStr() == "box")
		{
			m_world->m_shapes.push_back(m_curBody);
			m_curBody = NULL;
			return true;
		}
		else if(element.ValueStr() == "sphere")
		{
			m_world->m_shapes.push_back(m_curBody);
			m_curBody = NULL;
			return true;
		}
		else if(element.ValueStr() == "cylinder")
		{
			m_world->m_shapes.push_back(m_curBody);
			m_curBody = NULL;
			return true;
		}
		else if(element.ValueStr() == "cone")
		{
			m_world->m_shapes.push_back(m_curBody);
			m_curBody = NULL;
			return true;
		}
		else if(element.ValueStr() == "pos")
		{
			return true;
		}
		else if(element.ValueStr() == "vel")
		{
			return true;
		}
		else if(element.ValueStr() == "ori")
		{
			return true;
		}
		else if(element.ValueStr() == "avel")
		{
			return true;
		}
		else if(element.ValueStr() == "bodymaterial")
		{
			return true;
		}
		else
		{
			return false;
		}
	}