Beispiel #1
0
static inline bool readVizAttribute(
	GraphAttributes &GA,
	node v,
	const pugi::xml_node tag)
{
	const long attrs = GA.attributes();

	if(string(tag.name()) == "viz:position") {
		if(attrs & GraphAttributes::nodeGraphics) {
			pugi::xml_attribute xAttr = tag.attribute("x");
			pugi::xml_attribute yAttr = tag.attribute("y");
			pugi::xml_attribute zAttr = tag.attribute("z");

			if(!xAttr || !yAttr) {
				GraphIO::logger.lout() << "Missing \"x\" or \"y\" in position tag." << std::endl;
				return false;
			}

			GA.x(v) = xAttr.as_int();
			GA.y(v) = yAttr.as_int();

			// z attribute is optional and avaliable only in \a threeD mode
			GA.y(v) = yAttr.as_int();
			if (zAttr && (attrs & GraphAttributes::threeD)) {
				GA.z(v) = zAttr.as_int();
			}
		}
	} else if(string(tag.name()) == "viz:size") {
		if(attrs & GraphAttributes::nodeGraphics) {
			pugi::xml_attribute valueAttr = tag.attribute("value");
			if (!valueAttr) {
				GraphIO::logger.lout() << "\"size\" attribute is missing a value." << std::endl;
				return false;
			}

			double size = valueAttr.as_double();
			GA.width(v) = size * LayoutStandards::defaultNodeWidth();
			GA.height(v) = size * LayoutStandards::defaultNodeHeight();
		}
	} else if(string(tag.name()) == "viz:shape") {
		if(attrs & GraphAttributes::nodeGraphics) {
			pugi::xml_attribute valueAttr = tag.attribute("value");
			if(!valueAttr) {
				GraphIO::logger.lout() << "\"shape\" attribute is missing a value." << std::endl;
				return false;
			}

			GA.shape(v) = toShape(valueAttr.value());
		}
	} else if(string(tag.name()) == "viz:color") {
		if(attrs & GraphAttributes::nodeStyle) {
			return readColor(GA.fillColor(v), tag);
		}
	} else {
		GraphIO::logger.lout() << "Incorrect tag: \"" << tag.name() << "\"." << std::endl;
		return false;
	}

	return true;
}
Beispiel #2
0
bool Ref::Load(const pugi::xml_node& node)
{
    if (strcmp(node.name(), "bone_ref") && strcmp(node.name(), "object_ref"))
        return false;

    id_ = node.attribute("id").as_int();
    parent_ = node.attribute("parent").as_int(-1);
    timeline_ = node.attribute("timeline").as_int();
    key_ = node.attribute("key").as_int();
    zIndex_ = node.attribute("z_index").as_int();

    return true;
}
Beispiel #3
0
bool SpriterData::Load(const pugi::xml_node& node)
{
    Reset();

    if (strcmp(node.name(), "spriter_data"))
        return false;

    scmlVersion_ = node.attribute("scml_version").as_int();
    generator_ = node.attribute("generator").as_string();
    generatorVersion_ = node.attribute("scml_version").as_string();

    for (xml_node folderNode = node.child("folder"); !folderNode.empty(); folderNode = folderNode.next_sibling("folder"))
    {
        folders_.Push(new  Folder());
        if (!folders_.Back()->Load(folderNode))
            return false;
    }

    for (xml_node entityNode = node.child("entity"); !entityNode.empty(); entityNode = entityNode.next_sibling("entity"))
    {
        entities_.Push(new  Entity());
        if (!entities_.Back()->Load(entityNode))
            return false;
    }

    return true;
}
Beispiel #4
0
void mergeNodes(pugi::xml_node toNode, pugi::xml_node& fromNode)
{
  // Base case = both nodes are text nodes
  pugi::xml_text fromNodeText = fromNode.text();
  pugi::xml_text toNodeText = toNode.text();
  if (fromNodeText && toNodeText) {
    SBLog::info() << "Overwriting template value of \"" << toNode.name() << "\" from \"" << toNodeText.get() << "\" to \"" << fromNodeText.get() << "\"." << std::endl;
    toNodeText.set(fromNodeText.get());
    return;
  }

  // Calculate number of children in toNode
  unsigned maxDistance = std::distance(toNode.begin(), toNode.end());

  // Merge children
  for (pugi::xml_node fromNodeChild = fromNode.first_child(); fromNodeChild; fromNodeChild = fromNodeChild.next_sibling()) {
    // Find appropriate merge point
    pugi::xml_node toNodeChild = findSimilarNode(fromNodeChild, toNode, maxDistance);
    if (toNodeChild) {
      mergeNodes(toNodeChild, fromNodeChild);
    } else {
      toNode.append_copy(fromNodeChild);
    }
  }

  // Erase fromNode
  removeNode(fromNode);
}
Beispiel #5
0
static pugi::xml_node findSimilarNode(pugi::xml_node searchNode, pugi::xml_node searchRoot, unsigned maxDistance)
{
  std::string searchNodeName = searchNode.name();
  pugi::xml_node match;

  // Examine children of searchRoot that have matching names to searchNode
  unsigned i = 0;
  pugi::xml_node child = searchRoot.first_child();
  for (; child && i < maxDistance && !match; child = child.next_sibling(), i++) {
    // Ignore nodes with non-matching names
    if (searchNodeName != child.name())
      continue;

    // Assume child is a match, until shown otherwise
    match = child;

    // Check that all attributes of searchNode match the child node's attributes
    for (pugi::xml_attribute attr : searchNode.attributes()) {
      std::string searchNodeAttr = attr.value();
      std::string matchAttr = child.attribute(attr.name()).value();
      if (searchNodeAttr != matchAttr) {
        match = pugi::xml_node();
        break;
      }
    }
  }

  return match;
}
Beispiel #6
0
void parseAtomAuthor(FeedAuthor& author, const pugi::xml_node &authorNode) {
  string nodeName = authorNode.name();
  if (nodeName != "author") {
    throw ParseError("expected author node.");
  }
  bool haveDetailedAuthor = false;
  for (auto child: authorNode.children()) {
    haveDetailedAuthor = true;
    nodeName = child.name();
    if (nodeName == "name") {
      getNodeContent(author.name, child);
    } else if (nodeName == "email") {
      getNodeContent(author.email, child);
    } else if (nodeName == "uri") {
      getNodeContent(author.link.url, child);
    } else if (nodeName == "link") {
      if (author.link.url.empty()) {
        getNodeContent(author.link.url, child);
      }
    }
  }
  if (!haveDetailedAuthor) {
    // the node is just a bare <author>NAME</author> element.
    getNodeContent(author.name, authorNode);
  }
}
Beispiel #7
0
bool TimelineKey::Load(const pugi::xml_node& node)
{
    if (strcmp(node.name(), "key"))
        return false;

    id_ = node.attribute("id").as_int();
    time_ = node.attribute("time").as_float() * 0.001f;

    String curveType = node.attribute("curve_type").as_string("linear");
    if (curveType == "instant")
        curveType_ = INSTANT;
    else if (curveType == "linear")
        curveType_ = LINEAR;
    else if (curveType == "quadratic")
        curveType_ = QUADRATIC;
    else if (curveType == "cubic")
        curveType_ = CUBIC;
    else
        curveType_ = LINEAR;

    c1_ = node.attribute("c1").as_float();
    c2_ = node.attribute("c2").as_float();

    return true;
}
    virtual bool for_each(pugi::xml_node &node) {
        for (int i = 0; i < depth(); ++i) std::cout << "  "; // indentation

        std::cout << node_types[node.type()] << ": name='" << node.name() << "', value='" << node.value() << "'\n";

        return true; // continue traversal
    }
