void DebugBreakpointManager::SaveState(const Poco::Path& path) const { Poco::XML::Document* doc = new Poco::XML::Document(); Poco::XML::Element* breakpoints = doc->createElement(BREAKPOINTS_TAG); doc->appendChild(breakpoints)->release(); for (std::set<unsigned long>::const_iterator i = m_ObjectBreakpoints.begin(); i != m_ObjectBreakpoints.end(); ++i) { Poco::XML::Element* objectBreakpoint = doc->createElement(OBJECT_TAG); breakpoints->appendChild(objectBreakpoint)->release(); std::stringstream ss; ss << *i; objectBreakpoint->setAttribute(ID_ATTR, ss.str()); const Object* obj = DebugUtil::GetObject(*i); if (obj) { objectBreakpoint->setAttribute(CLASSNAME_ATTR, obj->GetClassName()); } } for (Poco::HashMap<int, const Object*>::ConstIterator i = m_SmartPointerBreakpoints.begin(); i != m_SmartPointerBreakpoints.end(); ++i) { Poco::XML::Element* spBreakpoint = doc->createElement(SMARTPOINTER_TAG); breakpoints->appendChild(spBreakpoint)->release(); std::stringstream ss; ss << i->first; spBreakpoint->setAttribute(ID_ATTR, ss.str()); const Object* obj = i->second; if (i->second) { spBreakpoint->setAttribute(CLASSNAME_ATTR, obj->GetClassName()); ss.clear(); ss << obj->GetTraceId(); spBreakpoint->setAttribute(OBJECTID_ATTR, ss.str()); } } Poco::FileOutputStream writer(path.toString()); Poco::XML::DOMWriter out; out.setOptions(3); //write declaration and pretty print out.writeNode(writer, doc); doc->release(); }
void DebugUtil::SaveState() { Poco::Path path; if (!GetPersistencePath(path)) return; path.setFileName(DEBUG_UTIL_XML); Poco::XML::Document* doc = new Poco::XML::Document(); Poco::XML::Element* debugutil = doc->createElement(DEBUGUTIL_TAG); doc->appendChild(debugutil)->release(); for (std::set<unsigned int>::const_iterator i = m_TracedObjects.begin(); i != m_TracedObjects.end(); ++i) { Poco::XML::Element* traceObject = doc->createElement(TRACEOBJECT_TAG); debugutil->appendChild(traceObject)->release(); std::stringstream ss; ss << *i; traceObject->setAttribute(ID_ATTR, ss.str()); } for (std::set<std::string>::const_iterator i = m_TracedClasses.begin(); i != m_TracedClasses.end(); ++i) { Poco::XML::Element* traceClass = doc->createElement(TRACECLASS_TAG); debugutil->appendChild(traceClass)->release(); traceClass->setAttribute(NAME_ATTR, *i); } try { Poco::FileOutputStream writer(path.toString()); Poco::XML::DOMWriter out; out.setOptions(3); //write declaration and pretty print out.writeNode(writer, doc); doc->release(); // save BreakpointManager path.setFileName(DebugBreakpointManager::BREAKPOINTS_XML); GetBreakpointManager()->SaveState(path); } catch (Poco::FileException& e) { BERRY_WARN << e.displayText(); } }
bool ofXml::setValue(const string& path, const string& value) { Poco::XML::Element *e; if(element) { e = (Poco::XML::Element*) element->getNodeByPath(path); } else { ofLogWarning("ofXml") << "setValue(): no element set yet"; return false; } if(!e) { ofLogWarning("ofXml") << "setValue(): path \"" + path + "\" doesn't exist"; return false; } if(!e->firstChild()){ Poco::XML::Text *node = getPocoDocument()->createTextNode(ofToString(value)); e->appendChild(node); node->release(); return true; } if(e->firstChild()->nodeType() == Poco::XML::Node::TEXT_NODE) { Poco::XML::Text *node = getPocoDocument()->createTextNode(ofToString(value)); e->replaceChild( (Poco::XML::Node*) node, e->firstChild()); // swap out node->release(); return true; }else{ return false; } }
bool ofXml::addChild( const string& path ) { vector<string> tokens; if(path.find('/') != string::npos) { tokens = tokenize(path, "/"); } // is this a tokenized tag? if(tokens.size() > 1) { // don't 'push' down into the new nodes Poco::XML::Element *el = element; vector<Poco::XML::Element*> toBeReleased; for(std::size_t i = 0; i < tokens.size(); i++) { Poco::XML::Element *pe = getPocoDocument()->createElement(tokens.at(i)); el->appendChild(pe); toBeReleased.push_back(pe); el = pe; } if(element) { element->appendChild(el); } else { element = el; } return true; } else { Poco::XML::Element* pe = getPocoDocument()->createElement(path); if(element) { element->appendChild(pe); } else { document->appendChild(pe); element = document->documentElement(); } } return true; }
//--------------------------------------------------------- bool ofXml::setAttribute(const string& path, const string& value) { string attributeName, pathToAttribute; bool hasPath = false; // you can pass either /node[@attr] or just attr if(path.find("[@") != string::npos) { size_t attrBegin = path.find("[@"); size_t start = attrBegin + 2; size_t end = path.find("]", start); attributeName = path.substr( start, end - start ); pathToAttribute = path.substr(0, attrBegin); hasPath = true; } else { attributeName = path; } // we don't have a path to resolve Poco::AutoPtr<Poco::XML::Attr> attr = getPocoDocument()->createAttribute(attributeName); attr->setValue(value); if(!hasPath) { Poco::AutoPtr<Poco::XML::NamedNodeMap> map = element->attributes(); map->setNamedItem(attr); return true; // and we're done } // we have a path to resolve Poco::XML::Element* curElement = getPocoElement(pathToAttribute); if(!curElement) { // if it doesn't exist vector<string> tokens; if(path.find('/') != string::npos) { tokens = tokenize(pathToAttribute, "/"); } // is this a tokenized tag? if(tokens.size() > 1) { // don't 'push' down into the new nodes curElement = element; // find the last existing tag size_t lastExistingTag = 0; // can't use reverse_iterator b/c accumulate doesn't like it for(vector<string>::iterator it = tokens.end(); it != tokens.begin(); it--) { string empty = ""; string concat = accumulate(tokens.begin(), it, std::string()); Poco::XML::Element* testElement = getPocoElement(concat); if(testElement) { lastExistingTag++; curElement = testElement; break; } } // create all the tags that don't exist for(size_t i = lastExistingTag; i < tokens.size(); i++) { Poco::XML::Element *newElement = getPocoDocument()->createElement(tokens.at(i)); curElement->appendChild(newElement); curElement = newElement; } curElement->setAttribute(attributeName, value); return true; } else { Poco::XML::Element* testElement = getPocoElement(pathToAttribute); if(testElement) { curElement = testElement; } else { Poco::XML::Element *newElement = getPocoDocument()->createElement(pathToAttribute); curElement->appendChild(newElement); curElement = newElement; } curElement->setAttribute(attributeName, value); return true; } } return false; }