Direction
< Newer Topic
:: Older Topic >
#41 Jan 28, 2010 1:46 pm
Magician
GroupMembers
Posts148
JoinedJan 24, 2008
Is std::bitset something a C++ nub like me could figure out pretty easily?
#42 Jan 28, 2010 2:33 pm
Sorcerer
GroupMembers
Posts902
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.)
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.)
#43 Jan 28, 2010 3:36 pm
Off the Edge of the Map
GroupAdministrators
Posts1,200
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.
Might talk more later, defending human colonies in Mass Effect 2 right now... Oh, and drooling. Lots of drooling.
#44 Jan 28, 2010 4:17 pm
Black Hand
GroupAdministrators
Posts3,698
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.
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.
#45 Jan 28, 2010 4:26 pm
Sorcerer
GroupMembers
Posts902
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.
#46 Jan 29, 2010 1:57 am
Magician
GroupMembers
Posts121
JoinedJun 30, 2006
link should be working now
#47 Jan 29, 2010 11:48 pm
Black Hand
GroupAdministrators
Posts3,698
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?
#48 Jan 30, 2010 2:29 am
Sorcerer
GroupMembers
Posts902
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:
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");
#49 Jul 30, 2023 9:10 pm
Conjurer
GroupMembers
Posts424
JoinedMar 7, 2005
Good to see that link spammers are still at it. Am I missing something or is there literally no way to report spammers on this forum now?
#50 Aug 3, 2023 11:08 pm
Black Hand
GroupAdministrators
Posts3,698
JoinedJan 1, 2002
There's no report button? Come to think of it I honestly can't say whether there ever was one or not, but I don't see one myself. I'm the admin though so it makes little sense for me to have one
In any case the spam post has been dealt with, including sending it to Akismet for processing.
In any case the spam post has been dealt with, including sending it to Akismet for processing.