Login
User Name:

Password:



Register
Forgot your password?
LOP 1.39r1
Author: Remcon
Submitted by: Remcon
Yaeger areas
Author: Yaeger
Submitted by: Cyberthrope
The City of Anon
Author: Yaeger
Submitted by: Cyberthrope
The Walls of Anon - Smaug
Author: Yaeger
Submitted by: Cyberthrope
LOP 1.39
Author: Remcon
Submitted by: Remcon
CommonCrawl, Yahoo!, Yandex, Exalead, Google, Soso Spider

Members: 0
Guests: 0
Stats
Files
Topics
Posts
Members
Newest Member
375
3,323
16,511
561
Aurin
Affiliates
Smaug Building Institute Arthmoor
» SmaugMuds.org » General » Coding » STL List
Forum Rules | Mark all | Recent Posts

STL List
< Newer Topic :: Older Topic >

Pages:<< prev 1 next >>
Post is unread #1 Jul 18, 2010, 10:26 am
Go to the bottom of the page Go to the top of the page
Keirath
Magician
GroupMembers
Posts125
JoinedJan 24, 2008

So I've been slowly converting my SWR to classes and adding the appropriate constructors and destructors. Well, I got to the shuttle system and began converting it over.

The shuttle system consists of two classes - one being the shuttle_data class and the other being the stop_data class. shuttle_data has a stop_data *current pointer.
So the problem I'm having, and I'm just not sure how to tackle it is the best way to convert this to use the std::list.
                                        shuttle->current = shuttle->current->next;



Also, just to double check with those who are smarter than I on this. Is this the proper way to say if the current stop is the last element in the std::list move to the front?
                                /* Move to next spot */
                                if (shuttle->current == shuttle->stops.back( )) 
                                {
                                        shuttle->current = shuttle->stops.front( );
                                        shuttle->current_number = 1;
                                }
       
Post is unread #2 Jul 19, 2010, 3:12 am   Last edited Jul 19, 2010, 3:17 am by Caius
Go to the bottom of the page Go to the top of the page


Caius
Magician
GroupMembers
Posts118
JoinedJan 29, 2006
WWW

You could consider turning "current" into an iterator instead of a pointer:
struct SHUTTLE_DATA
{
  std::list< STOP_DATA* >::iterator current; // or whatever your "stop" class is called
};


Initialize to first stop:
shuttle->current = shuttle->stops.begin();


Next stop:
shuttle->current++;


Find out if you're at the end of the list:
if( shuttle->current == shuttle->stops.end() )


In the last example you're actually one element past the last one, rather than at it, as per normal iterator behaviour.

As for your last question could you rewrite it? I don't understand what you're asking. Perhaps a word is missing?

       
Post is unread #3 Jul 19, 2010, 3:17 am
Go to the bottom of the page Go to the top of the page


Caius
Magician
GroupMembers
Posts118
JoinedJan 29, 2006
WWW

I suddenly understood the question. Just change "front" and "back" with "begin" and "end" in your example.
       
Post is unread #4 Jul 19, 2010, 9:07 am
Go to the bottom of the page Go to the top of the page
Keirath
Magician
GroupMembers
Posts125
JoinedJan 24, 2008

I actually really like the first option better. It looks much cleaner.
       
Post is unread #5 Jul 19, 2010, 9:25 am   Last edited Jul 19, 2010, 9:43 am by Keirath
Go to the bottom of the page Go to the top of the page
Keirath
Magician
GroupMembers
Posts125
JoinedJan 24, 2008

Only thing I'm not sure about is checking if that iterator is null or not.

Basically, if I change it to be an iterator how do you make this work:
                        if (shuttle->current == NULL)

Edit - I forgot to make it
 if(*shuttle->current == NULL)

It worked after that.
       
Pages:<< prev 1 next >>

 
Contact Us