|
Boost Users : |
From: shunsuke (pstade.mb_at_[hidden])
Date: 2007-02-16 13:33:06
abir basak wrote:
> Hi,
> I am having a few containers whose some portion I want to refer to
> another class (sometime I need to refer to a continuous portion, while
> sometime need a non-continuous portion) .
> At present I have written all of these myself. But wondering if a few
> portion can be substituted by some boost library.
>
> Just to make the concept clear, I am elaborating the structure and why
> it is done in that way.
> In the program it takes the user handwriting (as entered using digital
> pen etc) and analysis them.
> as user writes, I register points (x,y coord) and put them in an deque
> (in actual case I am using boost::circular_buffer_space_optimized ).
>
> Now, a second deque (or other container) stores another structure Trace,
> which has 2 index pointing start & end of that continuous writing until
> pen up occurs. These have to be 2 index rather than iterator, as
> iterator may get (and usually gets ) invalidated while more points are
> added in the point deque. Thus Trace refers deque<Point>
> Now from the trace structure I return the points for the trace
> (boost::sub_range ) using the 2 index and the deque (i.e from
> deque<Point> get iterator, add index as offset , make sub_range and
> return).
> Now these are the continues portions , referred by 2 index.
> Next, some such things can be even not continuous. In that case I store
> all index to which it points (in a vector ) and return a sub_range kind
> of structure (named index_range ) which takes these index and a
> container, and iterates over it jumping by those specific offsets.
>
> Example can be a Character class which refers some of those traces , not
> necessarily continuous (like user writes a dot much later than the i ,
> thus Character i contains index of the vertical stroke of the i & dot )
>
> Similarly more hierarchy are constructed, like Trace => Page, and
> Character => Word => Line => Paragraph => Page etc.
>
> Most of them contains 2 index and with the help of the container returns
> a boost sub_range , while some contains a vector of index (size_t) and
> returns index_range (created by me) .
>
> So far I found it is the ONLY way to create a level of hierarchy/ view
> from different set of dynamic data. (The other can be storing everything
> as a pointer in the container, and creating by new, in that case no
> problem arises as the objects are not movable, but in C++ it is quite
> bad solution)
>
> A Graphical representation is like,
> =============== deque<Point> =====================
> <=remove old data => add new data
> | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
> =============== deque<Trace> ====================
> | 1 | 2 |
> =============== deque<Page> =====================
>
> These are for continuous data (i.e 2 index struct & boost::sub_range )
>
> ================ deque<Trace> ====================
> |1,3,4| 2 | 5,6 | 7,9 | 8 | ...
> ================== deque<Character> ===============
> | 1,2,4, 5 | 3 | ....
> ================== deque<Word> =====================
> | 1 | 2 | 3 | .... (assuming past a line user doesn't correct word, they
> can be made a pair of index ! )
> ================== deque<Line> =====================
> ....
> ================== deque<Paragraph> ================ etc...
>
> My question ,
> 1) had anyone faced these kind of design , where a class referrers a
> portion of STL container ? and multiple view from same set of data
> exists (otherwise I could had Trace contains the points , instead of
> having index of the portion, if Trace is the only view for the points )
>
> 2) Any boost library / other library is there to help these kind of
> design ?
>
> I had posted a same kind of topic in C++ newsgroup also, but it seems
> their people are more concerned with answering C++ standard based
> question . I think, boost may be the better news group to ask this
> question, as boosters work in a broader area.
>
> Thanks to all, esp to those who share their thought on it ...
> abir
>
Though I can't understand exactly what you mean because of my poor english,
I guess the solution is polymorphic range, which is the 'iterator_range'
of 'any_iterator'?
Assume 'make_xxx' returns 'iterator_range' of 'xxx_iterator'.
deque<any_range> traces;
traces.push_back(make_counting(1, 5)); // continuous (light-weight)
traces.push_back(an_index_range); // non-continuous (needs its own
storage)
Draw( make_permutation(points, traces[0]) );
Draw( make_permutation(points, traces[1]) );
If my guess is right, I'll specify urls of 'any_iterator' implementations.
Regards,
-- Shunsuke Sogame
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net