tiled_objectgroup::tiled_objectgroup( xml_node<>* node ) { // find the name attribute for ( auto attr=node->first_attribute(); attr; attr=attr->next_attribute() ) { if ( attr->name() == string("name") ) { name = attr->value(); // I don't know why I don't include a break statement after // finding the name attribute. } } // Loop through all the internal nodes within the current objectgroup // for the purpose of building object_vec. for ( auto object_node=node->first_node(); object_node; object_node=object_node->next_sibling() ) { tiled_object to_push; // Build to_push using the attributes of object_node. for ( auto attr=object_node->first_attribute(); attr; attr=attr->next_attribute() ) { stringstream attr_sstm; attr_sstm << attr->value(); if ( attr->name() == string("id") ) { attr_sstm >> to_push.id; } else if ( attr->name() == string("gid") ) { attr_sstm >> to_push.gid_raw; // Tiled stores hflip and vflip within an object's gid // parameter. to_push.gid = to_push.gid_raw & 0x3fffffff; to_push.vflip = to_push.gid_raw & 0x40000000; to_push.hflip = to_push.gid_raw & 0x80000000; // subtract the gid by 1 if ( to_push.gid > 0 ) { --to_push.gid; } }
void mlUnitInfo::fetch( const std::string & name ) { pugi::xml_document doc; doc.load_file( ("ini/units/" + name + ".xml").c_str() ); auto root = doc.root().first_child(); while( root.attribute( "template" ) ) { pugi::xml_document doc; doc.load_file( root.attribute( "template" ).as_string() ); root.remove_attribute( "template" ); auto temp = doc.root().first_child(); for( auto attr = temp.first_attribute(); attr; attr = attr.next_attribute() ) { auto attrRoot = root.attribute( attr.name() ); if( !attrRoot ) attrRoot = root.append_attribute( attr.name() ); attrRoot.set_value( attr.value() ); } } Info info; info.layer = strToUnitLayer( root.attribute( "unitlayer" ).as_string() ); info.type = strToUnitType( root.attribute( "unittype" ).as_string() ); info.radius = root.attribute( "radius" ).as_float(); _info.insert( std::pair<std::string, Info>( name, info ) ); }
// Build the vector of tiled_object_property's void tiled_object::build_property_vec( xml_node<>* properties_node ) { for ( auto inner_node = properties_node->first_node(); inner_node; inner_node = inner_node->next_sibling() ) { tiled_object_property to_push; for ( auto attr=inner_node->first_attribute(); attr; attr=attr->next_attribute() ) { if ( attr->name() == string("name") ) { to_push.name = attr->value(); } else if ( attr->name() == string("value") ) { to_push.value = attr->value(); } } property_vec.push_back(to_push); } }
int checkSearchEntry(BerElement *ber) { int rc = LDAP_SUCCESS; ber_tag_t tag; ber_len_t len =0; BerValue attr; BerVarray vals; attr.bv_val = NULL; attr.bv_len = 0; char *a; int n; struct berval dn = BER_BVNULL; BerElement ber_value, ber_backup; ber_value = ber_backup= *ber; #ifdef DEBUG int ival = -1; ber_set_option( NULL, LBER_OPT_DEBUG_LEVEL, &ival ); #endif n=0; for ( a = first_attribute( ber ); a != NULL; a = next_attribute( ber ) ) { struct berval **vals; //printf( "| | ATTR: %s\n", a ); if ( (vals = get_values_len( &ber_value, a )) == NULL ) { printf( "| | %s:\t(no values)\n" , a); }else { int i; for ( i = 0; vals[i] != NULL; i++ ) { int j, nonascii; nonascii = 0; for ( j = 0; (ber_len_t) j < vals[i]->bv_len; j++ ) //Non-display ASCII will be shown as HEX, It is Control code before 33 in ASCII Table if ( !isascii( vals[i]->bv_val[j] ) || vals[i]->bv_val[j] < 33 ) { nonascii = 1; break; } if ( nonascii ) { printf( "|-%s(not ascii):\tlen (%ld) \n",a, vals[i]->bv_len ); ber_bprint( vals[i]->bv_val, vals[i]->bv_len ); continue; } #ifdef DETAIL printf( "|-%s:\tlen (%ld) \t%s\n",a, vals[i]->bv_len, vals[i]->bv_val ); #else printf( "|-%s:\t\t%s\n",a, vals[i]->bv_val ); #endif } ber_bvecfree( vals ); } ber_value = ber_backup; n++; } return n; }
// Print children of the node template<class OutIt, class Ch> inline OutIt print_children(OutIt out, const xml_node<Ch> *node, int flags, int indent) { for (xml_node<Ch> *child = node->first_node(); child; child = child->next_sibling()) out = print_node(out, child, flags, indent); return out; } // Print attributes of the node template<class OutIt, class Ch> inline OutIt print_attributes(OutIt out, const xml_node<Ch> *node, int flags) { Q_UNUSED(flags) for (xml_attribute<Ch> *attribute = node->first_attribute(); attribute; attribute = attribute->next_attribute()) { if (attribute->name() && attribute->value()) { // Print attribute name *out = Ch(' '), ++out; out = copy_chars(attribute->name(), attribute->name() + attribute->name_size(), out); *out = Ch('='), ++out; // Print attribute value using appropriate quote type if (find_char<Ch, Ch('"')>(attribute->value(), attribute->value() + attribute->value_size())) { *out = Ch('\''), ++out; out = copy_and_expand_chars(attribute->value(), attribute->value() + attribute->value_size(), Ch('"'), out); *out = Ch('\''), ++out; } else
/** * Description: 利用访问控制策略生成二叉树 * Input: * policy: 访问控制策略,形如: "((A OR BC)AND(E OR FG))AND((H AND IJ)OR(K OR MN))" * 属性与AND/OR之间利用空格隔开,利用小括号将一个逻辑表达式括起来。为简约存储开销,括弧与括弧、属性、AND/OR之间不用空格 * Output: * 返回建立的属性二叉树的根节点 */ node * generate_tree(const string & policy) { // 声明两个堆栈,分别用来存储 (and or not),及由AND OR ATTRIBUTE构建的二叉树根节点 stack<string> string_stack; stack<node *> node_stack; int i = 0; // 遍历访问策略,首先将属性,AND,OR分离,然后在不同的情况下做出不同的处理 while (i < policy.length()) { string word = ""; // while (1) // { if (policy.at(i) == '(') { word = "("; string_stack.push(word); i++; // break; } else if (policy.at(i) == ')') { // 右括弧,利用string_stack的栈顶元素构建树节点,左右孩子分别为node_stack的栈顶两个元素 // 然后将构建的节点压入node_stack栈,string_stack退出栈顶的左括弧 word = ")"; node *r; if(string_stack.top() == "not") r = NULL; else { r = node_stack.top(); node_stack.pop(); } node *l = node_stack.top(); node_stack.pop(); node *n = new node(string_stack.top(), l, r); node_stack.push(n); string_stack.pop(); string_stack.pop(); i++; // break; } else if (policy.at(i) == ' ') { i++; // break; } else { word = next_attribute(policy, i); if (word == "and" || word == "or" || word == "not" ) { // AND OR 压入string_stack栈内 string_stack.push(word); } else { // 属性值构建叶子节点,并入栈 node *n = new node(word); node_stack.push(n); } // break; } // } //cout << word << "---" << endl; } node * r; if(string_stack.top() == "not") { r = NULL; } else { r = node_stack.top(); node_stack.pop(); } node *l = node_stack.top(); node_stack.pop(); node * root = new node(string_stack.top(), l, r); string_stack.pop(); //search(root); return root; }
{ params.maxIterations_ = atoi(att->value()); } else if (word == "collpipelineiterations") { params.pipelineIterations_ = atoi(att->value()); } else if (word == "extents") { std::stringstream myStream(att->value()); myStream >> params.extents_[0] >> params.extents_[1] >> params.extents_[2] >> params.extents_[3] >> params.extents_[4] >> params.extents_[5]; params.setHasExtents(true); } att = att->next_attribute(); } n = root->first_node("RigidBodyList"); //std::cout << "Name of the current node: " << n->name() << "\n"; if(n) n = n->first_node(); else { return; //std::cerr << "Token RigidBodyList not found" << std::endl; } for (; n; n = n->next_sibling())