Exemplo n.º 1
0
static
void FromXml(const pugi::xml_node& xmlNode, DataSetElement& parent)
{
    // ignore non-named XML nodes
    //
    // pugi::xml separates XML parts into more node types than we use
    //
    const string& label = xmlNode.name();
    if (label.empty())
        return;

    // label & text
    DataSetElement e(xmlNode.name(), FromInputXml());
    e.Text(xmlNode.text().get());

    // iterate attributes
    auto attrIter = xmlNode.attributes_begin();
    auto attrEnd  = xmlNode.attributes_end();
    for ( ; attrIter != attrEnd; ++attrIter )
        e.Attribute(attrIter->name(), attrIter->value());

    // iterate children, recursively building up subtree
    auto childIter = xmlNode.begin();
    auto childEnd = xmlNode.end();
    for ( ; childIter != childEnd; ++childIter ) {
        pugi::xml_node childNode = *childIter;
        FromXml(childNode, e);
    }

    // add our element to its parent
    parent.AddChild(e);
}
Exemplo n.º 2
0
bool Config::parseNode(const pugi::xml_node& node) {
    UnicodeString currentPath = StringConverter::fromUtf8(node.path('/'));
    currentPath.append("@");

    pugi::xml_node::attribute_iterator attrIter = node.attributes_begin();
    pugi::xml_node::attribute_iterator attrEnd = node.attributes_end();

    for (; attrIter != attrEnd; ++attrIter) {
        UnicodeString configKey = currentPath;
        configKey.append(attrIter->name());
        std::map<UnicodeString, Variable>::iterator itm = variablesMap_.find(configKey);
        if (itm != variablesMap_.end()) {
            if (!itm->second.parse(attrIter->value())) {
                return false;
            }
        } else {
            LOG_WARN << "Ignoring unknown config value " << configKey << std::endl;
        }
    }

    pugi::xml_node::iterator nodeIter = node.begin();
    pugi::xml_node::iterator nodeEnd = node.end();

    for (; nodeIter != nodeEnd; ++nodeIter) {
        if (nodeIter->type() == pugi::node_element) {
            if (!parseNode(*nodeIter)) {
                return false;
            }
        }
    }

    return true;
}
Exemplo n.º 3
0
	void SettingsManager::mergeAttributes(pugi::xml_node _nodeTarget, pugi::xml_node _nodeSource)
	{
		for (pugi::xml_node::attribute_iterator attribute = _nodeSource.attributes_begin(); attribute != _nodeSource.attributes_end(); attribute ++)
		{
			pugi::xml_attribute attributeNode = _nodeTarget.attribute((*attribute).name());
			if (attributeNode.empty())
				attributeNode = _nodeTarget.append_attribute((*attribute).name());
			attributeNode.set_value((*attribute).value());
		}
	}
Exemplo n.º 4
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;
    }
