Login
User Name:

Password:



Register
Forgot your password?
Vote for Us!
auth_update crash
Dec 23, 2017, 10:15 pm
By Remcon
check_tumble
Dec 18, 2017, 7:21 pm
By Remcon
parse description bug
Dec 15, 2017, 10:08 pm
By Remcon
Couple bugs
Dec 12, 2017, 5:42 pm
By Remcon
Bug in disarm( )
Nov 12, 2017, 6:54 pm
By GatewaySysop
LoP 1.46
Author: Remcon
Submitted by: Remcon
LOP 1.45
Author: Remcon
Submitted by: Remcon
LOP Heroes Edition
Author: Vladaar
Submitted by: Vladaar
Heroes sound extras
Author: Vladaar
Submitted by: Vladaar
6Dragons 4.3
Author: Vladaar
Submitted by: Vladaar
Users Online
CommonCrawl, Yandex, Majestic-12

Members: 0
Guests: 9
Stats
Files
Topics
Posts
Members
Newest Member
478
3,708
19,242
612
Jacki72H
Today's Birthdays
There are no member birthdays today.
Related Links
» 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 top of the page
Go to the bottom of the page

Keirath
Magician
GroupMembers
Posts144
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 top of the page
Go to the bottom of the page

Caius
Magician
GroupMembers
Posts132
JoinedJan 29, 2006

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 top of the page
Go to the bottom of the page

Caius
Magician
GroupMembers
Posts132
JoinedJan 29, 2006

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 top of the page
Go to the bottom of the page

Keirath
Magician
GroupMembers
Posts144
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 top of the page
Go to the bottom of the page

Keirath
Magician
GroupMembers
Posts144
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 >>