473,799 Members | 3,224 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

storing iterator in a class

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<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<Pointwhic h 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
5 1857
"toton" <ab*******@gmai l.comwrote in message
news:11******** **************@ k70g2000cwa.goo glegroups.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<Character will 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<Pointwhic h 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_typ e 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

Ivan Vecerina wrote:
"toton" <ab*******@gmai l.comwrote in message
news:11******** **************@ k70g2000cwa.goo glegroups.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<Character will 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<Pointwhic h 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_typ e 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
"toton" <ab*******@gmai l.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<Character will 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<Pointwhic h 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
"toton" <ab*******@gmai l.comwrote in message
news:11******** **************@ h48g2000cwc.goo glegroups.com.. .
: If you only work with the end of the deque, storing indices (e.g.
: two deque::size_typ e 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

Daniel T. wrote:
"toton" <ab*******@gmai l.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<Character will 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<Pointwhic h 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

38
3695
by: Grant Edwards | last post by:
In an interview at http://acmqueue.com/modules.php?name=Content&pa=showpage&pid=273 Alan Kay said something I really liked, and I think it applies equally well to Python as well as the languages mentioned: I characterized one way of looking at languages in this way: a lot of them are either the agglutination of features or they're a crystallization of style. Languages such as APL, Lisp, and Smalltalk are what you might call style...
4
2508
by: Scott Smedley | last post by:
Hi all, I'm trying to write a special adaptor iterator for my program. I have *almost* succeeded, though it fails under some circumstances. See the for-loop in main(). Any pointers/help would be muchly appreciated. Apologies for the long post - I couldn't find a shorter way to
26
1514
by: Michael Klatt | last post by:
I am trying to write an iterator for a std::set that allows the iterator target to be modified. Here is some relvant code: template <class Set> // Set is an instance of std::set<> class Iterator { public : typedef typename Set::value_type T; typedef typename Set::iterator SetIterator; Iterator(Set& container, const SetIterator& it);
2
2498
by: prasanthag | last post by:
Hi, I am a newbie to this group. I have a problem in handling the variable arguments passed to a function. My requirement is like this. I have 2 functions say, void funcX(int i, int j); void funcY(int i, int j,char *name);
0
1443
by: toton | last post by:
Hi, I have a little design related problem, and finding a good way to resolve it. To state the problem, I have points from writing of several documents. Each document represents a Session class , and a SessionManager holds a deque of Session. Session holds deque of Page for that document. Page in turn holds vector of Char in that page. However Char do not hold the Point associated with that Char. Instead it holds a pair of iterator for...
0
2681
by: mailforpr | last post by:
Hi. Let me introduce an iterator to you, the so-called "Abstract Iterator" I developed the other day. I actually have no idea if there's another "Abstract Iterator" out there, as I have never looked for one on the net (I did browse the boost library though). It doesn't matter right now, anyway. To put it simply, Abstract Iterator is mainly a wrapper class. It helps
20
4652
by: Martin Jørgensen | last post by:
Hi, I'm reading a number of double values from a file. It's a 2D-array: 1 2 3 4 5 6 7 ------------- 1 3.2 2 0 2.1 3 9.3 4
8
1955
by: Mike Jolley | last post by:
Hello First off, I'm a student so I'm pretty new to C++, and therefore I have probably made a stupid mistake somewhere. Anyway Ive been trying to fix this 5 hours straight now, so i need a little assistance. What I'm trying to do I am using inheritance to make some bookings for a marina, which are: Booking
2
2143
by: jeet232 | last post by:
I've a class 'Parent' I declare a map using map<Parent, Parent> mymap; Now I derive one child 'Child' and I've to add it to this map, so I do a static_cast like this: Child* key = new Child(); Child* val = new Child(); mymap.insert(pair<Parent, Parent>(static_cast<Parent&>(*key), static_cast<Parent&>(*val)));
0
9538
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10470
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10214
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10023
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9067
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7561
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5583
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3751
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2935
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.