当前位置: 首页>>代码示例>>C++>>正文


C++ CL_DomElement::get_attribute方法代码示例

本文整理汇总了C++中CL_DomElement::get_attribute方法的典型用法代码示例。如果您正苦于以下问题:C++ CL_DomElement::get_attribute方法的具体用法?C++ CL_DomElement::get_attribute怎么用?C++ CL_DomElement::get_attribute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CL_DomElement的用法示例。


在下文中一共展示了CL_DomElement::get_attribute方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: CL_Exception

TileMap::TileMap(CL_GraphicContext& gc, CL_ResourceManager& resmgr, const CL_String& tileset)
: map_width(0), map_height(0), cur_map_x(0), cur_map_y(0) {
    CL_Resource res = resmgr.get_resource(tileset);

    if (res.get_type() != "tilemap")
        throw CL_Exception(cl_format("Resource %1 is not a tilemap", tileset));

    CL_DomElement element = res.get_element();
    levelname = element.get_attribute("name");
    CL_String resource_name = element.get_attribute("resource");
    map_width = element.get_attribute_int("width");
    map_height = element.get_attribute_int("height");

    tiles = CL_Sprite(gc, resource_name, &resmgr);
    float scalex, scaley;
    tiles.get_scale(scalex, scaley);
    tile_width = tiles.get_width() * scalex;
    tile_height = tiles.get_height() * scaley;

    auto layer_nodes = element.select_nodes("layer");
    for (CL_DomNode& idx : layer_nodes) {
        CL_DomElement layer_element = idx.to_element();

        CL_String layer_tiles = layer_element.get_first_child().get_node_value();
        std::vector<CL_String> tile_indices = CL_StringHelp::split_text(layer_tiles, ",");

        MapLayer layer;
        layer.map.reserve(tile_indices.size());
        for (auto& tile : tile_indices)
            layer.map.push_back(CL_StringHelp::text_to_int(tile));

        layers.push_back(layer);
    }
}
开发者ID:zeroshade,项目名称:ClanRPG,代码行数:34,代码来源:TileMap.cpp

示例2: load_from_xml

void BBN_Prob::load_from_xml(CL_DomElement element)
{
  DEBUG_MSG("BBN_Prob::load_from_xml(CL_DomElement) - Called.")

	_probability = CL_StringHelp::text_to_float(element.get_attribute("value"));
  DEBUG_MSG("BBN_Prob::load_from_xml(CL_DomElement) - Prob value = '" + CL_StringHelp::float_to_text(_probability) + "'.")

	_option = static_cast<CL_String8>(element.get_attribute("option"));
	DEBUG_MSG("BBN_Prob::load_from_xml(CL_DomElement) - Prob option = '" + _option + "'.")
}
开发者ID:aggronerd,项目名称:Mystery-Game,代码行数:10,代码来源:BBN_Prob.cpp

示例3: on_set_options

void CL_FileDialog_Generic::on_set_options(const CL_DomElement &options)
{
	if (options.has_attribute("file"))
		set_file(options.get_attribute("file"), false);

	if (options.has_attribute("filter"))
		set_filter(options.get_attribute("filter"), false);

	if (options.has_attribute("show_hidden"))
		show_hidden = CL_String::to_bool(options.get_attribute("show_hidden"));

	read_dir();
}
开发者ID:BackupTheBerlios,项目名称:flexlay-svn,代码行数:13,代码来源:filedialog_generic.cpp

示例4: load_texture

void CL_Collada_Effect_Texture_Impl::load_texture(CL_DomElement &profile_element, CL_DomElement &newparam_element, CL_DomElement &sampler2d_element, std::vector<CL_Collada_Image> &library_images)
{
	sid = newparam_element.get_attribute("sid");

	CL_DomElement source_element = sampler2d_element.named_item("source").to_element();
	if (source_element.is_null())
		throw CL_Exception("source is missing");

	CL_String source_name = source_element.get_text();

	// Find the corresponding surface
	CL_DomElement surface_element;
	CL_DomNode cur_child(profile_element.get_first_child());
	while (!cur_child.is_null())
	{
			if(cur_child.get_node_name() == "newparam")
			{
				CL_DomElement newparam_element = cur_child.to_element();
				CL_String new_sid = newparam_element.get_attribute("sid");
				if (new_sid == source_name)
				{
					surface_element = newparam_element.named_item("surface").to_element();
					if (!surface_element.is_null())
						break;	// Found match
				}
			}
			cur_child = cur_child.get_next_sibling();
	}

	if (surface_element.is_null())
		throw CL_Exception("Cannot find the corresponding surface");

	CL_DomElement init_from_element = surface_element.named_item("init_from").to_element();
	if (init_from_element.is_null())
		throw CL_Exception("Only init_from surfaces are supported");

	CL_String image_name = init_from_element.get_text();

	unsigned int size = library_images.size();
	for (unsigned int cnt=0; cnt < size; cnt++)
	{
		if (library_images[cnt].get_id() == image_name)
		{
			image = library_images[cnt];
			break;
		}
	}
	if (image.is_null())
		throw CL_Exception("Cannot find requested image in the image library");

}
开发者ID:PaulFSherwood,项目名称:cplusplus,代码行数:51,代码来源:collada_effect_texture.cpp

