+Toc::iterator TocBackend::findItem(Toc & toc, int depth, docstring const & str)
+{
+ if (toc.empty())
+ return toc.end();
+ Toc::iterator it = toc.begin();
+ Toc::iterator itend = toc.end();
+ for (; it != itend; ++it) {
+ if (it->depth() == depth && it->str() == str)
+ break;
+ }
+ return it;
+}
+
+
+///////////////////////////////////////////////////////////////////////////
+//
+// TocBuilder implementation
+//
+///////////////////////////////////////////////////////////////////////////
+
+TocBuilder::TocBuilder(shared_ptr<Toc> toc)
+ : toc_(toc ? toc : lyx::make_shared<Toc>()),
+ stack_()
+{
+ LATTEST(toc);
+}
+
+void TocBuilder::pushItem(DocIterator const & dit, docstring const & s,
+ bool output_active, bool is_captioned)
+{
+ toc_->push_back(TocItem(dit, stack_.size(), s, output_active));
+ frame f = {
+ toc_->size() - 1, //pos
+ is_captioned, //is_captioned
+ };
+ stack_.push(f);
+}
+
+void TocBuilder::captionItem(DocIterator const & dit, docstring const & s,
+ bool output_active)