Andreas Vox wrote: > Hi!
Hi Andreas, > As a newbie I'm still trying to figure out how to use > the various iterators. My current hypotheses are: > > DocIterator is used to iterate the whole document in a > preorder style. Ok. > ParagraphIterator is used to iterate over paragraphs local > to one surrounding inset. > > InsetIterator iterates over the whole document but only > gives insets. Not quite: These two are mere wrappers arount DocIterator, basically DocIterator is NOT a forward iterator (it doesn't have operator++, but forward{Par,Pos,Inset} methods), and these two are. All three iterate in a full subtree of the lyx document tree (i.e. get into insets). > > My questions are: > > 1. How do I iterate over all text and insets on one level, > without going into the insets, and with insets interspersed > into the text in the right order? Eg. for the document > A: (P: (bla I:() blabla J:(soso K:() aha) blablabla) P: ...) > I want to iterate the first P: inset and want to get: > bla, I, blabla, J, blablabla Just use a ParagraphList::iterator for iterating over paragraphs (it is a std::vector) I'd do something like (untested code) ParagraphList::iterator it = paragraphs().begin(); ParagraphList::iterator end = paragraphs().end(); for (; it != end; ++it) { for (lyx::pos_type pos = 0; pos != it->size(); ++pos) { if (it->isInset(pos)) ; //do something else { char c = it->getChar(pos); //do something else } } } If this is needed in more than one place, it could be wrapped into an iterator class (Something like FlatIterator?). Another option would be to use a PosIterator/DocIterator and just jump over insets incrementing manually the position. > 2. Is there something like a PCDATA-inset for plain text? How do you eat that? (I mean, what's PCDATA?) > 3. Which iterator would I use to iterate all mathhull-insets > for snippet collection? Insetiterator? Yes. > > 4. Are these iterators compatible with STL? Mostly, with the notable exception of not having a compatible operator*. But there was some discussion in the STL about this very subject IIRC. They could probably be made so. Cheers, Alfredo