storing iterator in a class

T

toton

Hi,
I have a deque of Point class,. Point class have two fields x, and y.
Now I want another class Character should point to a portion of the
deque, and allow iteration only on the portion.
Thus a deque<Character> will point on the deque<Point> over different
ranges.
Both are dynamic in the sense, new character, and hence new point gets
added, while old character and old points get removed.

My question is, what the Character will store as pointer to
deque<Point>? Two size_t / or int as start and past end pointer, or two
iterator? With iterator, I am facing problem is that they are not
default construct able. Like Character class can point to another
deque<Point> which stores some modified set of points, and are
available only after performing some computation.

In general, I need different views on same set of data. Say the
deque<Point> can be viewed as Page => Character => Point. or even Page
=> Stroke => Point or something else.

Thanks for help
abir
 
I

Ivan Vecerina

: I have a deque of Point class,. Point class have two fields x, and y.
: Now I want another class Character should point to a portion of the
: deque, and allow iteration only on the portion.
: Thus a deque<Character> will point on the deque<Point> over different
: ranges.
: Both are dynamic in the sense, new character, and hence new point gets
: added, while old character and old points get removed.
Caveat: any insertion/removal in a deque will invalidate all iterators
(including any call to a pop or push function).

Because of this, std::deque is not the ideal container if you work
with a lot of iterators. (also because deque iterators do not
provide the best performance...).

: My question is, what the Character will store as pointer to
: deque<Point>? Two size_t / or int as start and past end pointer, or
two
: iterator? With iterator, I am facing problem is that they are not
: default construct able. Like Character class can point to another
: deque<Point> which stores some modified set of points, and are
: available only after performing some computation.

If you only work with the end of the deque, storing indices (e.g.
two deque::size_type values), is probably a better choice.

hth -Ivan
 
T

toton

Ivan said:
: I have a deque of Point class,. Point class have two fields x, and y.
: Now I want another class Character should point to a portion of the
: deque, and allow iteration only on the portion.
: Thus a deque<Character> will point on the deque<Point> over different
: ranges.
: Both are dynamic in the sense, new character, and hence new point gets
: added, while old character and old points get removed.
Caveat: any insertion/removal in a deque will invalidate all iterators
(including any call to a pop or push function).
I don't use deque in actual implementation a circular_buffer much like
http://www.goodliffe.net/cbuf.html. It has a advantage, that it wraps
the index with a modulo. In my case, it can also change the size (which
of course needs copy ) if required. i.e it is semi-fixed sized, while
allows index wrapping.
Because of this, std::deque is not the ideal container if you work
with a lot of iterators. (also because deque iterators do not
provide the best performance...). Thanks for making this point.
: My question is, what the Character will store as pointer to
: deque<Point>? Two size_t / or int as start and past end pointer, or
two
: iterator? With iterator, I am facing problem is that they are not
: default construct able. Like Character class can point to another
: deque<Point> which stores some modified set of points, and are
: available only after performing some computation.

If you only work with the end of the deque, storing indices (e.g.
two deque::size_type values), is probably a better choice.
Thanks. Then I will store indices (size_t or size_type) . However it
stores only a range of the deque (or my container) not the whole thing.
In when I need points from the deque, I need to create two iterators
from the indices and return them. Probably I need to store a reference
to the container also. Then when I need points, I can return
container.begin()+begin_index , and container.begin()+end_index as two
iterator. As the container is random access, hope it won't cost more.
Am I on the write track?
Once again , thanks for the answer.
abir
 
D

Daniel T.

toton said:
I have a deque of Point class,. Point class have two fields x, and y.
Now I want another class Character should point to a portion of the
deque, and allow iteration only on the portion.
Thus a deque<Character> will point on the deque<Point> over different
ranges.
Both are dynamic in the sense, new character, and hence new point gets
added, while old character and old points get removed.

My question is, what the Character will store as pointer to
deque<Point>? Two size_t / or int as start and past end pointer, or two
iterator? With iterator, I am facing problem is that they are not
default construct able. Like Character class can point to another
deque<Point> which stores some modified set of points, and are
available only after performing some computation.

In general, I need different views on same set of data. Say the
deque<Point> can be viewed as Page => Character => Point. or even Page
=> Stroke => Point or something else.

I suggest you reverse things. Instead of having a single deque and then
several containers representing parts of the deque, try creating several
deques (one for each part) and another class that knows how to jump from
deque to deque thus treating them as one.
 
I

Ivan Vecerina

: > If you only work with the end of the deque, storing indices (e.g.
: > two deque::size_type values), is probably a better choice.
: Thanks. Then I will store indices (size_t or size_type) . However it
: stores only a range of the deque (or my container) not the whole
thing.
: In when I need points from the deque, I need to create two iterators
: from the indices and return them. Probably I need to store a reference
: to the container also. Then when I need points, I can return
: container.begin()+begin_index , and container.begin()+end_index as two
: iterator. As the container is random access, hope it won't cost more.
std::deque is random access, so performance will be ok.
[ a deque iterator has at least a size of 2-pointers, so this won't
be more expensive size-wise either ]

: Am I on the write track?
At this technical level yet. I can't speak for the whole design ... ;)

Cheers,
Ivan

: Once again , thanks for the answer.
: abir
:
: > hth -Ivan
: > --
: > http://ivan.vecerina.com/contact/?subject=NG_POST <- email contact
form
: > Brainbench MVP for C++ <> http://www.brainbench.com
:
 
T

toton

Daniel said:
I suggest you reverse things. Instead of having a single deque and then
several containers representing parts of the deque, try creating several
deques (one for each part) and another class that knows how to jump from
deque to deque thus treating them as one.
That is certainly an alternative. However I frequently need a uniform
treatment to all of the points, and such jump are needed, while
sometimes need to have a character-wise access.
Also I need different views of the points, other than character. In
that case, it is problematic if I store the points inside the character
as a deque. The problem is which view the data ( the deque of Point)
should represent? Will it store deque of Points for character, or
stroke or anything else. In any case, for any other view the same
problem arrives. That's why I decided to have a single deque. I raised
the issue in a separate thread
http://groups.google.com/group/comp...915e0?lnk=gst&q=toton&rnum=6#4e59255dcd4915e0
though , no one replied :(
And the program is supposed to run in a low memory device (PDA's ) ,
thus I want to make the caching effect as dominating as possible.

Thanks again for reply.
abir
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top