Beispiel #9
0
int32_t
GCConfigTest::triggerOperation(pugi::xml_node node)
{
	OMRPORT_ACCESS_FROM_OMRPORT(gcTestEnv->portLib);
	int32_t rt = 0;
	for (; node; node = node.next_sibling()) {
		if (0 == strcmp(node.name(), "systemCollect")) {
			const char *gcCodeStr = node.attribute("gcCode").value();
			if (0 == strcmp(gcCodeStr, "")) {
				/* gcCode defaults to J9MMCONSTANT_IMPLICIT_GC_DEFAULT */
				gcCodeStr = "0";
			}
			uint32_t gcCode = (uint32_t)atoi(gcCodeStr);
			omrtty_printf("Invoking gc system collect with gcCode %d...\n", gcCode);
			rt = (int32_t)OMR_GC_SystemCollect(exampleVM->_omrVMThread, gcCode);
			if (OMR_ERROR_NONE != rt) {
				omrtty_printf("%s:%d Failed to perform OMR_GC_SystemCollect with error code %d.\n", __FILE__, __LINE__, rt);
				goto done;
			}
			OMRGCTEST_CHECK_RT(rt);
			verboseManager->getWriterChain()->endOfCycle(env);
		}
	}
done:
	return rt;
}
	void EmmaParser::parseContainer(EmmaDoc &doc, pugi::xml_node containerNode)
	{
		std::string containerName = containerNode.name();

		if(containerName == "emma:interpretation")
		{
			doc.setContainerType("interpretation");
			parseInterpretation(doc, containerNode);
		}
		else if(containerName == "emma:sequence")
		{
			doc.setContainerType("sequence");
			for (pugi::xml_node interpretation = containerNode.first_child(); interpretation; interpretation = interpretation.next_sibling())
			{
				parseInterpretation(doc, interpretation);
			}
		}
		else if(containerName == "emma:one-of")
		{
			doc.setContainerType("one-of");

			for (pugi::xml_node interpretation = containerNode.first_child(); interpretation; interpretation = interpretation.next_sibling())
			{
				parseInterpretation(doc, interpretation);
			}
		}
        doc.sortInputs();
	}
