コード例 #1
0
ファイル: Xml.cpp プロジェクト: Ahbee/Cinder
void parseItem( const rapidxml::xml_node<> &node, XmlTree *parent, XmlTree *result, const XmlTree::ParseOptions &options )
{
	*result = XmlTree( node.name(), node.value(), parent );
	for( const rapidxml::xml_node<> *item = node.first_node(); item; item = item->next_sibling() ) {
		XmlTree::NodeType type;
		switch( item->type() ) {
			case rapidxml::node_element:
				type = XmlTree::NODE_ELEMENT;
			break;
			case rapidxml::node_cdata: {
				if( options.getCollapseCData() ) {
					result->setValue( result->getValue() + item->value() );
					continue;
				}
				else {
					type = XmlTree::NODE_CDATA;
				}
			}
			break;						
			case rapidxml::node_comment:
				type = XmlTree::NODE_COMMENT;
			break;
			case rapidxml::node_doctype: {
				result->setDocType( item->value() );
				continue;
			}
			case rapidxml::node_data: {
				if( ! options.getIgnoreDataChildren() )
					type = XmlTree::NODE_DATA;
				else
					continue;
			}
			break;
			default:
				continue;
		}
		
		result->getChildren().push_back( unique_ptr<XmlTree>( new XmlTree ) );
		parseItem( *item, result, result->getChildren().back().get(), options );
		result->getChildren().back()->setNodeType( type );
	}

	for( rapidxml::xml_attribute<> *attr = node.first_attribute(); attr; attr = attr->next_attribute() )
		result->getAttributes().push_back( XmlTree::Attr( result, attr->name(), attr->value() ) );
}
コード例 #2
0
ファイル: XmlNode.hpp プロジェクト: yuang1516/dodge
//===========================================
// XmlNode::getString
//===========================================
inline std::string XmlNode::getString() const {
   if (isNull())
      throw XmlException("Node is NULL", __FILE__, __LINE__);

   return std::string(m_node->value(), m_node->value_size());
}
コード例 #3
0
ファイル: Frame.cpp プロジェクト: cesarl/AllegroSpriter
bool					Frame::parseXml(const rapidxml::xml_node<char> &node,
							std::string const &rootPath)
{
  //read name
  rapidxml::xml_node<char>		*nameNode = node.first_node("name");
  if (!nameNode)
    {
      std::cerr << "Error: Invalid Spriter file: Frame without name!" << std::endl;
      return false;
    }

  this->name_ = nameNode->value();

  //read and create sprites
  for (rapidxml::xml_node<char> *curNode = node.first_node("sprite");
       curNode;
       curNode = curNode->next_sibling("sprite"))
    {
      Sprite				*sprite;

      sprite = new Sprite;
      if (!sprite)
	return false;

      //get <image>
      rapidxml::xml_node<char> *node = curNode->first_node("image");
      if (!node)
	{
	  std::cerr << "Error: Invalid Spriter file: Frame \"" << this->name_ << "\" lacks <image> node!" << std::endl;
	  return false;
	}
      if (!sprite->setBitmap(node->value(), rootPath))
	{
	  return false;
	}

      //get <color> [0x000000 ; 0xffffff]
      node = curNode->first_node("color");
      if(!node)
      	{
      	  std::cerr << "Error: Invalid Spriter file: Frame \"" << this->name_ << "\" lacks <color> node!" << std::endl;
      	  return false;
      	}

      int intColor = atoi(node->value());

      //get <opacity> [0.f ; 100.f]
      node = curNode->first_node("opacity");
      if(!node)
      	{
      	  std::cerr << "Error: Invalid Spriter file: Frame \"" << this->name_ << "\" lacks <opacity> node!" << std::endl;
      	  return false;
      	}
      float opacity = atof(node->value());

      int colorR = (intColor & 0xff0000) >> 16;
      int colorG = (intColor & 0x00ff00) >> 8;
      int colorB = (intColor & 0x0000ff) >> 0;
      int colorA = opacity / 100.f * 255.f;

      sprite->setColor(al_map_rgba(colorR, colorG, colorB, colorA));

      //get <angle> (in degrees, around upper left corner)
      node = curNode->first_node("angle");
      if(!node)
      	{
      	  std::cerr << "Error: Invalid Spriter file: Frame \"" << this->name_ << "\" lacks <angle> node!" << std::endl;
      	  return false;
      	}

      sprite->setRotation(atof(node->value()));

      //get <width> (in pixels)
      node = curNode->first_node("width");
      if(!node)
      	{
      	  std::cerr << "Error: Invalid Spriter file: Frame \"" << this->name_ << "\" lacks <width> node!" << std::endl;
      	  return false;
      	}

      sprite->setWidth(atoi(node->value()));

      //get <height> (in pixels)
      node = curNode->first_node("height");
      if(!node)
      	{
      	  std::cerr << "Error: Invalid Spriter file: Frame \"" << this->name_ << "\" lacks <height> node!" << std::endl;
      	  return false;
      	}
      sprite->setHeight(atof(node->value()));

      // //get <xflip>
      // node = curNode->first_node("xflip");
      // if(!node)
      // 	{
      // 	  sf::err() << "Error: Invalid Spriter file: Frame \"" << mName << "\" lacks <xflip> node!" << std::endl;
      // 	  return false;
      // 	}
      // //            if(atoi(node->value())) width *= -1;

      // //get <yflip>
      // node = curNode->first_node("yflip");
      // if(!node)
      // 	{
      // 	  sf::err() << "Error: Invalid Spriter file: Frame \"" << mName << "\" lacks <yflip> node!" << std::endl;
      // 	  return false;
      // 	}
      // //            if(atoi(node->value())) height *= -1;

      //get <x> (in pixels)
      node = curNode->first_node("x");
      if(!node)
      	{
      	  std::cerr << "Error: Invalid Spriter file: Frame \"" << this->name_ << "\" lacks <x> node!" << std::endl;
      	  return false;
      	}
      sprite->setX(atoi(node->value()));

      //get <y> (in pixels)
      node = curNode->first_node("y");
      if(!node)
      	{
      	  std::cerr << "Error: Invalid Spriter file: Frame \"" << this->name_ << "\" lacks <y> node!" << std::endl;
      	  return false;
      	}
      sprite->setY(atoi(node->value()));

      // //create Sprite
      // //width/height is negative if the axis is flipped, in that case we need to reposition the origin to upper left
      // sprite->setOrigin((width < 0 ? width : 0), (height < 0 ? height : 0));
      // sprite->setPosition(x, y);
      // sprite->setScale(width / float(tex->getSize().x), height / float(tex->getSize().y));
      // sprite->setRotation(-angle);
      // sprite->setColor(color);
      this->list_.push_back(sprite);
    }
  return true;
}