void UIParserChangeTextureDelegate::constraintWithParent(const pugi::xml_node& node, const pugi::xml_node& prev_node, cocos2d::Node* parent, cocos2d::Node* recent)
{
    if (parent)
    {
        std::string src;
        std::string atlas;
        std::string frame;
        cocos2d::Node* target = nullptr;
        
        for (auto it = node.attributes_begin(); it != node.attributes_end(); it++)
        {
            if (strcmp(it->name(), "src") == 0)
            {
                src = it->value();
            }
            else if (strcmp(it->name(), "atlas") == 0)
            {
                atlas = it->value();
            }
            else if (strcmp(it->name(), "frame") == 0)
            {
                frame = it->value();
            }
            else if (strcmp(it->name(), "target") == 0)
            {
                std::vector<std::string> ids;
                ui_parser_utils::split(it->value(), ':', ids);
                
                target = parent;
                for (int i = 0; i < ids.size(); i++)
                {
                    if (ids[i].compare("this") != 0 && target)
                    {
                        target = target->getChildByName(ids[i]);
                    }
                }
            }
        }
        
        auto imageview = dynamic_cast<CustomUIImageView*>(target);
        if (imageview)
        {
            if (!src.empty())
            {
                imageview->loadTexture(src);
            }
            else if(!atlas.empty() && !frame.empty())
            {
                imageview->setSpriteFrame(atlas_cache::getSpriteFrame(atlas, frame));
            }
        }
    }
}
Exemplo n.º 6
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");

}
Exemplo n.º 7
0
//Parses XML data into calls to glTexParameteri
void Visitor::setGLCodeFromXml(pugi::xml_node xml_input, Texture& texture)
{
	if (std::strcmp(xml_input.name(), "Parameter") == 0)
	{
		for (pugi::xml_attribute_iterator tex_parameter = xml_input.attributes_begin();
			tex_parameter != xml_input.attributes_end(); ++tex_parameter)
		{
			//Signals whether the parameter passed to openGL is a macro or integer
			bool expect_int = false;
			//Signals whether the parameter passed to openGL is a float or an integer
			bool expect_float = false;
			std::string param_id = tex_parameter->name();
			std::string param_value = tex_parameter->as_string();
			int param_type = 0;

			//Filtering options
			if (strcmp(param_id.c_str(), "MinFilter") == 0)
				param_type = GL_TEXTURE_MIN_FILTER;
			else if (strcmp(param_id.c_str(), "MagFilter") == 0)
				param_type = GL_TEXTURE_MAG_FILTER;

			// Min/Max values for texture
			else if (strcmp(param_id.c_str(), "MaxLOD") == 0)
			{
				param_type = GL_TEXTURE_MAX_LOD;
				expect_float = true;
			}
			else if (strcmp(param_id.c_str(), "MinLOD") == 0)
			{
				param_type = GL_TEXTURE_MIN_LOD;
				expect_float = true;
			}
			else if (strcmp(param_id.c_str(), "BaseLevel") == 0)
			{
				param_type = GL_TEXTURE_BASE_LEVEL;
				expect_int = true;
			}
			else if (strcmp(param_id.c_str(), "MaxLevel") == 0)
			{
				param_type = GL_TEXTURE_MAX_LEVEL;
				expect_int = true;
			}

			//Comparison options
			else if (strcmp(param_id.c_str(), "CompareMode") == 0)
				param_type = GL_TEXTURE_COMPARE_MODE;
			else if (strcmp(param_id.c_str(), "CompareFunc") == 0)
				param_type = GL_TEXTURE_COMPARE_FUNC;

			//Swizzle options
			else if (strcmp(param_id.c_str(), "SwizzleR") == 0)
				param_type = GL_TEXTURE_SWIZZLE_R;
			else if (strcmp(param_id.c_str(), "SwizzleG") == 0)
				param_type = GL_TEXTURE_SWIZZLE_G;
			else if (strcmp(param_id.c_str(), "SwizzleB") == 0)
				param_type = GL_TEXTURE_SWIZZLE_B;
			else if (strcmp(param_id.c_str(), "SwizzleA") == 0)
				param_type = GL_TEXTURE_SWIZZLE_A;

			//Texture wrapping modes
			else if (strcmp(param_id.c_str(), "WrapS") == 0)
				param_type = GL_TEXTURE_WRAP_S;
			else if (strcmp(param_id.c_str(), "WrapT") == 0)
				param_type = GL_TEXTURE_WRAP_T;
			else if (strcmp(param_id.c_str(), "WrapR") == 0)
				param_type = GL_TEXTURE_WRAP_R;
			else
			{
				//If we are here an unknown identifier was supplied
				std::cout << "Unknown parameter type: " << param_id << std::endl;
				std::cout << "Check XML Resource file for errors" << std::endl;
				return;
			}

			//Now need to discern the argument to pass
			int gl_parameter = 0;

			//Regular filter types
			if (strcmp(param_value.c_str(), "Linear") == 0)
				gl_parameter = GL_LINEAR;
			else if (strcmp(param_value.c_str(), "Nearest") == 0)
				gl_parameter = GL_NEAREST;

			//Mipmap filter types
			else if (strcmp(param_value.c_str(), "NearestMipmapNearest") == 0)
				gl_parameter = GL_NEAREST_MIPMAP_NEAREST;
			else if (strcmp(param_value.c_str(), "NearestMipmapLinear") == 0)
				gl_parameter = GL_NEAREST_MIPMAP_LINEAR;
			else if (strcmp(param_value.c_str(), "LinearMipmapNearest") == 0)
				gl_parameter = GL_LINEAR_MIPMAP_NEAREST;
			else if (strcmp(param_value.c_str(), "LinearMipmapLinear") == 0)
				gl_parameter = GL_LINEAR_MIPMAP_LINEAR;

			//Comparison functions
			else if (strcmp(param_value.c_str(), "CompareRefToTexture") == 0)
				gl_parameter = GL_COMPARE_REF_TO_TEXTURE;
			else if (strcmp(param_value.c_str(), "None") == 0)
				gl_parameter = GL_NONE;

			//Colors
			else if (strcmp(param_value.c_str(), "Red") == 0)
				gl_parameter = GL_RED;
			else if (strcmp(param_value.c_str(), "Green") == 0)
				gl_parameter = GL_GREEN;
			else if (strcmp(param_value.c_str(), "Blue") == 0)
				gl_parameter = GL_BLUE;
			else if (strcmp(param_value.c_str(), "Alpha") == 0)
				gl_parameter = GL_ALPHA;
			else if (strcmp(param_value.c_str(), "One") == 0)
				gl_parameter = GL_ONE;
			else if (strcmp(param_value.c_str(), "Zero") == 0)
				gl_parameter = GL_ZERO;

			//Wrapping modes
			else if (strcmp(param_value.c_str(), "ClampToEdge") == 0)
				gl_parameter = GL_CLAMP_TO_EDGE;
			else if (strcmp(param_value.c_str(), "MirroredRepeat") == 0)
				gl_parameter = GL_MIRRORED_REPEAT;
			else if (strcmp(param_value.c_str(), "Repeat") == 0)
				gl_parameter = GL_REPEAT;

			//Function options
			else if (strcmp(param_value.c_str(), "LEqual") == 0)
				gl_parameter = GL_LEQUAL;
			else if (strcmp(param_value.c_str(), "GEqual") == 0)
				gl_parameter = GL_GEQUAL;
			else if (strcmp(param_value.c_str(), "GLess") == 0)
				gl_parameter = GL_LESS;
			else if (strcmp(param_value.c_str(), "Greater") == 0)
				gl_parameter = GL_GREATER;
			else if (strcmp(param_value.c_str(), "Equal") == 0)
				gl_parameter = GL_EQUAL;
			else if (strcmp(param_value.c_str(), "Notequal") == 0)
				gl_parameter = GL_NOTEQUAL;
			else if (strcmp(param_value.c_str(), "Always") == 0)
				gl_parameter = GL_ALWAYS;
			else if (strcmp(param_value.c_str(), "Never") == 0)
				gl_parameter = GL_NEVER;

			//Check if we are expecting an int or float
			else if (expect_int)
				gl_parameter = atoi(param_value.c_str());
			else if (expect_float)
				gl_parameter = atof(param_value.c_str());
			else
			{
				//If we are here an unknown identifier was supplied
				std::cout << "Unknown parameter value: " << param_value << std::endl;
				std::cout << "Check XML Resource file for errors" << std::endl;
				return;
			}

			if (expect_float)
				texture.setFloatParameter(param_type, gl_parameter);
			else
				texture.setIntParameter(param_type, gl_parameter);
		}
	}
}