示例5: load_material

void CL_Collada_Material_Impl::load_material(CL_DomElement &material_element, std::vector<CL_Collada_Effect> &effects)
{
	id = material_element.get_attribute("id");

	CL_DomElement instance_effect_element = material_element.named_item("instance_effect").to_element();
	if (instance_effect_element.is_null())
		throw CL_Exception("Only instance_effect materials are supported");

	CL_String url = instance_effect_element.get_attribute("url");
	url = url.substr(1);	// Remove the initial '#' symbol

	std::vector<CL_Collada_Effect>::size_type size, cnt;
	size = effects.size();
	for (cnt=0; cnt< size; cnt++)
	{
		if (effects[cnt].get_id() == url)
		{
			effect = effects[cnt];
			break;
		}
	}

	if (effect.is_null())
		throw CL_Exception("Unable to find effect");

}
开发者ID:PaulFSherwood,项目名称:cplusplus,代码行数:26,代码来源:collada_material.cpp

示例6: load

void TileMap::load(CL_GraphicContext &gc, const CL_String &level, CL_ResourceManager &resources)
{
	CL_Resource resource = resources.get_resource(level);
	
	if (resource.get_type() != "tilemap")
		throw CL_Exception(cl_format("Resource %1 is not of type tilemap!", level));

	CL_DomElement element = resource.get_element();
	CL_String level_name = element.get_attribute("name");
	CL_String resource_name = element.get_attribute("resource");
	map_width = element.get_attribute_int("width");
	map_height = element.get_attribute_int("height");
	
	cl_log_event("Debug", "Loading level %1 (%2x%3)", level_name, map_width, map_height);

	sprite_tiles = CL_Sprite(gc, resource_name, &resources);

	tile_width = sprite_tiles.get_width();
	tile_height = sprite_tiles.get_height();

	cl_log_event("Debug", "Loaded resource %1 with %2 tiles", resource_name, sprite_tiles.get_frame_count());

	std::vector<CL_DomNode> layer_nodes = element.select_nodes("layer");
	for (size_t layer_index = 0; layer_index < layer_nodes.size(); layer_index++)
	{
		CL_DomElement layer_element = layer_nodes[layer_index].to_element();
		CL_String layer_name = layer_element.get_attribute("name");

		CL_String layer_tiles = layer_element.get_first_child().get_node_value();
		std::vector<CL_String> tile_indices = CL_StringHelp::split_text(layer_tiles, ",");

		TileMapLayer layer;
		layer.map.reserve(tile_indices.size());
		for(size_t i = 0; i < tile_indices.size(); ++i)
			layer.map.push_back(CL_StringHelp::text_to_int(tile_indices[i]));
	
		layers.push_back(layer);

		cl_log_event("Debug", "Loaded layer %1 with %2 tiles", layer_name, layer.map.size());
	}

	current_map_position_x = 0;
	current_map_position_y = 0;
}
开发者ID:PaulFSherwood,项目名称:cplusplus,代码行数:44,代码来源:tilemap.cpp

示例7: load_polylist

void CL_Collada_Triangles_Impl::load_polylist(CL_DomElement &polylist_element, bool contains_vcount, std::vector<CL_Collada_Source> &sources, CL_Collada_Vertices &vertices, std::vector<CL_Collada_Material> &library_materials)
{
	name = polylist_element.get_attribute("name");

	// Find material	
	if (polylist_element.has_attribute("material"))
	{
		CL_String material_name = polylist_element.get_attribute("material");

			std::vector<CL_Collada_Material>::size_type size, cnt;
			size = library_materials.size();
			for (cnt=0; cnt< size; cnt++)
			{
				if (library_materials[cnt].get_id() == material_name)
				{
					material = library_materials[cnt];
					break;
				}
			}
	
		if (material.is_null())
			throw CL_Exception("Unable to find material");

	}

	triangle_count = polylist_element.get_attribute_int("count", 0);

	load_inputs(polylist_element, sources, vertices);

	if (contains_vcount)
	{
		CL_DomElement vcount_element = polylist_element.named_item("vcount").to_element();
		if (!vcount_element.is_null())
			validate_vcount(vcount_element);
	}

	CL_DomElement primitive_element = polylist_element.named_item("p").to_element();
	if (!primitive_element.is_null())
		load_primitive(primitive_element);
}
开发者ID:PaulFSherwood,项目名称:cplusplus,代码行数:40,代码来源:collada_triangles.cpp