Beispiel #11
0
//-----------------------------------------------------------------------------
void XMLMesh::read_array_uint(std::vector<std::size_t>& array,
                              const pugi::xml_node xml_array)
{
  // Check that we have an array
  const std::string name = xml_array.name();
  if (name != "array")
  {
    dolfin_error("XMLMesh.cpp",
                 "read mesh array data from XML file",
                 "Expecting an XML array node");
  }

  // Check type is unit
  const std::string type = xml_array.attribute("type").value();
  if (type != "uint")
  {
    dolfin_error("XMLMesh.cpp",
                 "read mesh array data from XML file",
                 "Expecting an XML array node");
  }

  // Get size and resize vector
  const std::size_t size = xml_array.attribute("size").as_uint();
  array.resize(size);

  // Iterate over array entries
  for (pugi::xml_node_iterator it = xml_array.begin(); it !=xml_array.end();
       ++it)
  {
    const std::size_t index = it->attribute("index").as_uint();
    const double value = it->attribute("value").as_uint();
    dolfin_assert(index < size);
    array[index] = value;
  }
}
Beispiel #12
0
bool Entity::Load(const pugi::xml_node& node)
{
    Reset();

    if (strcmp(node.name(), "entity"))
        return false;

    id_ = node.attribute("id").as_int();
    name_ = node.attribute("name").as_string();

    for (xml_node characterMapNode = node.child("character_map"); !characterMapNode.empty(); characterMapNode = characterMapNode.next_sibling("character_map"))
    {
        characterMaps_.Push(new CharacterMap());
        if (!characterMaps_.Back()->Load(characterMapNode))
            return false;
    }

    for (xml_node animationNode = node.child("animation"); !animationNode.empty(); animationNode = animationNode.next_sibling("animation"))
    {
        animations_.Push(new  Animation());
        if (!animations_.Back()->Load(animationNode))
            return false;
    }

    return true;
}
Beispiel #13
0
bool Animation::Load(const pugi::xml_node& node)
{
    Reset();

    if (strcmp(node.name(), "animation"))
        return false;

    id_ = node.attribute("id").as_int();
    name_ = node.attribute("name").as_string();
    length_ = node.attribute("length").as_float() * 0.001f;
    looping_ = node.attribute("looping").as_bool(true);

    xml_node mainlineNode = node.child("mainline");
    for (xml_node keyNode = mainlineNode.child("key"); !keyNode.empty(); keyNode = keyNode.next_sibling("key"))
    {
        mainlineKeys_.Push(new MainlineKey());
        if (!mainlineKeys_.Back()->Load(keyNode))
            return false;
    }

    for (xml_node timelineNode = node.child("timeline"); !timelineNode.empty(); timelineNode = timelineNode.next_sibling("timeline"))
    {
        timelines_.Push(new Timeline());
        if (!timelines_.Back()->Load(timelineNode))
            return false;
    }

    return true;
}
Beispiel #14
0
void ClientVersion::loadOTBInfo(pugi::xml_node otbNode)
{
	if (as_lower_str(otbNode.name()) != "otb") {
		return;
	}

	pugi::xml_attribute attribute;
	OtbVersion otb = {"", OTB_VERSION_3, CLIENT_VERSION_NONE};
	if (!(attribute = otbNode.attribute("client"))) {
		wxLogError(wxT("Node 'otb' must contain 'client' tag."));
		return;
	}

	otb.name = attribute.as_string();
	if (!(attribute = otbNode.attribute("id"))) {
		wxLogError(wxT("Node 'otb' must contain 'id' tag."));
		return;
	}

	otb.id = pugi::cast<int32_t>(attribute.value());
	if (!(attribute = otbNode.attribute("version"))) {
		wxLogError(wxT("Node 'otb' must contain 'version' tag."));
		return;
	}

	OtbFormatVersion versionId = static_cast<OtbFormatVersion>(pugi::cast<int32_t>(attribute.value()));
	if (versionId < OTB_VERSION_1 || versionId > OTB_VERSION_3) {
		wxLogError(wxT("Node 'otb' unrecognized format version (version 1..3 supported)."));
		return;
	}

	otb.format_version = versionId;
	otb_versions[otb.name] = otb;
}
    void read_xml_node( pugi::xml_node node, Ptree &pt, int flags)
    {
        typedef typename Ptree::key_type::value_type Ch;

        switch ( node.type() )
        {
            case pugi::node_element:
                {
                    Ptree &tmp = pt.push_back(std::make_pair( node.name(), Ptree()))->second;
                    for ( pugi::xml_attribute attr = node.first_attribute(); attr; attr = attr.next_attribute() )
                        tmp.put( xmlattr<Ch>() + "." + attr.name(), attr.value());
                    for ( pugi::xml_node child = node.first_child(); child; child = child.next_sibling())
                        read_xml_node(child, tmp, flags);
                }
                break;
            case pugi::node_pcdata:
                {
                    if (flags & no_concat_text)
                        pt.push_back(std::make_pair(xmltext<Ch>(), Ptree( node.value() )));
                    else
                        pt.data() += node.value();
                }
                break;
            case pugi::node_comment:
                {
                    if (!(flags & no_comments))
                        pt.push_back(std::make_pair(xmlcomment<Ch>(), Ptree( node.value() )));
                }
                break;
            default:
                // skip other types
                break;
        }
    }
