//-------------------------------------------------------------- void ofApp::setup(){ // load the file and check if it was loaded ok. Also check it's // format is correct, it needs to have: // // - a root called drawing which // - contains a background element which itself contains nodes // red, green and blue auto isLoaded = xml.load_file(ofToDataPath("points.xml").c_str()) != pugi::status_ok; isLoaded &= bool(xml.child("drawing")); isLoaded &= bool(xml.select_node("//drawing/background[red and green and blue]")); // Last check could have also been done like: // isLoaded &= bool(xml.select_node("//drawing/background/red")); // isLoaded &= bool(xml.select_node("//drawing/background/green")); // isLoaded &= bool(xml.select_node("//drawing/background/blue")); if(!isLoaded){ ofLogNotice() << "File not found or incorrect format, creating"; auto bg = xml.append_child("drawing") .append_child("background"); bg.append_child("red") .append_child(pugi::node_pcdata) .set_value("255"); bg.append_child("green") .append_child(pugi::node_pcdata) .set_value("255"); bg.append_child("blue") .append_child(pugi::node_pcdata) .set_value("255"); } // select background and read it's values auto background = xml.select_node("//background").node(); if(background){ bgColor.r = background.child("red").text().as_int(); bgColor.g = background.child("green").text().as_int(); bgColor.b = background.child("blue").text().as_int(); } // select all strokes and iterate through them // for each stroke, create a new mesh auto strokesXml = xml.select_nodes("//strokes"); for(auto & stroke: strokesXml){ strokes.emplace_back(); strokes.back().setMode(OF_PRIMITIVE_LINE_STRIP); // for each pt in the stroke insert a new // vertex in the mesh auto pts = stroke.node().children("pt"); for(auto & pt: pts){ auto x = pt.attribute("x").as_int(); auto y = pt.attribute("y").as_int(); strokes.back().addVertex({x,y,0}); } } }
static int create_folder_tree (NODE* parent, char* path) { DIR *dp = NULL; struct dirent *entry = NULL; struct stat statbuf; LOG ("enter new path = %s\n", path); if ((dp = opendir(path)) == NULL) { LOG ("Can`t open directory %s\n", path); return ; } NODE* entry_node = create_node (path); entry_node->type = D; if (parent != NULL) { entry_node->level = parent->level + 1; entry_node->parent = parent; append_child (parent, entry_node); } else root_node = entry_node; chdir(path); while ((entry = readdir(dp)) != NULL) { lstat(entry->d_name, &statbuf); if (S_ISDIR(statbuf.st_mode)) { if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0 ) continue; LOG ("dir = %s\n", entry->d_name); create_folder_tree (entry_node, entry->d_name); } else { NODE* entry_child_node = create_node (entry->d_name); entry_child_node->level = entry_node->level + 1; entry_child_node->parent = entry_node; entry_child_node->type = F; append_child (entry_node, entry_child_node); LOG ("file = %s\n", entry->d_name); } } LOG ("Leaving path %s\n", path); chdir(".."); closedir(dp); }
bool World::Serialize(std::string const& file) const { pugi::xml_document doc; auto parent = doc.append_child("World"); parent.append_attribute("version").set_value("0.0.1"); auto sysNode = parent.append_child("Systems"); for (auto system : m_systems) { auto s = sysNode.append_child("System"); s.append_attribute("name").set_value(system->GetName().c_str()); } return doc.save_file(file.c_str()); }
DomNode DomNode::insert_before(DomNode &new_child, DomNode &ref_child) { if (!ref_child.impl) { append_child(new_child); return new_child; } if (impl && new_child.impl && ref_child.impl) { DomDocument_Impl *doc_impl = (DomDocument_Impl *)impl->owner_document.lock().get(); DomTreeNode *tree_node = impl->get_tree_node(); DomTreeNode *new_tree_node = new_child.impl->get_tree_node(); DomTreeNode *ref_tree_node = ref_child.impl->get_tree_node(); new_tree_node->previous_sibling = ref_tree_node->previous_sibling; new_tree_node->next_sibling = ref_child.impl->node_index; ref_tree_node->previous_sibling = new_child.impl->node_index; if (new_tree_node->previous_sibling != cl_null_node_index) new_tree_node->get_previous_sibling(doc_impl)->next_sibling = new_child.impl->node_index; if (tree_node->first_child == ref_child.impl->node_index) tree_node->first_child = new_child.impl->node_index; new_tree_node->parent = impl->node_index; return new_child; } return DomNode(); }
void CL_DomElement::set_child_string_ns(const CL_DomString &namespace_uri, const CL_DomString &qualified_name, const CL_DomString &value) { CL_DomString local_name; CL_DomString::size_type pos = qualified_name.find(L':'); if (pos != CL_DomString::npos) local_name = qualified_name.substr(pos+1); else local_name = qualified_name; CL_DomElement element = named_item_ns(namespace_uri, local_name).to_element(); if (element.is_null()) { element = get_owner_document().create_element_ns(namespace_uri, qualified_name); append_child(element); } CL_DomText dom_text = get_owner_document().create_text_node(value); if (element.get_first_child().is_text()) { CL_DomNode temp_domnode = element.get_first_child(); replace_child(dom_text, temp_domnode); } else { element.append_child(dom_text); } }
void COptions::SetXmlValue(unsigned int nID, wxString const& value) { if (!m_pXmlFile) return; // No checks are made about the validity of the value, that's done in SetOption wxScopedCharBuffer utf8 = value.utf8_str(); if (!utf8) return; auto settings = CreateSettingsXmlElement(); if (settings) { pugi::xml_node setting; for (setting = settings.child("Setting"); setting; setting = setting.next_sibling("Setting")) { const char *attribute = setting.attribute("name").value(); if (!attribute) continue; if (!strcmp(attribute, options[nID].name)) break; } if (!setting) { setting = settings.append_child("Setting"); SetTextAttribute(setting, "name", options[nID].name); } setting.text() = utf8; } }
pugi::xml_node COptions::CreateSettingsXmlElement() { if (!m_pXmlFile) { return pugi::xml_node(); } auto element = m_pXmlFile->GetElement(); if (!element) { return element; } auto settings = element.child("Settings"); if (settings) { return settings; } settings = element.append_child("Settings"); for (int i = 0; i < OPTIONS_NUM; ++i) { if (options[i].type == string) { SetXmlValue(i, GetOption(i)); } else { SetXmlValue(i, GetOptionVal(i)); } } return settings; }
void COptions::SetXmlValue(unsigned int nID, std::wstring const& value) { if (!m_pXmlFile) { return; } // No checks are made about the validity of the value, that's done in SetOption std::string utf8 = fz::to_utf8(value); auto settings = CreateSettingsXmlElement(); if (settings) { pugi::xml_node setting; for (setting = settings.child("Setting"); setting; setting = setting.next_sibling("Setting")) { const char *attribute = setting.attribute("name").value(); if (!attribute) { continue; } if (!strcmp(attribute, options[nID].name)) { break; } } if (!setting) { setting = settings.append_child("Setting"); SetTextAttribute(setting, "name", options[nID].name); } setting.text() = utf8.c_str(); } }
unsigned long long Client::free_size() noexcept { Header header = { "Accept: */*", "Depth: 0", "Content-Type: text/xml" }; pugi::xml_document document; auto propfind = document.append_child("D:propfind"); propfind.append_attribute("xmlns:D") = "DAV:"; auto prop = propfind.append_child("D:prop"); prop.append_child("D:quokta-available-bytes"); prop.append_child("D:quota-used-bytes"); auto document_print = pugi::node_to_string(document); size_t size = document_print.length() * sizeof((document_print.c_str())[0]); Data data = { 0, 0, 0 }; Request request(GetImpl(this)->options()); request.set(CURLOPT_CUSTOMREQUEST, "PROPFIND"); request.set(CURLOPT_HTTPHEADER, (struct curl_slist *)header.handle); request.set(CURLOPT_POSTFIELDS, document_print.c_str()); request.set(CURLOPT_POSTFIELDSIZE, (long)size); request.set(CURLOPT_HEADER, 0); request.set(CURLOPT_WRITEDATA, (size_t)&data); request.set(CURLOPT_WRITEFUNCTION, (size_t)Callback::Append::buffer); auto is_performed = request.perform(); if (!is_performed) return 0; document.load_buffer(data.buffer, (size_t)data.size); pugi::xml_node multistatus = document.select_single_node("d:multistatus").node(); pugi::xml_node response = multistatus.select_single_node("d:response").node(); pugi::xml_node propstat = response.select_single_node("d:propstat").node(); prop = propstat.select_single_node("d:prop").node(); pugi::xml_node quota_available_bytes = prop.select_single_node("d:quota-available-bytes").node(); std::string free_size_text = quota_available_bytes.first_child().value(); auto free_size = atol(free_size_text.c_str()); return free_size; }
void ssd_dialog_new_entry (const char *name, const char *value, int flags, SsdCallback callback) { SsdWidget child = ssd_entry_new (name, value, flags, 0,SSD_MIN_SIZE, SSD_MIN_SIZE,""); append_child (child); ssd_widget_set_callback (child, callback); }
static void add_node(pugi::xml_node& graph, int id, std::string label) { auto node = graph.append_child("node"); node.append_attribute("id") = std::to_string(id).c_str(); auto data = node.append_child("data"); data.append_attribute("key") = "label"; data.text() = label.c_str(); }
void DjVuTXT::Zone::decode(const GP<ByteStream> &gbs, int maxtext, const Zone * parent, const Zone * prev) { ByteStream &bs=*gbs; // Decode type ztype = (ZoneType) bs.read8(); if ( ztype<PAGE || ztype>CHARACTER ) G_THROW( ERR_MSG("DjVuText.corrupt_text") ); // Decode coordinates int x=(int) bs.read16()-0x8000; int y=(int) bs.read16()-0x8000; int width=(int) bs.read16()-0x8000; int height=(int) bs.read16()-0x8000; // Decode text info text_start = (int) bs.read16()-0x8000; // int start=text_start; text_length = bs.read24(); if (prev) { if (ztype==PAGE || ztype==PARAGRAPH || ztype==LINE) { x=x+prev->rect.xmin; y=prev->rect.ymin-(y+height); } else // Either COLUMN or WORD or CHARACTER { x=x+prev->rect.xmax; y=y+prev->rect.ymin; } text_start+=prev->text_start+prev->text_length; } else if (parent) { x=x+parent->rect.xmin; y=parent->rect.ymax-(y+height); text_start+=parent->text_start; } rect=GRect(x, y, width, height); // Get children size int size = bs.read24(); // Checks if (rect.isempty() || text_start<0 || text_start+text_length>maxtext ) G_THROW( ERR_MSG("DjVuText.corrupt_text") ); // Process children const Zone * prev_child=0; children.empty(); while (size-- > 0) { Zone *z = append_child(); z->decode(gbs, maxtext, this, prev_child); prev_child=z; } }
SsdWidget ssd_dialog_new_button (const char *name, const char *value, const char **bitmaps, int num_bitmaps, int flags, SsdCallback callback) { SsdWidget child = ssd_button_new (name, value, bitmaps, num_bitmaps, flags, callback); append_child (child); return child; }
void CVerifyCertDialog::SetPermanentlyTrusted(CCertificateNotification const& notification) { const CCertificate certificate = notification.GetCertificates()[0]; unsigned int len; const unsigned char* const data = certificate.GetRawData(len); CReentrantInterProcessMutexLocker mutex(MUTEX_TRUSTEDCERTS); LoadTrustedCerts(); if (IsTrusted(notification.GetHost(), notification.GetPort(), data, len, true)) { return; } t_certData cert; cert.host = notification.GetHost(); cert.port = notification.GetPort(); cert.len = len; cert.data = new unsigned char[len]; memcpy(cert.data, data, len); m_trustedCerts.push_back(cert); if (COptions::Get()->GetOptionVal(OPTION_DEFAULT_KIOSKMODE) == 2) { return; } auto element = m_xmlFile.GetElement(); if (!element) { return; } auto certs = element.child("TrustedCerts"); if (!certs) certs = element.append_child("TrustedCerts"); auto xCert = certs.append_child("Certificate"); AddTextElement(xCert, "Data", ConvertHexToString(data, len)); AddTextElement(xCert, "ActivationTime", static_cast<int64_t>(certificate.GetActivationTime().get_time_t())); AddTextElement(xCert, "ExpirationTime", static_cast<int64_t>(certificate.GetExpirationTime().get_time_t())); AddTextElement(xCert, "Host", notification.GetHost()); AddTextElement(xCert, "Port", notification.GetPort()); m_xmlFile.Save(true); }
void QuadTree::subdivide(iterator_base & leaf_it) { QuadTreeNodeData leaf_data = *leaf_it; const RS_Vector * _p_tr = leaf_data.tr(); const RS_Vector * _p_tl = leaf_data.tl(); const RS_Vector * _p_br = leaf_data.br(); const RS_Vector * _p_bl = leaf_data.bl(); RS_Vector center((*_p_tr + *_p_bl)*0.5); RS_Vector top((*_p_tr + *_p_tl)*0.5); //mid point of top line RS_Vector bot((*_p_br + *_p_bl)*0.5); //mid point of bot line RS_Vector left((*_p_tl + *_p_bl)*0.5); //mid point of left line RS_Vector right((*_p_tr + *_p_br)*0.5); //mid point of righy line const RS_Vector * _p_center = this->add_point(center); const RS_Vector * _p_top = this->add_point(top); const RS_Vector * _p_bot = this->add_point(bot); const RS_Vector * _p_left = this->add_point(left); const RS_Vector * _p_right = this->add_point(right); iterator_base tl_child = append_child(leaf_it, QuadTreeNodeData(_p_tl, _p_top, _p_center, _p_left, QuadTreeLocation(L,T))); //tl iterator_base tr_child = append_child(leaf_it, QuadTreeNodeData(_p_top, _p_tr, _p_right, _p_center, QuadTreeLocation(R,T))); //tr iterator_base br_child = append_child(leaf_it, QuadTreeNodeData(_p_center, _p_right, _p_br, _p_bot, QuadTreeLocation(R,B))); //br iterator_base bl_child = append_child(leaf_it, QuadTreeNodeData(_p_left, _p_center, _p_bot, _p_bl, QuadTreeLocation(L,B))); //bl tl_child->region() = leaf_it->region(); tl_child->region_intersection_flag() = leaf_it->region_intersection_flag(); tl_child->line_intersection_flag() = leaf_it->line_intersection_flag(); tr_child->region() = leaf_it->region(); tr_child->region_intersection_flag() = leaf_it->region_intersection_flag(); tr_child->line_intersection_flag() = leaf_it->line_intersection_flag(); br_child->region() = leaf_it->region(); br_child->region_intersection_flag() = leaf_it->region_intersection_flag(); br_child->line_intersection_flag() = leaf_it->line_intersection_flag(); bl_child->region() = leaf_it->region(); bl_child->region_intersection_flag() = leaf_it->region_intersection_flag(); bl_child->line_intersection_flag() = leaf_it->line_intersection_flag(); }
std::string create_packet(const message::ServiceElementData* message) { pugi::xml_document doc; auto root = doc.append_child("drop"); auto node = root.append_child("service_element_data"); node.append_attribute("name").set_value(message->name().c_str()); node.append_attribute("address").set_value(message->address().c_str()); auto services = node.append_child("services"); for (const auto& s : message->services()) { services.append_child("service").append_attribute("name").set_value(s.c_str()); } std::ostringstream os; doc.save(os); return os.str(); }
//operations to build the family tree CDFamilyIterator CDFamily::addChild(CCdCore* cd, CCdCore* parentCD) { CDFamilyIterator pit; if (parentCD == 0) pit = end(); else pit = findCD(parentCD); if (pit == end()) return pit; else return append_child(pit, CDNode(cd)); }
CSSLayoutText CSSLayoutElement::create_text(const std::string &text) { if (!is_null()) { CSSLayoutText obj = impl->layout_impl.lock()->get_layout().create_text(text); append_child(obj); return obj; } else { return CSSLayoutText(); } }
CSSLayoutObject CSSLayoutElement::create_object() { if (!is_null()) { CSSLayoutObject obj = impl->layout_impl.lock()->get_layout().create_object(); append_child(obj); return obj; } else { return CSSLayoutObject(); } }
void append_before_child( mxml_node * parent, mxml_node * n, mxml_node * before ) { if ( before == NULL ) { if ( !parent->last_child && !parent->first_child ) { append_child( parent, n ); return; } else { if ( parent->first_child ) parent->first_child->prev = n; n->next = parent->first_child; parent->first_child = n; } } else { if ( before->parent == parent ) { mxml_node * aprev = before->prev; mxml_node * nparent = n->parent; if ( nparent ) { remove_child( nparent, n ); } before->prev = n; n->prev = aprev; if ( aprev ) { aprev->next = n; } n->next = before; if ( before == parent->first_child ) parent->first_child = n; } else // logic error ! return; } n->parent = parent; if ( !n->document) n->document = parent->document; }
void xtr_usf_c::finish_track() { auto subtitles = m_doc->document_element().append_child("subtitles"); subtitles.append_child("language").append_attribute("code").set_value(m_language.c_str()); for (auto &entry : m_entries) { std::string text = std::string{"<subtitle>"} + entry.m_text + "</subtitle>"; strip(text, true); std::stringstream text_in(text); pugi::xml_document subtitle_doc; if (!subtitle_doc.load(text_in, pugi::parse_default | pugi::parse_declaration | pugi::parse_doctype | pugi::parse_pi | pugi::parse_comments)) { mxwarn(boost::format(Y("Track %1%: An USF subtitle entry starting at timecode %2% is not well-formed XML and will be skipped.\n")) % m_tid % format_timecode(entry.m_start * 1000000, 3)); continue; } auto subtitle = subtitles.append_child("subtitle"); subtitle.append_attribute("start").set_value(format_timecode(entry.m_start * 1000000, 3).c_str()); subtitle.append_attribute("stop"). set_value(format_timecode(entry.m_end * 1000000, 3).c_str()); for (auto child : subtitle_doc.document_element()) subtitle.append_copy(child); } }
void TaskScheduler::saveDependencyGraph_GraphML(std::string fname) const { pugi::xml_document doc; auto root = doc.append_child("graphml"); root.append_attribute("xmlns") = "http://graphml.graphdrawing.org/xmlns"; root.append_attribute("xmlns:xsi") = "http://www.w3.org/2001/XMLSchema-instance"; root.append_attribute("xsi:schemaLocation") = "http://graphml.graphdrawing.org/xmlns " "http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd"; auto key = root.append_child("key"); key.append_attribute("id") = "label"; key.append_attribute("for") = "node"; key.append_attribute("attr.name") = "label"; key.append_attribute("attr.type") = "string"; auto graph = root.append_child("graph"); graph.append_attribute("id") = "Task graph"; graph.append_attribute("edgedefault") = "directed"; // Nodes for (const auto& t : tasks) add_node(graph, t.id, t.label); // Edges for (const auto& n : nodes) { for (auto dep : n->to) add_edge(graph, n->id, dep->id); for (auto dep : n->from_backup) add_edge(graph, dep->id, n->id); } auto filename = fname + ".graphml"; doc.save_file(filename.c_str()); }
CL_DomDocument::CL_DomDocument( const CL_DomString &namespace_uri, const CL_DomString &qualified_name, const CL_DomDocumentType &document_type) : CL_DomNode(CL_SharedPtr<CL_DomNode_Generic>(new CL_DomDocument_Generic)) { impl->owner_document = impl; CL_DomElement element = create_element(qualified_name); element.set_attribute("xmlns:" + element.get_prefix(), qualified_name); append_child(element); CL_DomDocument_Generic *doc = dynamic_cast<CL_DomDocument_Generic *>(impl.get()); const CL_DomDocument_Generic *doctype = dynamic_cast<const CL_DomDocument_Generic *>(document_type.impl.get()); doc->public_id = doctype->public_id; doc->system_id = doctype->system_id; }
DomDocument::DomDocument( const DomString &namespace_uri, const DomString &qualified_name, const DomDocumentType &document_type) : DomNode(std::shared_ptr<DomNode_Impl>(new DomDocument_Impl)) { impl->owner_document = impl; DomElement element = create_element(qualified_name); element.set_attribute("xmlns:" + element.get_prefix(), qualified_name); append_child(element); DomDocument_Impl *doc = dynamic_cast<DomDocument_Impl *>(impl.get()); const DomDocument_Impl *doctype = dynamic_cast<const DomDocument_Impl *>(document_type.impl.get()); doc->public_id = doctype->public_id; doc->system_id = doctype->system_id; }
std::string document::dump() { pugi::xml_document doc; auto root = doc.append_child("svg"); auto wid = root.append_attribute("width"); wid.set_value(width()); auto hei = root.append_attribute("height"); hei.set_value(height()); for (auto e : edges()) e->dump(&root.append_child("edge"));//name will be changed by dump std::stringstream s; doc.save(s); return s.str(); }
/* void CSSLayoutElement::apply_properties(const std::vector<CSSPropertyValue *> &properties) { if (!is_null()) { impl->layout_impl.lock()->box_tree.apply_properties(static_cast<CSSBoxElement*>(impl->box_node), properties); // Temp hack to support before and after pseudo elements. // To do: Make a better more official way to create pseudo elements. if (static_cast<CSSBoxElement*>(impl->box_node)->properties.content.type == CSSValueContent::type_string) { CSSBoxText *box_text = new CSSBoxText(); box_text->set_text(static_cast<CSSBoxElement*>(impl->box_node)->properties.content.str); impl->box_node->push_back(box_text); } } } void CSSLayoutElement::apply_properties(const std::string &style_string, const std::string &base_uri) { apply_properties(CSSDocument::get_style_properties(style_string, base_uri)); } */ void CSSLayoutElement::insert_before(CSSLayoutNode &new_child, CSSLayoutNode &ref_child) { if (!is_null() && !new_child.is_null()) { if (ref_child.is_null()) { append_child(new_child); } else { if (new_child.impl->box_node->get_parent()) throw Exception("Node already has a parent"); if (ref_child.impl->box_node->get_parent() != impl->box_node) throw Exception("Node is not a direct child of this element"); impl->box_node->insert(new_child.impl->box_node, ref_child.impl->box_node); } } }
void CL_DomElement::set_child_string(const CL_DomString &name, const CL_DomString &value) { CL_DomElement element = named_item(name).to_element(); if (element.is_null()) { element = get_owner_document().create_element(name); append_child(element); } while (!element.get_first_child().is_null()) { CL_DomNode my_child = element.get_first_child(); element.remove_child(my_child); } CL_DomText dom_text = get_owner_document().create_text_node(value); element.append_child(dom_text); }
void test_tree() { TreeNode<int> *root = tree_node_new<int>(); root->data = 0; TreeNode<int> *node1 = append_child(root, 1); /*TreeNode<int> *node2 = */append_child(root, 2); /*TreeNode<int> *node3 = */append_child(root, 3); /*TreeNode<int> *node4 = */append_child(node1, 4); TreeNode<int> *node5 = append_child(node1, 5); /*TreeNode<int> *node6 = */append_child(node5, 6); preorder2(root, PrintFunc()); }
void COptions::SetServer(std::wstring path, const CServer& server) { if (!m_pXmlFile) { return; } if (path.empty()) { return; } auto element = m_pXmlFile->GetElement(); while (!path.empty()) { std::wstring sub; size_t pos = path.find('/'); if (pos != std::wstring::npos) { sub = path.substr(0, pos); path = path.substr(pos + 1); } else { sub = path; path.clear(); } std::string utf8 = fz::to_utf8(sub); auto newElement = element.child(utf8.c_str()); if (newElement) { element = newElement; } else { element = element.append_child(utf8.c_str()); } } ::SetServer(element, server); if (GetOptionVal(OPTION_DEFAULT_KIOSKMODE) == 2) { return; } CInterProcessMutex mutex(MUTEX_OPTIONS); m_pXmlFile->Save(true); }
std::string ProviderWithChecksum::serializeManifest() { pugi::xml_document manifestDoc; auto decl = manifestDoc.prepend_child(pugi::node_declaration); decl.append_attribute("version") = "1.0"; decl.append_attribute("encoding") = "UTF-8"; auto root = manifestDoc.root().append_child(); root.set_name("checksums"); for (auto &p : contents) { auto node = root.append_child(); node.set_name("checksum"); node.text().set(p.first.cStr()); node.append_attribute("SHA1") = p.second.c_str(); } std::stringstream ss; manifestDoc.save(ss, " "); return ss.str(); }