本文整理汇总了C++中CL_DomNode类的典型用法代码示例。如果您正苦于以下问题:C++ CL_DomNode类的具体用法?C++ CL_DomNode怎么用?C++ CL_DomNode使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CL_DomNode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: loadBoundsElement
void Level::loadBoundsElement(const CL_DomNode &p_boundsNode)
{
const CL_DomNodeList boundList = p_boundsNode.get_child_nodes();
const int boundListSize = boundList.get_length();
for (int i = 0; i < boundListSize; ++i) {
const CL_DomNode boundNode = boundList.item(i);
if (boundNode.get_node_name() == "bound") {
CL_DomNamedNodeMap attrs = boundNode.get_attributes();
float x1 = CL_StringHelp::local8_to_float(attrs.get_named_item("x1").get_node_value());
float y1 = CL_StringHelp::local8_to_float(attrs.get_named_item("y1").get_node_value());
float x2 = CL_StringHelp::local8_to_float(attrs.get_named_item("x2").get_node_value());
float y2 = CL_StringHelp::local8_to_float(attrs.get_named_item("y2").get_node_value());
x1 *= Block::WIDTH;
y1 *= Block::WIDTH;
x2 *= Block::WIDTH;
y2 *= Block::WIDTH;
cl_log_event("debug", "Loading bound %1 x %2 -> %3 x %4", x1, y1, x2, y2);
const CL_LineSegment2f segment(CL_Pointf(x1, y1), CL_Pointf(x2, y2));
m_bounds.push_back(CL_SharedPtr<Bound>(new Bound(segment)));
} else {
cl_log_event("race", "Unknown node '%1', ignoring", boundNode.get_node_name());
}
}
}
示例2: is_null
bool CL_DomNode::operator ==(const CL_DomNode &other) const
{
if (is_null() || other.is_null())
return is_null() == other.is_null();
else
return impl->node_index == other.impl->node_index;
}
示例3: get_next_sibling
CL_DomElement CL_DomElement::get_next_sibling_element() const
{
CL_DomNode node = get_next_sibling();
while (!node.is_null() && !node.is_element())
node = node.get_next_sibling();
return node.to_element();
}
示例4: loadMetaElement
void Level::loadMetaElement(const CL_DomNode &p_metaNode)
{
m_width = p_metaNode.select_int("size/width");
m_height = p_metaNode.select_int("size/height");
cl_log_event("race", "level size set to %1 x %2", m_width, m_height);
}
示例5: while
void TexturePacker::process_resource(CL_Resource &item_resource, std::vector<CL_Subtexture> &packed_sub_textures, std::map<CL_Texture, CL_String> &generated_texture_filenames, int &generated_texture_index, const CL_String &image_pathname )
{
// Found a sprite resource, lets modify its content!
CL_Resource resource = item_resource;
// Iterate through all nodes, and remove all previous image tags
CL_DomElement &element = resource.get_element();
CL_DomNode cur = element.get_first_child();
while (!cur.is_null())
{
CL_DomNode next = cur.get_next_sibling();
CL_DomNode::NodeType nodeType = (CL_DomNode::NodeType)cur.get_node_type();
// Only remove the <image> tag, as we want to keep the other sprite attributes
if (cur.get_node_name() == "image")
element.remove_child(cur);
cur = next;
}
// Add new image tag to resource DOM
std::vector<CL_Subtexture>::size_type index, size;
size = packed_sub_textures.size();
for(index = 0; index < size; ++index)
{
CL_Subtexture subtexture = packed_sub_textures[index];
// Try to find out if we already have created a texture-on-disk for this subtexture
CL_String texture_filename;
CL_Texture texture = subtexture.get_texture();
std::map<CL_Texture, CL_String>::iterator it;
it = generated_texture_filenames.find(texture);
if(it == generated_texture_filenames.end())
{
// Texture not found, generate a filename and dump texture to disk
texture_filename = cl_format("texture%1.png", ++generated_texture_index);
CL_PNGProvider::save(texture.get_pixeldata(), image_pathname + texture_filename);
generated_texture_filenames[texture] = texture_filename;
}
else
{
// Previously dumped textures, lets reuse the filename
texture_filename = (*it).second;
}
// Add <grid> DOM element
CL_DomElement new_grid_element = element.get_owner_document().create_element("grid");
new_grid_element.set_attribute("pos", cl_format("%1,%2", subtexture.get_geometry().left + last_border_size, subtexture.get_geometry().top + last_border_size));
new_grid_element.set_attribute("size", cl_format("%1,%2", subtexture.get_geometry().get_width()- last_border_size*2, subtexture.get_geometry().get_height()- last_border_size*2));
// Add <image> DOM element
CL_DomElement new_image_element = element.get_owner_document().create_element("image");
new_image_element.set_attribute("file", texture_filename);
new_image_element.append_child(new_grid_element);
// Add <image> element under <sprite> element
element.append_child(new_image_element);
}
}
示例6: select_node
CL_String CL_DomNode::select_string(const CL_DomString &xpath_expression) const
{
CL_DomNode node = select_node(xpath_expression);
if (node.is_element())
return node.to_element().get_text();
else
return node.get_node_value();
}
示例7: get_first_child
CL_DomNode CL_DomNode::named_item(const CL_DomString &name) const
{
CL_DomNode node = get_first_child();
while (node.is_null() == false)
{
if (node.get_node_name() == name) return node;
node = node.get_next_sibling();
}
return CL_DomNode();
}
示例8: get_attributes
bool CL_DomElement::has_attribute_ns(
const CL_DomString &namespace_uri,
const CL_DomString &local_name) const
{
if (impl)
{
CL_DomNode attribute = get_attributes().get_named_item_ns(namespace_uri, local_name);
return attribute.is_attr();
}
return false;
}
示例9: get_first_child
CL_DomElement CL_DomDocument::get_document_element()
{
CL_DomNode cur = get_first_child();
while (!cur.is_null())
{
if (cur.is_element())
return cur.to_element();
cur = cur.get_next_sibling();
}
return CL_DomElement();
}
示例10: oldnode
CL_DomNode CL_DomNamedNodeMap::set_named_item(const CL_DomNode &node)
{
int size = impl->attributes.size();
for (int i=0; i<size; i++)
{
if (impl->attributes[i].first == node.to_attr().get_name())
{
CL_DomNode oldnode(impl->attributes[i].second);
impl->attributes[i].second = node;
return oldnode;
}
}
impl->attributes.push_back(std::pair<std::string, CL_DomNode>(node.to_attr().get_name(), node));
return CL_DomNode();
}
示例11: to_element
CL_DomString CL_DomNode::find_prefix(const CL_DomString &namespace_uri) const
{
CL_DomElement cur = to_element();
while (!cur.is_null())
{
CL_DomNamedNodeMap attributes = cur.get_attributes();
int size = attributes.get_length();
for (int index = 0; index < size; index++)
{
CL_DomNode attribute = attributes.item(index);
if (attribute.get_prefix() == "xmlns" &&
attribute.get_node_value() == namespace_uri)
{
return attribute.get_local_name();
}
}
cur = cur.get_parent_node().to_element();
}
return CL_DomString();
}
示例12: cloneElement
//рекурсивное клонирование XML-элемента
CL_DomElement cloneElement(CL_DomElement &element, CL_DomDocument &doc)
{
//создаем элемент-клон
CL_DomElement clone(doc, element.get_tag_name());
//копируем атрибуты
CL_DomNamedNodeMap attributes = element.get_attributes();
unsigned long length = attributes.get_length();
for (unsigned long i = 0; i < length; ++i)
{
CL_DomNode attr = attributes.item(i);
clone.set_attribute(attr.get_node_name(), attr.get_node_value());
}
//рекурсивно копируем дочерние элементы
for (CL_DomElement child = element.get_first_child_element(); !child.is_null(); child = child.get_next_sibling_element())
clone.append_child(cloneElement(child, doc));
//возвращаем клонированный элемент
return clone;
}
示例13: load_sprite
ResourceItem *TexturePacker::load_resource(CL_GraphicContext &gc, CL_String &resource_id, CL_Resource &resource, CL_ResourceManager &resources)
{
ResourceItem *item = 0;
try
{
CL_String type = resource.get_type();
if(type == "sprite")
{
item = load_sprite(gc, resource_id, resource, resources);
}
else if(type == "image")
{
item = load_image(gc, resource_id, resource, resources);
}
else
{
throw CL_Exception(cl_format("Resourcetype %1 is not supported", type));
}
}
catch(CL_Exception ex)
{
item = new NotSupportedResourceItem(resource, ex.message);
}
// Find resource path by traversing parents
CL_DomElement &dom_element = resource.get_element();
CL_DomNode parent = dom_element.get_parent_node();
while (!parent.is_null())
{
CL_DomElement parent_element = parent.to_element();
CL_String parent_name = parent_element.get_attribute("name");
if(parent_name.length() > 0)
item->resource_path = cl_format("%1/%2", parent_name, item->resource_path);
parent = parent.get_parent_node();
}
return item;
}
示例14: assert
void Level::loadFromFile(const CL_String& p_filename)
{
assert(!m_loaded && "level is already loaded");
try {
CL_File file(p_filename, CL_File::open_existing, CL_File::access_read);
CL_DomDocument document(file);
const CL_DomElement root = document.get_document_element();
// load meta element
const CL_DomNode metaNode = root.named_item("meta");
loadMetaElement(metaNode);
// gets level's content
const CL_DomNode contentNode = root.named_item("content");
// load sand
const CL_DomNode sandNode = contentNode.named_item("sand");
loadSandElement(sandNode);
// load track
const CL_DomNode trackNode = contentNode.named_item("track");
loadTrackElement(trackNode);
// load track bounds
const CL_DomNode boundsNode = contentNode.named_item("bounds");
loadBoundsElement(boundsNode);
file.close();
m_loaded = true;
} catch (CL_Exception e) {
CL_Console::write_line(e.message);
}
}
示例15: get_first_child
CL_String CL_DomElement::get_text() const
{
CL_String str;
if (has_child_nodes() == false)
return str;
CL_DomNode cur = get_first_child();
while (!cur.is_null())
{
if (cur.is_text() || cur.is_cdata_section())
str.append(cur.get_node_value());
if (cur.is_element())
str.append(cur.to_element().get_text());
cur = cur.get_next_sibling();
}
return str;
}