Beispiel #16
0
void Spellbooks::checkAttribute(pugi::xml_node& node, const char* name) const {
    if (!node.attribute(name)) {
        std::string str("Missing attribute ");
        str += name;
        str += " in node ";
        str += node.name();
        throw XmlLoadException(str);
    }
}
Beispiel #17
0
//Creates and initializes a texture object from xml
Texture Visitor::loadTextureFromXml(pugi::xml_node& xml_text_data)
{
	Texture to_return;// = nullptr;
	if (std::strcmp(xml_text_data.name(), "Texture") == 0)
	{
		pugi::xml_attribute tex_path = xml_text_data.attribute("TexturePath");
		to_return = scene_objects.loadTexture(tex_path.as_string());
		if (glGetError() != 0)
			std::cout << "Illegal arguments set for texture";
		for (pugi::xml_node_iterator tex_parameter = xml_text_data.begin(); tex_parameter != xml_text_data.end(); ++tex_parameter)
			setGLCodeFromXml(*tex_parameter, to_return);
	}
	//TODO: Fix this, does not work because load3DTexture returns a pointer
	else if (std::strcmp(xml_text_data.name(), "Texture3D") == 0)
	{
		pugi::xml_attribute tex_path = xml_text_data.attribute("TexturePath");
		//to_return = scene_objects.load3DTexture(tex_path.as_string());
		for (pugi::xml_node_iterator tex_parameter = xml_text_data.begin(); tex_parameter != xml_text_data.end(); ++tex_parameter)
			setGLCodeFromXml(*tex_parameter, to_return);
	}
	else if (std::strcmp(xml_text_data.name(), "FrameBufferTexture") == 0)
	{
		int left = xml_text_data.attribute("left").as_int();
		int bottom = xml_text_data.attribute("Bottom").as_int();
		int width = xml_text_data.attribute("Width").as_int();
		int height = xml_text_data.attribute("Height").as_int();
		std::string name = xml_text_data.attribute("Name").as_string();

		//to_return = scene_objects.loadFramebufferTexture(left, bottom, width, height, name);

		for (pugi::xml_node_iterator tex_parameter = xml_text_data.begin(); tex_parameter != xml_text_data.end(); ++tex_parameter)
			setGLCodeFromXml(*tex_parameter, to_return);
		for (pugi::xml_node_iterator tex_parameter = xml_text_data.begin(); tex_parameter != xml_text_data.end(); ++tex_parameter)
		{
			//if (strcmp(tex_parameter->name(), "TriangleMesh") == 0)
			//	(static_cast<FrameBufferTexture*>(to_return))->addMesh(loadMeshFromXml(*tex_parameter));
		}
	}
	else
		std::cout << "Undefined XML node type, check resource file for errors." << std::endl;

	return to_return;
}
Beispiel #18
0
    BOOL SMessageBoxImpl::SetMsgTemplate( pugi::xml_node uiRoot )
    {
        if(wcscmp(uiRoot.name(),L"SOUI")!=0 ) return FALSE;
        if(!uiRoot.attribute(L"frameSize").value()[0]) return FALSE;
        if(!uiRoot.attribute(L"minSize").value()[0]) return FALSE;

        s_xmlMsgTemplate.reset();
        s_xmlMsgTemplate.append_copy(uiRoot);
        return TRUE;
    }
	spActor deserializedata::deser(pugi::xml_node node, const creator* factory)
	{
		deserializedata d;
		d.node = node;
		d.factory = factory;
		const char *name = node.name();
		spActor actor = factory->create(name);
		actor->deserialize(&d);
		return actor;
	}
