473,320 Members | 1,876 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

STL customer iterator

I am very new to STL and generic programming. PLEASE help.
I have my own class looks like:

class pixelProperty {
public:
// get-functions here...
private:
Point mPosition;
int mCenterID;
Color mColor;
}

Basically the pixelProperty represents a 2D image data. To make it
more convenience for pixle random access, I would like to use the
Vector container in STL but with an "enhanced" iterator which give me
more convenience such as using a member function in the iterator,
myiterator::neighbor(x,y), which give me a 2d-style random access.

My questions are:
1) Can I acutally make my customer iterator by composition or inherit
from the vector::iterator (how about deriving from or composing the
vector container class - I read some posts in the forum but not fully
understand.... ) . if it is possible, could any one can be kind enough
to show me an example?

2) I would like to use a customer a random access iterator with the
STL algorithm (such as find()), take the pixelProperty as the data
type, how can I implement this STL-compatible iterator?

I really new to this area, any help will be greatly appreciated.
Thanks in advance.
Sheldon

Dec 5 '06 #1
5 1771

ca**********@hotmail.com ha escrito:
I am very new to STL and generic programming. PLEASE help.
I have my own class looks like:

class pixelProperty {
public:
// get-functions here...

Cai:

Take a look at the book "The C++ Standard Library: A Tutorial and
Reference" by Nicolai M. Josuttis. There you will find an excellent
guide to start working with containers and iterators.

Hope this help.

Dec 5 '06 #2
Thanks flagos:
I am reading this book but could not find anything related with
customer iterator.
Is my question is too simple to ask or too simple to answer?

Thanks anyway.
Sheldon

flagos wrote:
ca**********@hotmail.com ha escrito:
I am very new to STL and generic programming. PLEASE help.
I have my own class looks like:

class pixelProperty {
public:
// get-functions here...


Cai:

Take a look at the book "The C++ Standard Library: A Tutorial and
Reference" by Nicolai M. Josuttis. There you will find an excellent
guide to start working with containers and iterators.

Hope this help.
Dec 5 '06 #3
On Dec 5, 11:58 am, cai_xiaod...@hotmail.com wrote:
I am very new to STL and generic programming. PLEASE help.
I have my own class looks like:

class pixelProperty {
public:
// get-functions here...
private:
Point mPosition;
int mCenterID;
Color mColor;

}Basically the pixelProperty represents a 2D image data. To make it
more convenience for pixle random access, I would like to use the
Vector container in STL but with an "enhanced" iterator which give me
more convenience such as using a member function in the iterator,
myiterator::neighbor(x,y), which give me a 2d-style random access.

My questions are:
1) Can I acutally make my customer iterator by composition or inherit
from the vector::iterator (how about deriving from or composing the
vector container class - I read some posts in the forum but not fully
understand.... ) . if it is possible, could any one can be kind enough
to show me an example?
Either inheritance of composition should work, but from the iterators
and not the vector. It can be quite a lot of work if you are using
composition or have many special requirements.
2) I would like to use a customer a random access iterator with the
STL algorithm (such as find()), take the pixelProperty as the data
type, how can I implement this STL-compatible iterator?
Just make sure that your iterator has the same interface and
functionality as STL ones. To find documentation about the STL
iterators google for "wg21c++", the first result is the standard group,
go to paper ans find a draft (working copy) and download. The part of
interest is section 24.1 "Iterator requirements".

--
Erik Wikström

Dec 5 '06 #4
Thanks Eriwik:
I have checked the document. Quite understandable , but still feel a
bit difficult for me to implement one without an example.
Anyone else can give a hand?

Sheldon .

"er****@student.chalmers.se 写é“:
"
On Dec 5, 11:58 am, cai_xiaod...@hotmail.com wrote:
I am very new to STL and generic programming. PLEASE help.
I have my own class looks like:

class pixelProperty {
public:
// get-functions here...
private:
Point mPosition;
int mCenterID;
Color mColor;

}Basically the pixelProperty represents a 2D image data. To make it
more convenience for pixle random access, I would like to use the
Vector container in STL but with an "enhanced" iterator which give me
more convenience such as using a member function in the iterator,
myiterator::neighbor(x,y), which give me a 2d-style random access.

My questions are:
1) Can I acutally make my customer iterator by composition or inherit
from the vector::iterator (how about deriving from or composing the
vector container class - I read some posts in the forum but not fully
understand.... ) . if it is possible, could any one can be kind enough
to show me an example?

Either inheritance of composition should work, but from the iterators
and not the vector. It can be quite a lot of work if you are using
composition or have many special requirements.
2) I would like to use a customer a random access iterator with the
STL algorithm (such as find()), take the pixelProperty as the data
type, how can I implement this STL-compatible iterator?

Just make sure that your iterator has the same interface and
functionality as STL ones. To find documentation about the STL
iterators google for "wg21c++", the first result is the standard group,
go to paper ans find a draft (working copy) and download. The part of
interest is section 24.1 "Iterator requirements".

--
Erik Wikström
Dec 5 '06 #5
On Dec 5, 2:55 pm, "food4uk" <cai_xiaod...@hotmail.comwrote:
Thanks Eriwik:
I have checked the document. Quite understandable , but still feel a
bit difficult for me to implement one without an example.
Anyone else can give a hand?
Next time, type your reply below what you are replying to.

As for your problem, what exactly do you want your iterator to do that
a normal iterator does not, if you are just adding functionality a
normal inheritance should do most of the work for you, if you need to
change some of the behaviour normal inheritance and just overriding one
or two methods might do. Ask yourself in which way your iterator is
different from an STL-iterator and what special considerations your
iterator might have, which of the STL-iterator methods/operators will
work the same and which won't.

--
Erik Wikström

Dec 5 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

38
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...
26
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...
0
by: nick | last post by:
Hi, I need to manage a "layered" collection of objects, where each layer grows independently, e.g, o--+--+--+--+--+ 1st layer | o 2nd layer (empty) | o--+--+--+ 3rd...
14
by: shawnk | last post by:
I searched the net to see if other developers have been looking for a writable iterator in C#. I found much discussion and thus this post. Currently (C# 2) you can not pass ref and out arguments...
0
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...
21
by: T.A. | last post by:
I understand why it is not safe to inherit from STL containers, but I have found (in SGI STL documentation) that for example bidirectional_iterator class can be used to create your own iterator...
16
by: mailforpr | last post by:
How do I do that? The thing is, the only information I have about the iterator is the iterator itself. No container it is belonging to or anything. Like template<Iteratorvoid...
15
by: CMOS | last post by:
one of the projects im working in currently requires use of ultra large sized maps, lists, vector, etc. (basically stl containers). Sizes might grow up to 1000 Million entries. since it is...
4
by: mkborregaard | last post by:
Hi, I have the weirdest problem, and I can not see what is going wrong. I have made a 2d container class, and am implementing an iterator for that class. However, the ++ operator is behaving very...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.