Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > STL customer iterator

Reply
Thread Tools

STL customer iterator

 
 
cai_xiaodong@hotmail.com
Guest
Posts: n/a
 
      12-05-2006
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

 
Reply With Quote
 
 
 
 
flagos
Guest
Posts: n/a
 
      12-05-2006

http://www.velocityreviews.com/forums/(E-Mail Removed) 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.

 
Reply With Quote
 
 
 
 
food4uk
Guest
Posts: n/a
 
      12-05-2006
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:
> (E-Mail Removed) 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.


 
Reply With Quote
 
eriwik@student.chalmers.se
Guest
Posts: n/a
 
      12-05-2006
On Dec 5, 11:58 am, (E-Mail Removed) 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

 
Reply With Quote
 
food4uk
Guest
Posts: n/a
 
      12-05-2006
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 .

"(E-Mail Removed) 写道:
"
> On Dec 5, 11:58 am, (E-Mail Removed) 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


 
Reply With Quote
 
eriwik@student.chalmers.se
Guest
Posts: n/a
 
      12-05-2006
On Dec 5, 2:55 pm, "food4uk" <(E-Mail Removed)> wrote:
> 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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
List iterator assignment fails, assert iterator not dereferencable David Bilsby C++ 5 10-09-2007 02:05 PM
What makes an iterator an iterator? Steven D'Aprano Python 28 04-20-2007 03:34 AM
Difference between Java iterator and iterator in Gang of Four Hendrik Maryns Java 18 12-22-2005 05:14 AM
How to convert from std::list<T*>::iterator to std::list<const T*>::iterator? PengYu.UT@gmail.com C++ 6 10-30-2005 03:31 AM
Iterator doubts, Decision on Iterator usage greg C++ 6 07-17-2003 01:26 PM



Advertisments