本文整理汇总了C++中tree::begin方法的典型用法代码示例。如果您正苦于以下问题:C++ tree::begin方法的具体用法?C++ tree::begin怎么用?C++ tree::begin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tree
的用法示例。
在下文中一共展示了tree::begin方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: list_if
int list_if(tree<int> &T,
list<int> &L,
bool (*pred)(int)) {
L.clear();
if (T.begin()!=T.end())
list_if(T,T.begin(),L,pred);
}
示例2: print_subtree_bracketed
void print_subtree_bracketed(const tree<T>& t, typename tree<T>::iterator iRoot, std::ostream& str)
{
if(t.begin() == t.end()) return;
if (t.number_of_children(iRoot) == 0) {
str << *iRoot;
}
else {
// parent
str << *iRoot;
str << "(";
// child1, ..., childn
int siblingCount = t.number_of_siblings(t.begin(iRoot));
int siblingNum;
typename tree<T>::sibling_iterator iChildren;
for (iChildren = t.begin(iRoot), siblingNum = 0; iChildren != t.end(iRoot); ++iChildren, ++siblingNum) {
// recursively print child
print_subtree_bracketed(t,iChildren,str);
// comma after every child except the last one
if (siblingNum != siblingCount - 1 ) {
str << ", ";
}
}
str << ")";
}
}
示例3: writeSiblingsXML
void writeSiblingsXML(const tree<AstNode>& t, const tree<AstNode>::iterator iRoot, ostream& stream)
{
if(t.empty())
return;
if (iRoot->getType() == "root") {
tree<AstNode>::sibling_iterator iChildren = t.begin(iRoot);
stream << "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" << endl;
writeSiblingsXML(t,iChildren,stream);
}
else if (t.number_of_children(iRoot) == 0) {
string type = iRoot->getType();
stream << "<php:" << type << '>';
if (iRoot->getValue().length() > 0)
stream << htmlentities(iRoot->getValue());
stream << "</php:" << type << '>' << endl;
}
else {
string type = iRoot->getType();
string xmlns="";
if (type == "start")
xmlns = " xmlns:php=\"http://php.net/csl\"";
stream << "<php:" << type << xmlns << '>' << endl;
int siblingNum;
tree<AstNode>::sibling_iterator iChildren;
for (iChildren = t.begin(iRoot), siblingNum = 0; iChildren != t.end(iRoot); ++iChildren)
{
writeSiblingsXML(t,iChildren,stream);
}
stream << "</php:" << type << '>' << endl;
}
}
示例4: print_tree_bracketed
void print_tree_bracketed(const tree<T>& t, std::ostream& str)
{
int headCount = t.number_of_siblings(t.begin());
int headNum = 0;
for(typename tree<T>::sibling_iterator iRoots = t.begin(); iRoots != t.end(); ++iRoots) {
print_subtree_bracketed(t,iRoots,str);
if (headNum <= headCount - 1) {
str << std::endl;
}
}
}
示例5: printTree
void printTree(tree<T> const &intree, std::ostream& str=std::cout)
{
int nhead(0);
auto now(intree.begin());
while(intree.is_valid(now)){
str << " " << *now << boost::format(" <-- [Head](%3d)") % nhead++ << std::endl;
for(typename tree<T>::iterator sib = intree.begin(now);sib != intree.end(now);++sib){
for(int i = 0;i < intree.depth(sib);++i) str << "---";
str << "> ";
str << *sib << std::endl;
} // End sib
now = intree.next_at_same_depth(now);
} // End while
}
示例6: findNodeWithPathFromNode
tree_node_<FILE_ITEM>* CFileTree::findNodeWithPathFromNode(std::string path, tree_node_<FILE_ITEM>* node)
{
tree<FILE_ITEM>::sibling_iterator sib = filesTree.begin(node);
tree<FILE_ITEM>::sibling_iterator end = filesTree.end(node);
bool currentLevel = true;
std::string currentPath = _first_dirname(path);
size_t position = currentPath.size();
std::string followingPath = _following_path(path);
currentLevel = followingPath.empty();
while (sib != end) {
// printf("sib->path '%s' lv %d curpath '%s' follow '%s'\n", sib->path, currentLevel, currentPath.c_str(), followingPath.c_str());
if (strcmp(sib->path, currentPath.c_str()) == 0) {
if (currentLevel) {
return sib.node;
}
else {
return findNodeWithPathFromNode(followingPath, sib.node);
}
}
++sib;
}
return NULL;
}
示例7: GenerateSubTree
/*!
* \fn static bool GenerateSubTree(const tree<HTML::Node> &tDom, const string &tagname, tree<HTML::Node> &tSubDom);
* \brief 生成子树
* \param [in]DOM原树
* \param [in]子树根节点的标签名
* \param [out]DOM子树
* \return bool
* \date 2011-06-01
* \author nanjunxiao
*/
bool Pretreat::GenerateSubTree(const tree<HTML::Node> &tDom, const std::string &tagname, tree<HTML::Node> &tSubDom)//目前只是为body使用
{
tree<HTML::Node>::iterator tIter = tDom.begin();
tree<HTML::Node>::sibling_iterator tFromIter,tToIter;
string sTagName;
for (; tIter != tDom.end(); ++tIter)
{
/*if (tIter->tagName() == tagname)
break;*/
if (tIter->isTag() )
{
sTagName = tIter->tagName();
transform(sTagName.begin(), sTagName.end(), sTagName.begin(), ::tolower);
if (sTagName == tagname)
break;
}
}
if (tIter == tDom.end() )
{
return false;
}
tFromIter = tIter;
tToIter = tDom.next_sibling(tFromIter);
tDom.subtree(tSubDom, tFromIter, tToIter);
return true;
}
示例8: graph2tree
//---:---<*>---:---<*>---:---<*>---:---<*>---:---<*>
void graph2tree(map<int, list<int> > &G,
tree<int> &T) {
// Buscar la raiz. Para eso recorremos los padres (claves
// de G) y buscamos cual no esta en la lista de hijos
set<int> fathers, sons, tmp;
map<int, list<int> >::iterator q = G.begin();
while (q!=G.end()) {
fathers.insert(q->first);
tmp.clear();
set_union(q->second.begin(),q->second.end(),
sons.begin(),sons.end(),
inserter(tmp,tmp.end()));
swap(tmp,sons);
q++;
}
// Saca de `fathers' los hijos, el unico que deberia
// quedar es la raiz
tmp.clear();
set_difference(fathers.begin(),fathers.end(),
sons.begin(),sons.end(),
inserter(tmp,tmp.end()));
assert(tmp.size()==1);
int root = *tmp.begin();
// printf("root of tree is %d\n",root);
graph2tree(G,root,T,T.begin());
}
示例9: followingPath
tree_node_<FILE_ITEM>* CFileTree::findNodeWithPathFromNode(std::string path, tree_node_<FILE_ITEM>* node)
{
tree<FILE_ITEM>::sibling_iterator sib = filesTree.begin(node);
tree<FILE_ITEM>::sibling_iterator end = filesTree.end(node);
bool currentLevel = true;
std::string currentPath = path.substr(0, path.find('\\'));
size_t position = path.find('\\');
std::string followingPath("");
if (position != std::string::npos) {
followingPath = path.substr(path.find('\\') + 1);
currentLevel = false;
}
while (sib != end) {
if (strcmp(sib->path, currentPath.c_str()) == 0) {
if (currentLevel) {
return sib.node;
}
else {
return findNodeWithPathFromNode(followingPath, sib.node);
}
}
++sib;
}
return NULL;
}
示例10: operator
void RenameClass::operator()(tree<AstNode>& tr, MapClasses* classes, MapVariables* vars, MapFunctions *func) {
// for every names in the class, generate a new *unique* name
map<string, string> classNames;
for (MapClasses::iterator iter = classes->begin(); iter != classes->end(); ++iter)
{
string newName = generateName();
classNames.insert(make_pair(iter->first, newName));
}
map<string, string>::iterator cter;
tree<AstNode>::iterator parent;
for (tree<AstNode>::iterator iter=tr.begin(); iter!=tr.end(); ++iter)
{
parent = tr.parent(iter);
if (iter->getType() == "text"
&& parent->getType() == "T_STRING"
&& (tr.parent(parent)->getType() == "unticked_class_declaration_statement"
|| tr.parent(parent)->getType() == "function_call" // constructor
|| tr.parent(parent)->getType() == "class_name_reference"
|| tr.parent(parent)->getType() == "fully_qualified_class_name"
)
&& ((cter=classNames.find(iter->getValue())) != classNames.end())) {
// rename the currenet node
iter->setValue(cter->second);
}
}
}
示例11: AddItem
FILE_ITEM CFileTree::AddItem(char *absolutePath, unsigned char* handle)
{
FILE_ITEM item;
item.handle = handle;
item.bCached = false;
if (filesTree.empty()) {
item.path = new char[strlen(absolutePath) + 1];
strcpy_s(item.path, (strlen(absolutePath) + 1), absolutePath);
item.nPathLen = strlen(item.path);
filesTree.set_head(item);
topNode = filesTree.begin();
}
else {
std::string sPath(absolutePath);
tree_node_<FILE_ITEM>* parentNode = findParentNodeFromRootForPath(absolutePath);
std::string splittedPath = sPath.substr(sPath.find_last_of('\\') + 1);
item.path = new char[splittedPath.length() + 1];
strcpy_s(item.path, (splittedPath.length() + 1), splittedPath.c_str());
if (parentNode) {
filesTree.append_child(tree<FILE_ITEM>::iterator_base(parentNode), item);
} else {
//printf("Parent node found for %s", absolutePath);
}
}
DisplayTree(topNode.node, 0);
return item;
}
示例12: WeaveNet
void WeaveNet(SQcont<T> const &incont, tree<T> &outnet)
{
outnet.clear();
auto top(outnet.begin());
auto now(outnet.insert(top, *incont.cbegin()));
for(auto c = incont.cbegin()+1;c != incont.cend();++c)
now = outnet.append_child(now, *c);
}
示例13: clean_pattern
/**
Clean the possible patterns annotations:
$enter_new_statement ...
*/
void clean_pattern(tree<AstNode>& tr) {
for (tree<AstNode>::iterator iter=tr.begin(); iter!=tr.end(); ++iter) {
if (iter->getType() == "text" && iter->getValue() == "$enter_the_new_statement") {
iter = rewind(iter, "statement", tr);
tr.erase(iter);
break;
}
}
}
示例14: detectAfterStmt
bool detectAfterStmt(const tree<AstNode>& tr) {
unsigned short ret = 0;
for (tree<AstNode>::iterator iter=tr.begin(); iter!=tr.end(); ++iter) {
if (iter->getType() == "text" && iter->getValue() == "$__END_OBF_HERE") {
return true;
}
}
return false;
}
示例15: AddItem
FILE_ITEM CFileTree::AddItem(char *absolutePath, unsigned char* handle)
{
FILE_ITEM item;
item.handle = handle;
item.bCached = false;
// If the tree is empty just add the new path as node on the top level.
if (filesTree.empty()) {
item.path = new char[strlen(absolutePath) + 1];
strcpy_s(item.path, (strlen(absolutePath) + 1), absolutePath);
item.nPathLen = strlen(item.path);
filesTree.set_head(item);
topNode = filesTree.begin();
}
else {
// Check if the requested path belongs to an already registered parent node.
std::string sPath(absolutePath);
tree_node_<FILE_ITEM>* parentNode = findParentNodeFromRootForPath(absolutePath);
std::string splittedPath = _basename_932(sPath);
//printf("spl %s %s\n", splittedPath.c_str(), absolutePath);
item.path = new char[splittedPath.length() + 1];
strcpy_s(item.path, (splittedPath.length() + 1), splittedPath.c_str());
// If a parent was found use th parent.
if (parentNode) {
//printf("parent %s\n", parentNode->data.path);
filesTree.append_child(tree<FILE_ITEM>::iterator_base(parentNode), item);
} else {
// Node wasn't found - most likely a new root - add it to the top level.
//printf("No parent node found for %s. Adding new sibbling.", absolutePath);
item.path = new char[strlen(absolutePath) + 1];
strcpy_s(item.path, (strlen(absolutePath) + 1), absolutePath);
item.nPathLen = strlen(item.path);
filesTree.insert(tree<FILE_ITEM>::iterator_base(topNode), item);
topNode = filesTree.begin();
}
}
DisplayTree(topNode.node, 0);
return item;
}