By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,227 Members | 1,376 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,227 IT Pros & Developers. It's quick & easy.

storing iterator in a class

P: n/a
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<Characterwill point on the deque<Pointover 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<Pointwhich 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<Pointcan be viewed as Page = Character =Point. or even Page
=Stroke =Point or something else.

Thanks for help
abir

Nov 3 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
"toton" <ab*******@gmail.comwrote in message
news:11**********************@k70g2000cwa.googlegr oups.com...
: 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<Characterwill point on the deque<Pointover 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<Pointwhich 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
--
http://ivan.vecerina.com/contact/?subject=NG_POST <- email contact form
Brainbench MVP for C++ <http://www.brainbench.com

Nov 3 '06 #2

P: n/a

Ivan Vecerina wrote:
"toton" <ab*******@gmail.comwrote in message
news:11**********************@k70g2000cwa.googlegr oups.com...
: 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<Characterwill point on the deque<Pointover 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<Pointwhich 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
hth -Ivan
--
http://ivan.vecerina.com/contact/?subject=NG_POST <- email contact form
Brainbench MVP for C++ <http://www.brainbench.com
Nov 3 '06 #3

P: n/a
"toton" <ab*******@gmail.comwrote:
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<Characterwill point on the deque<Pointover 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<Pointwhich 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<Pointcan 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.

--
To send me email, put "sheltie" in the subject.
Nov 4 '06 #4

P: n/a
"toton" <ab*******@gmail.comwrote in message
news:11**********************@h48g2000cwc.googlegr oups.com...
: 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
:

Nov 4 '06 #5

P: n/a

Daniel T. wrote:
"toton" <ab*******@gmail.comwrote:
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<Characterwill point on the deque<Pointover 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<Pointwhich 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<Pointcan 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.
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....59255dcd4915e0
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
--
To send me email, put "sheltie" in the subject.
Nov 6 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.