Beispiel #20
0
	void XMLFileParser::AddChild(XMLContainer & parent, const pugi::xml_node & node)
	{
		std::shared_ptr<XMLContainer> child(new XMLContainer());
		AddAttributes(*(child.get()), node);
		child->SetName(star::string_cast<tstring>(node.name()));
		child->SetValue(star::string_cast<tstring>(node.child_value()));
		auto sibling = node.first_child();
		if(sibling != NULL)
		{
			do 
			{
				AddChild(*(child.get()), sibling);
				sibling = sibling.next_sibling();
			} while (sibling != NULL);
		}
		if(child->GetName() != EMPTY_STRING)
		{
			parent.insert(std::make_pair(star::string_cast<tstring>(node.name()), child));
		}
	}
Beispiel #21
0
    virtual bool for_each(pugi::xml_node& node) {

        Log::log(logModule, level, "XML node type = [%s], name = [%s], value = [%s]",
                node_types[node.type()], node.name(), 
                node.type() == pugi::node_cdata || node.type() == pugi::node_pcdata ? node.text().get() : node.value());
        for (pugi::xml_attribute_iterator ait = node.attributes_begin(); ait != node.attributes_end(); ++ait) {
            Log::log(logModule, level, "  attribute name = [%s], value = [%s]",
                    ait->name(), ait->value());
        }
        return true;
    }