示例8: test_resources

void TestApp::test_resources(void)
{
	CL_Console::write_line(" Header: resource.h");
	CL_Console::write_line("  Class: CL_Resource");

	// Construct resource manager. This will cause sig_resource_added() to be signalled for each
	// resource object located in the resource file. This means ResourceApp::on_resource_added will
	// get called for each resource.
	CL_ResourceManager resources("resources.xml");

	// Lets try to access some of the clanlib objects in the resource file:
	CL_String config_name = resources.get_string_resource("Configuration/name", "");
	int config_width = resources.get_integer_resource("Configuration/width", 0 );
	int config_height = resources.get_integer_resource("Configuration/height", 0 );

	CL_Console::write_line(CL_String("name = ") + config_name );
	CL_Console::write_line(CL_String("width = ") + CL_StringHelp::int_to_text(config_width));
	CL_Console::write_line(CL_String("height = ") + CL_StringHelp::int_to_text(config_height));

	// Get a list over all classes
	std::vector<CL_String> v = resources.get_resource_names_of_type("uclass", "Classes");
	std::vector<CL_String>::iterator it;
	for(it = v.begin(); it != v.end(); ++it)
	{
		// Get one of our custom resources:
		CL_Resource resource = resources.get_resource(*it);

		// Its possible to access the dom element object in the resource:
		CL_DomElement element = resource.get_element();
		int strength = CL_StringHelp::text_to_int(element.get_attribute("strength"));
		int magic = CL_StringHelp::text_to_int(element.get_attribute("magic"));

		CL_Console::write_line(CL_String("\n") + "name = " + resource.get_name());
		CL_Console::write_line(CL_String("strength = ") + CL_StringHelp::int_to_text(strength));
		CL_Console::write_line(CL_String("magic = ") + CL_StringHelp::int_to_text(magic) );
	}

}
开发者ID:PaulFSherwood,项目名称:cplusplus,代码行数:38,代码来源:test_resources.cpp

示例9: Exception

SpriteResource::SpriteResource(CL_Resource &resource)
: mResource(resource)
{
	GAME_ASSERT(mResource.get_type() == "sprite");

	std::string basePath = mResource.get_manager().get_directory(mResource).get_file_system().get_path();
	for (CL_DomElement element = mResource.get_element().get_first_child_element(); !element.is_null(); element = element.get_next_sibling_element())
		if (element.get_tag_name() == "image")
		{
			std::string fileName = element.get_attribute("file");
			if (fileName.empty())
				throw Exception("Sprite '" + mResource.get_name() + "' has empty or missing 'file' attribute");
			mFrames.insert(std::make_pair(basePath + fileName, Frame(fileName)));
		}

	if (mFrames.empty())
		throw Exception("Sprite '" + mResource.get_name() + "' has no frames");
}
开发者ID:ermachkov,项目名称:Balance_GUI,代码行数:18,代码来源:SpriteResource.cpp

示例10: on_set_options

void CL_Button_Silver::on_set_options(const CL_DomElement &options)
{
	if (options.has_attribute("surface_up"))
		set_surface_up(new CL_Surface(options.get_attribute("surface_up"), resources), true);
	if (options.has_attribute("surface_down"))
		set_surface_down(new CL_Surface(options.get_attribute("surface_down"), resources), true);
	if (options.has_attribute("surface_disabled"))
		set_surface_disabled(new CL_Surface(options.get_attribute("surface_disabled"), resources), true);
	if (options.has_attribute("surface_highlighted"))
		set_surface_highlighted(new CL_Surface(options.get_attribute("surface_highlighted"), resources), true);
	if (options.has_attribute("font"))
		set_font(new CL_Font(options.get_attribute("font"), resources), true);
	if (options.has_attribute("font_disabled"))
		set_font_disabled(new CL_Font(options.get_attribute("font_disabled"), resources), true);
}
开发者ID:BackupTheBerlios,项目名称:flexlay-svn,代码行数:15,代码来源:button_silver.cpp

