Login
User Name:

Password:



Register
Forgot your password?
Vote for Us!
 parse description bug
Yesterday, 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
Bug in will_fall( )
Oct 23, 2017, 1:35 am
By GatewaySysop
Bug in do_zap( ), do_brandish( )
Oct 18, 2017, 1:52 pm
By GatewaySysop
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
Memwatch
Author: Johan Lindh
Submitted by: Vladaar
Users Online
CommonCrawl, Bing

Members: 0
Guests: 5
Stats
Files
Topics
Posts
Members
Newest Member
477
3,706
19,240
608
LAntorcha
Today's Birthdays
There are no member birthdays today.
Related Links
» SmaugMuds.org » General » General Discussions » Direction
Forum Rules | Mark all | Recent Posts

Direction
< Newer Topic :: Older Topic >

Pages:<< prev 1, 2, 3 next >>
Post is unread #41 Jan 28, 2010, 11:46 am
Go to the top of the page
Go to the bottom of the page

Keirath
Magician
GroupMembers
Posts144
JoinedJan 24, 2008

Is std::bitset something a C++ nub like me could figure out pretty easily?
       
Post is unread #42 Jan 28, 2010, 12:33 pm
Go to the top of the page
Go to the bottom of the page

David Haley
Sorcerer
GroupMembers
Posts903
JoinedJan 29, 2007

I would think so, yes. It's an encapsulation of a bit vector that is created with arbitrary size.

If you want a topical example of writing "OOP" in C, by the way, I uploaded a C implementation of arbitrary sized bitvectors to MudBytes a while ago.

I'll mention again that I really don't think that std::bitset on its own is an appropriate solution; it's missing a few awfully nice features like automatic string conversion. (The code I refer to above doesn't have that feature, either. It's meant to demonstrate simple code that does something straightforward but in a (hopefully) pretty nice way, using OOP-like techniques in C.)
       
Post is unread #43 Jan 28, 2010, 1:36 pm
Go to the top of the page
Go to the bottom of the page

Kayle
Off the Edge of the Map
GroupAdministrators
Posts1,195
JoinedMar 21, 2006

After working in depth with std::bitset. It won't be used in these bases without a serious examination as to whether it's pros outweigh it's cons. It definitely leaves a little to be desired, as David Said, automatic string conversion would be nice. But it also appears to use more memory then an extended bitvector.

Might talk more later, defending human colonies in Mass Effect 2 right now... Oh, and drooling. Lots of drooling.
       
Post is unread #44 Jan 28, 2010, 2:17 pm
Go to the top of the page
Go to the bottom of the page

Samson
Black Hand
GroupAdministrators
Posts3,639
JoinedJan 1, 2002

How exactly is "automatic string conversion" being defined? A template that does what flag_string does? If so, the one in AFKMud would suit this just fine.

I can't see memory usage being a deciding factor. Especially since I've not seen any indication in my own experience that std::bitset is any more or less of a memory hog than anything else. I think you're going to find that just including the STL in general is what's doing most of the memory hogging. You'll get that with std::string or std::vector just as quickly.
       
Post is unread #45 Jan 28, 2010, 2:26 pm
Go to the top of the page
Go to the bottom of the page

David Haley
Sorcerer
GroupMembers
Posts903
JoinedJan 29, 2007

I haven't looked at the one in AFKMud, but I was thinking something along the lines of being able to set flags on the bitvector by name or by number. It would also make stringification easier, by returning a vector of strings that are set that the caller can then join as appropriate (using commas, spaces, whatever). The general idea is to encode the size and the associated strings with the template. A nice consequence of this is that bitvectors of the same size but different flag names become type-incompatible, so you cannot assign, e.g., mob flags to room flags even if they happen to be of the same size.
       
Post is unread #46 Jan 28, 2010, 11:57 pm
Go to the top of the page
Go to the bottom of the page

kiasyn
Magician
GroupMembers
Posts121
JoinedJun 30, 2006

link should be working now
       
Post is unread #47 Jan 29, 2010, 9:48 pm
Go to the top of the page
Go to the bottom of the page

Samson
Black Hand
GroupAdministrators
Posts3,639
JoinedJan 1, 2002

David Haley said:

I haven't looked at the one in AFKMud


I'm talking about this template:
template < size_t N > char *bitset_string( bitset < N > bits, const char *flagarray[] )
{
   static char buf[MSL];
   size_t x;

   buf[0] = '\0';
   for( x = 0; x < bits.size(  ); ++x )
   {
      if( bits.test( x ) )
      {
         mudstrlcat( buf, flagarray[x], MSL );
         // don't catenate a blank if the last char is blank  --Gorog 
         if( buf[0] != '\0' && ' ' != buf[strlen( buf ) - 1] )
            mudstrlcat( buf, " ", MSL );
      }
   }

   if( ( x = strlen( buf ) ) > 0 )
      buf[--x] = '\0';

   return buf;
}


I'm not sure exactly what you were proposing with setting flags on the bitvector. Do you mean extending the bitset class with additional member functions?
       
Post is unread #48 Jan 30, 2010, 12:29 am
Go to the top of the page
Go to the bottom of the page

David Haley
Sorcerer
GroupMembers
Posts903
JoinedJan 29, 2007

Yes, I'm referring to more methods on the bitvector class, and indeed even encoding the flagarray as one of the template parameters to the bitvector type.

So it would be something like:
// declare the type
typedef bitset<123, mobflag_names> mob_flag_set;

// create an object of this type
mob_flag_set myMobFlags;

// set a flag by name
myMobFlags.set("guardian";);
       
Pages:<< prev 1, 2, 3 next >>