Beispiel #22
0
pugi::xml_node XMLBuilder::getNodeFromPath(const pugi::xml_node& i_parrentNode,
                                           const std::string& i_path) {
  pugi::xml_node childNode =
      i_parrentNode.first_element_by_path(i_path.c_str());
  if (childNode) {
    return childNode;
  } else {
    LOG_ERROR("Could not find a child node from: "
              << i_path << " starting at node: " << i_parrentNode.name());
  }
}
Beispiel #23
0
bool MapInstruction::Load(const pugi::xml_node& node)
{
    if (strcmp(node.name(), "map"))
        return false;

    folder_ = node.attribute("folder").as_int();
    file_ = node.attribute("file").as_int();
    targetFolder_ = node.attribute("target_folder").as_int(-1);
    targetFile_ = node.attribute("target_file").as_int(-1);

    return true;
}
Beispiel #24
0
std::string xvnu::path(const pugi::xml_node& node)
{
	// Get the string for this node
	string str = "(" + std::to_string(xvnu::index(node)) + ")" + string(node.name());

	// If the node has a parent, recursivly call this function, adding this nodes location to the end of the string
	if(node.parent() && node.parent().type() != xml_node_type::node_document)
		return xvnu::path(node.parent()) + " " + str;
	// If the node has no parent, return and empty string and end the recursive loop
	else
		return string();
}
Beispiel #25
0
bool File::Load(const pugi::xml_node& node)
{
    if (strcmp(node.name(), "file"))
        return false;

    id_ = node.attribute("id").as_int();
    name_ = node.attribute("name").as_string();
    width_ = node.attribute("width").as_float();
    height_ = node.attribute("height").as_float();
    pivotX_ = node.attribute("pivot_x").as_float(0.0f);
    pivotY_ = node.attribute("pivot_y").as_float(1.0f);

    return true;
}
Beispiel #26
0
void xmlManager::print_node(pugi::xml_node source_node, string prefix) {

    cout << prefix << source_node.name() << ": " << source_node.value() << endl;

    for (pugi::xml_attribute_iterator it = source_node.attributes_begin();
         it != source_node.attributes_end();
         it++)
        cout << prefix + "\t" << it->name() << " : " << it->value() << endl;

    for (pugi::xml_node_iterator it = source_node.begin();
         it != source_node.end();
         it++)
        print_node(*it, prefix + "\t");

}
Beispiel #27
0
CXmlNode::CXmlNode(CXmlNode* _parent , const pugi::xml_node& rowData )
{
	this->nodeData.parent=NULL;
	if(rowData!=NULL)
	{
	  nodeData.nodeName=rowData.name();
      for (auto &&item : rowData.attributes()) {
        AddProperty(item.name(), item.value());
      }
      for (auto &&child : rowData.children()) {
        CXmlNode* newChild = new CXmlNode(this, child);
        this->nodeData.children.push_back(newChild);
      }
	}
	this->nodeData.parent=_parent;
}
Beispiel #28
0
Math::Vec3 PugiHelper::ParseVec3( const pugi::xml_node& node )
{
	// Parse vector elements (in double)
	std::vector<double> v;
	std::stringstream ss(node.child_value());

	double t;
	while (ss >> t) v.push_back(t);
	if (v.size() != 3)
	{
		LM_LOG_WARN("Invalid number of elements in '" + std::string(node.name()) + "'");
		return Math::Vec3();
	}

	// Convert type and return
	return Math::Vec3(Math::Float(v[0]), Math::Float(v[1]), Math::Float(v[2]));
}
Beispiel #29
0
void ResourceLoader::getSpriteRecursive(SpriteSheet& sheet, pugi::xml_node& node, string name)
{
	string newPath = name + node.attribute("name").as_string();
	string curNodeType = node.name();
	if (curNodeType == "spr") {
		auto& newRect = sheet.sprites.insert(make_pair(newPath, sf::FloatRect())).first->second;
		newRect.left = node.attribute("x").as_float();
		newRect.top = node.attribute("y").as_float();
		newRect.width = node.attribute("w").as_float();
		newRect.height = node.attribute("h").as_float();
	}
	else {
		for (auto& n : node) {
			getSpriteRecursive(sheet, n, newPath + "/");
		}
	}
}
Beispiel #30
0
bool Timeline::Load(const pugi::xml_node& node)
{
    Reset();

    if (strcmp(node.name(), "timeline"))
        return false;

    id_ = node.attribute("id").as_int();
    name_ = node.attribute("name").as_string();

    String typeString;
    xml_attribute typeAttr = node.attribute("type");
    if (typeAttr.empty())
        typeString = node.attribute("object_type").as_string("sprite");
    else
        typeString = typeAttr.as_string("sprite");
    
    if (typeString == "bone")
    {
        objectType_ = BONE;
        for (xml_node keyNode = node.child("key"); !keyNode.empty(); keyNode = keyNode.next_sibling("key"))
        {
            keys_.Push(new BoneTimelineKey(this));
            if (!keys_.Back()->Load(keyNode))
                return false;
        }
    }
    else if (typeString == "sprite")
    {
        objectType_ = SPRITE;
        for (xml_node keyNode = node.child("key"); !keyNode.empty(); keyNode = keyNode.next_sibling("key"))
        {
            keys_.Push(new SpriteTimelineKey(this));
            if (!keys_.Back()->Load(keyNode))
                return false;
        }
    }
    else
    {
        // Unsupported object type now.
        return false;
    }

    return true;
}