示例11: on_set_options

void CL_Component_Generic::on_set_options(const CL_DomElement &options)
{
	int x = 0, y = 0, width = 0, height = 0;

	if (options.has_attribute("x")) x = CL_String::to_int(options.get_attribute("x"));
	if (options.has_attribute("y")) y = CL_String::to_int(options.get_attribute("y"));
	if (options.has_attribute("width"))  width = CL_String::to_int(options.get_attribute("width"));
	if (options.has_attribute("height")) height = CL_String::to_int(options.get_attribute("height"));

	owner->set_position(CL_Rect(x, y, x + width, y + height));

	if (options.has_attribute("visible")) owner->show(CL_String::to_bool(options.get_attribute("visible")));
	if (options.has_attribute("enabled")) owner->enable(CL_String::to_bool(options.get_attribute("enabled")));
	if (options.has_attribute("tab_id")) owner->set_tab_id(CL_String::to_int(options.get_attribute("tab_id")));

	owner->update();
}
开发者ID:BackupTheBerlios,项目名称:flexlay-svn,代码行数:17,代码来源:component_generic.cpp

示例12: main

int ConsoleProgram::main(const std::vector<CL_String> &args)
{
	// Setup clanCore:
	CL_SetupCore setup_core;

	// Initialize the ClanLib display component
	CL_SetupDisplay setup_display;

	// Create a console Window if one does not exist:
	CL_ConsoleWindow console_window("Console", 80, 600);

try
{	
	//получение параметра запуска
	for (std::vector<CL_String>::const_iterator iter_args = args.begin(); iter_args != args.end(); ++iter_args)
		CL_Console::write_line( *iter_args );

	//получение имени директории для сохранения
	CL_String workDirectoryName;
	if (args.size() > 1)
	{
		//полное имя рабочей директории
		workDirectoryName = args[1];
		//конвертирование из CP-1251 в UTF-8 имени рабочей директории
		workDirectoryName = decode(workDirectoryName);
	}
	else
	{
		//получение полного пути к текущему каталогу
		workDirectoryName = CL_Directory::get_current();
	}

	CL_Console::write_line("workDirectoryName: %1", workDirectoryName);
	//получение имени последней директории
	CL_String locationName = CL_PathHelp::remove_trailing_slash(workDirectoryName);
	locationName = CL_PathHelp::get_filename(locationName);
	CL_Console::write_line("locationName: %1", locationName);

	CL_String tempDir = CL_PathHelp::add_trailing_slash(workDirectoryName) + "temp\\";
	CL_DirectoryScanner directoryScanner;
	directoryScanner.scan(tempDir, "*.export");
	while (directoryScanner.next())
	{
		//имя обрабатываемого файла
		CL_String fileName;

		if (directoryScanner.is_directory())
			continue;
		//получение полного имени файла экспорта
		fileName = directoryScanner.get_pathname();
		//конвертирование из CP-1251 в UTF-8
		fileName = decode(fileName);
		CL_Console::write_line("find: %1", fileName);

		//открытие XML файла
		CL_File fileXML;
		bool is_opened = fileXML.open(fileName);
		if( !is_opened )
			return PrintError( CL_String("Can't open file: ") + fileName );

		//Создание объекта DOM парсера
		CL_DomDocument document(fileXML);
		//получение root узла
		CL_DomElement root = document.get_document_element();
		if( root.get_local_name() != "resources")
		{
			CL_Console::write_line("Root name can't be: %1", root.get_local_name().c_str());
			return PrintError("");
		}

		//цикл по потомкам "resources"
		for (CL_DomNode cur = root.get_first_child(); !cur.is_null(); cur = cur.get_next_sibling())
		{
			//загрузка только спрайтов
			if (cur.get_node_name() != "sprite")
				continue;

			CL_DomElement element = cur.to_element();

			//проверка на обязательные параметры
			if (!element.has_attribute("name"))
				return PrintError("Error: can't find parametr \"name\"");

			CL_DomString name = element.get_attribute("name");
			int x = element.get_attribute_int("x");
			int y = element.get_attribute_int("y");
			//добавление спрайта
			sprites.push_back( S_Sprite(name, CL_Vec2i(x, y) ) );

			//цикл по "image" (формирование списка имен файлов)
			for (CL_DomNode cur_image = cur.get_first_child(); !cur_image.is_null(); cur_image = cur_image.get_next_sibling())
			{
				//загрузка только image
				if (cur_image.get_node_name() != "image")
					continue;
				
				CL_DomElement element_image = cur_image.to_element();
				CL_DomString file = element_image.get_attribute("file");
				
				//конвертирование из CP-1251 в UTF-8 имени файла изображения
//.........这里部分代码省略.........
开发者ID:ermachkov,项目名称:bmgui,代码行数:101,代码来源:main.cpp

示例13: on_set_options

void CL_Label_Generic::on_set_options(const CL_DomElement &options)
{
	if (options.has_attribute("text"))
		text = options.get_attribute("text");
}
开发者ID:BackupTheBerlios,项目名称:flexlay-svn,代码行数:5,代码来源:label_generic.cpp

示例14: if

void CL_GUIXMLLoaderVersion_1_0::load(CL_DomElement &element, CL_GUIComponent *parent)
{
	CL_DomElement e = element.get_first_child().to_element();

	dialog_width = 0;
	dialog_height = 0;

	while (e.is_element())
	{
		CL_String tag = e.get_tag_name();
		CL_GUIComponent *new_comp = 0;

		if (tag == "button")
		{
			CL_PushButton *co = new CL_PushButton(parent);
			if (e.has_attribute("text"))
				co->set_text(e.get_attribute("text"));
			new_comp = co;
		}
		else if (tag == "checkbox")
		{
			CL_CheckBox *co = new CL_CheckBox(parent);
			if (e.has_attribute("text"))
				co->set_text(e.get_attribute("text"));
			new_comp = co;
		}
		else if (tag == "radiobutton")
		{
			CL_RadioButton *co = new CL_RadioButton(parent);
			if (e.has_attribute("text"))
				co->set_text(e.get_attribute("text"));
			if (e.has_attribute("group"))
				co->set_group_name(e.get_attribute("group"));
			new_comp = co;
		}
		else if (tag == "label")
		{
			CL_Label *co = new CL_Label(parent);
			if (e.has_attribute("text"))
				co->set_text(e.get_attribute("text"));
			new_comp = co;
		}
		else if (tag == "toolbar")
		{
			CL_ToolBar *co = new CL_ToolBar(parent);
			new_comp = co;
		}
		else if (tag == "progressbar")
		{
			CL_ProgressBar *co = new CL_ProgressBar(parent);
			new_comp = co;
		}
		else if (tag == "lineedit")
		{
			CL_LineEdit *co = new CL_LineEdit(parent);
			if (e.has_attribute("text"))
				co->set_text(e.get_attribute("text"));
			new_comp = co;
		}
		else if (tag == "slider")
		{
			CL_Slider *co = new CL_Slider(parent);
			co->set_min(CL_StringHelp::text_to_int(e.get_attribute("min")));
			co->set_max(CL_StringHelp::text_to_int(e.get_attribute("max")));
			co->set_tick_count(CL_StringHelp::text_to_int(e.get_attribute("ticks")));
			co->set_page_step(CL_StringHelp::text_to_int(e.get_attribute("page_step")));
			new_comp = co;
		}
		else if (tag == "listview")
		{
			CL_ListView *co = new CL_ListView(parent);
			CL_ListViewHeader *header = co->get_header();

			std::vector<CL_DomNode> columns_nodes = e.select_nodes("listview_header/listview_column");
			for(size_t i = 0; i < columns_nodes.size(); ++i)
			{
				CL_DomElement column_element = columns_nodes[i].to_element();
				CL_String id = column_element.get_attribute("col_id");
				CL_String caption = column_element.get_attribute("caption");
				int width = column_element.get_attribute_int("width");

				CL_ListViewColumnHeader column = header->create_column(id, caption);
				column.set_width(width);
				header->append(column);
			}

			new_comp = co;
		}
		else if (tag == "tab")
		{
			CL_Tab *co = new CL_Tab(parent);
			new_comp = co;

			CL_DomElement tab_child = e.get_first_child().to_element();
			while (tab_child.is_element())
			{
				if (tab_child.get_tag_name() == "tabpage")
				{
					CL_String label = tab_child.get_attribute("label", "Error: NO LABEL!");
					int id = CL_StringHelp::text_to_int(tab_child.get_attribute("id", "0"));
//.........这里部分代码省略.........
开发者ID:PaulFSherwood,项目名称:cplusplus,代码行数:101,代码来源:gui_xml_loader_version_1_0.cpp


注:本文中的CL_DomElement::get_attribute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。