bitset question

Started by
8 comments, last by original vesoljc 20 years, 8 months ago
let say: bitset<256> Status; how should be the flags defined in order to still use bitwise operators? like this? #define FLAG1 0x0000 #define FLAG2 0x0001 now, when i want to pass a combo of flags to the Status, i say: SetStatus(const UInt64& lNewStatus); SetStatus(FLAG1 | FLAG2); but this still keeps me under 64 bit limit (because of the 64bit int). how should i pass flags?
Abnormal behavior of abnormal brain makes me normal...
Advertisement
Flags should be other bitsets.

How appropriate. You fight like a cow.
I use them like this. May not be the best way but it works fine.

enum SampleFlags{    SF_DUMMY01 = (1<<1),    SF_DUMMY02 = (1<<2),    SF_DUMMY03 = (1<<3),    SF_DUMMY03 = (1<<4)};//void SomeFunction(int Flags){    if(Flags & SF_DUMMY01)    {         //DoSomething    }}//SomeFunction(SF_DUMMY01 | SF_DUMMY02);//


I don't know if thats a good example, but it should show what I'm talking about...

-UltimaX-

"You wished for a white christmas... Now go shovel your wishes!"

[edited by - UltimaX on July 28, 2003 5:40:18 PM]
@Sneftel

not sure i understand u...
could u give an example?

@UltimaX

void SomeFunction(int Flags)

if int = 32bits, that only gives u 32 flags...
i need more, even more than 64 (uint64)
Abnormal behavior of abnormal brain makes me normal...
std::vector<bool>// compiles down to a bitset class// you can access each element by using the [] operators.//you can use it like this..std::vector<bool> myBitset(n);enum {  FLAG1 = 0,  FLAG2,  ...  FLAGn}if( myBitset[FLAG1] ){  // do whatever}


A GOOD friend will come bail you out of jail...
but, a TRUE friend will be sitting next to you saying, "Damn, we fucked up."
Ingite 3D Game Engine Home -- Just click it


[edited by - silvermace on July 28, 2003 5:50:22 PM]
"I am a donut! Ask not how many tris/batch, but rather how many batches/frame!" -- Matthias Wloka & Richard Huddy, (GDC, DirectX 9 Performance)

http://www.silvermace.com/ -- My personal website
@silvermace

access is not the issue here...

what i''m trying to do:
class CStatus{//con,desprivate:std::bitset<256>   mStatus;};


before, i had this:
UInt64 mStatus;
and could do this:
SetStatus(UInt64 flags)
{
mStatus = flags;
}

AddStatus(UInt64 flags)
{
mStatus = mStatus | flags;
}


the question is, how do i do this with bitset (and ability to go over 64 bits)???
Abnormal behavior of abnormal brain makes me normal...
quote:
AddStatus(UInt64 flags)
{
mStatus = mStatus | flags;
}


void AddStatus(const std::bitset<256> &flags){    mStatus = mStatus | flags;}
I gotta ask: under what circumstances do you have 256 separate flags, which don't take to being referenced by number rather than by name?
How appropriate. You fight like a cow.

[edited by - sneftel on July 28, 2003 6:20:21 PM]
quote:
I gotta ask: under what circumstances do you have 256 separate flags, which don''t take to being referenced by number rather than by name?


my knowledge of english isn''t perfect.
so, i dont understand the second part of the question
"which dont take to being" ???
256 was an example, i found out that 64 wouldn''t be enough...
that''s why i''m switching to bitset

Abnormal behavior of abnormal brain makes me normal...
Well, here''s the thing. If you''re using named flags, then obviously each of those flags has a separate meaning: You''ll have, say, one flag named FLAG_DEAD, one named FLAG_RED_HAIRED, one named FLAG_HUNGRY, etc. Do you actually have 256 of them? or are they really more like FLAG_HAS_KEY_0, FLAG_HAS_KEY_1, FLAG_HAS_KEY_2, etc?

How appropriate. You fight like a cow.
well, they all have names/diffrent meanings. i don't have YET 256 flags, but like i said, after a quick calculation, i found out that 64 just wont cut it. so, how they say it? better safe then sorry???

btw: ur solution works perfectly, tnx

one more btw:
is there a faster/better solution?
INLINE axpConcreteStatus& axpConcreteStatus::operator -=								(const std::bitset<axpStatusSize>& lStatus){	std::bitset<axpStatusSize> lRightInvert;	std::bitset<axpStatusSize> lAllSet;	lAllSet.set();	lRightInvert	= lStatus ^ lAllSet;	mStatus			&= lRightInvert;	return(*this);}


[edited by - original vesoljc on July 28, 2003 7:31:20 PM]
Abnormal behavior of abnormal brain makes me normal...

This topic is closed to new replies.

Advertisement