473,624 Members | 1,957 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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::nei ghbor(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::iterato r (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 1789

ca**********@ho tmail.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**********@ho tmail.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...@ho tmail.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::nei ghbor(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::iterato r (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 Wikstrm

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...@ho tmail.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::nei ghbor(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::iterato r (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...@h otmail.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 Wikstrm

Dec 5 '06 #6

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

Similar topics

38
3659
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...
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);
0
1943
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 layer |
14
4867
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 to an iterator method (one returning IEnumerable). I WOULD like to do this for transformative operations on a collection. I realize the need to lock target, etc. Does anyone know how to handle 'writable iterators' in C# 2?
0
2672
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
21
5694
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 classes by inheriting from it, ie. class my_bidirectional_iterator : public bidirectional_iterator<double> { ... };
16
2576
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 totally_isolated(Iterator& it) { //how do I find out if it points to the end node? }
15
2588
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 impossible to have all this data in memory, im planning to implement these containers to hold data both in memory and disk at the same time. im not sure this can be achieved using customer allocators and im wondering if there are any such...
4
2000
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 strange. The implementation looks like this (there is a lot of code, but I have only included it all for consistency. The problem is quite small and local): template<typename T> class Row<T> : public std::vector<T> {}; template<typename...
0
8238
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
8174
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
8680
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...
0
8624
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
6111
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
5565
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4082
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4176
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1485
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.