Пример #1
0
bool TCODBsp::traverseLevelOrder(ITCODBspCallback *listener, void *userData) {
	TCODList<TCODBsp *> stack;
	stack.push(this);
	while ( ! stack.isEmpty() ) {
		TCODBsp *node=stack.get(0);
		stack.remove(node);
		if ( node->getLeft() ) stack.push(node->getLeft());
		if ( node->getRight() ) stack.push(node->getRight());
		if (!listener->visitNode(node,userData)) return false;
	}
	return true;
}
Пример #2
0
// computes the page tree and auto-numbers pages
void buildTree() {
	// get the list of root (level 0) pages
	TCODList<PageData *>rootPages;
	for (PageData **it=pages.begin();it!=pages.end();it++) {
		// page requires at least a @PageName and @PageTitle
		if (! (*it)->name ) {
			printf ("ERROR : page #%d (%s) in %s has no @PageName\n",
				(*it)->fileOrder,(*it)->name ? (*it)->name : "null", (*it)->filename);
			it=pages.remove(it);
			continue;
		}
		if (! (*it)->title ) {
			printf ("ERROR : page #%d (%s) in %s has no @PageTitle\n",
				(*it)->fileOrder,(*it)->name ? (*it)->name : "null",(*it)->filename);
			it=pages.remove(it);
			continue;
		}
		if ( (*it)->fatherName == NULL ) rootPages.push(*it);
	}
	// first, order the level 0 pages according to their category
	int categId=0;
	while ( categs[categId] ) {	
		for (PageData **it=pages.begin();it!=pages.end();it++) {
			if ( (*it)->fatherName == NULL && strcmp((*it)->categoryName,categs[categId]) == 0 ) {
				// new root page
				root->numKids++;
				(*it)->father=root;
				(*it)->order=root->numKids;
				char tmp[1024];
				sprintf(tmp,"%d",(*it)->order);
				(*it)->pageNum=strdup(tmp);
				sprintf(tmp,"doc/html2/%s.html",(*it)->name);
				(*it)->url=strdup(tmp);
				sprintf(tmp,"<a onclick=\"link('../index2.html')\">Index</a> &gt; <a onclick=\"link('%s.html')\">%s. %s</a>",
					(*it)->name,(*it)->pageNum,(*it)->title);
				(*it)->breadCrumb=strdup(tmp);						
				rootPages.remove(*it);
			}
		}
		categId++;
	}
	// pages with unknown categories
	for ( PageData **it=rootPages.begin(); it != rootPages.end(); it++) {
		printf ("ERROR : unknown category '%s' in page '%s'\n",(*it)->categoryName,(*it)->name);
		pages.remove(*it);
	}
	// build the subpages tree
	for (PageData **it=pages.begin();it!=pages.end();it++) {
		if ( (*it)->fatherName != NULL ) {
			// sub-page. find its daddy and order
			(*it)->father=getPage((*it)->fatherName);
			if ( ! (*it)->father ) {
				printf ("ERROR : unknown father '%s' for page '%s'\n",
					(*it)->fatherName,(*it)->name);
				it=pages.remove(it);
				continue;
			}
			(*it)->father->numKids++;
			(*it)->order=(*it)->father->numKids;
		}
	}
	// now compute sub-page numbers 
	TCODList<PageData *> hierarchy;
	bool missing=true;
	while ( missing ) {
		missing=false;
		for (PageData **it=pages.begin();it!=pages.end();it++) {
			if ((*it)->pageNum == NULL ) {
				PageData *page=*it;
				if ( page->father->pageNum == NULL ) {
					missing=true;
				} else {                
					char tmp[256];
					sprintf(tmp,"%s.%d", page->father->pageNum,page->order);
					page->pageNum = strdup(tmp);
					sprintf(tmp,"doc/html2/%s.html",page->name);
					page->url=strdup(tmp);
				}
			}
		}
	}
	// now compute prev/next links and breadcrumbs for sub pages
	for (PageData **it=pages.begin();it!=pages.end();it++) {
		PageData *page=*it;
		page->prev=getPrev(page);
		// prev link
		if ( page->prev ) {
			char tmp[1024];
			sprintf (tmp,
				"<a class=\"prev\" onclick=\"link('%s.html')\">%s. %s</a>",
				page->prev->name,page->prev->pageNum,page->prev->title);
			page->prevLink=strdup(tmp);
		}
		// next link
		page->next=getNext(page);
		if ( page->next ) {
			char tmp[1024];
			sprintf (tmp,
				"%s<a class=\"next\" onclick=\"link('%s.html')\">%s. %s</a>",
				page->prev ? "| " : "",
				page->next->name,page->next->pageNum,page->next->title);
			page->nextLink=strdup(tmp);
		}
		// breadCrumb
		if (! page->breadCrumb ) {
			char tmp[1024];
			TCODList<PageData *> hierarchy;
			PageData *curPage=page;
			while ( curPage ) {
				hierarchy.push(curPage);
				curPage=curPage->father;
			}
			char *ptr=tmp;
			ptr[0]=0;
			while ( ! hierarchy.isEmpty() ) {
				curPage=hierarchy.pop();
				if ( curPage == root ) {
					sprintf(ptr, "<a onclick=\"link('../%s.html')\">%s</a>", 
						curPage->name,curPage->title);
				} else {
					sprintf(ptr, " &gt; <a onclick=\"link('%s.html')\">%s. %s</a>", 
						curPage->name,curPage->pageNum,curPage->title);
				}
				ptr += strlen(ptr);
			}
			page->breadCrumb =strdup(tmp);
		}
	}
}