BitArray request

don’t know if i’m blind or what, but it seems that i miss a function like testBit:

[code]BitArray channels;

// set channels whatever

if (channels.testBit (10) == true)
// …

or i just need to sleep a little more ?

bool BitArray::operator[] ( const int bit ) const throw ()

Returns the value of a specified bit in the array

Edit: Get a cup of coffee :slight_smile:

ouch o_O

today is a really strange day… and i browsed the doxygen page 1000 times !!!

I am confused, again.
How to assign a BitArray return to my BitArray Variable?

[code]//This works in a strange fashion
BitArray* bitArray;
bitArray = (BitArray*)&device->getActiveOutputChannels();

//results to: bitArray 0x0012f4c4 {values=0x031d2468 numValues=4 highestBit=1 …} juce::BitArray *

[code]//This does not work
BitArray bitArray;
bitArray = device->getActiveOutputChannels();

//no result, compiler error[/code]

Thank you!

Your “working” code takes a pointer to a temporary variable and uses it. That’s a classic example of how to cock-up pointers in c++ and the compiler should probably have warned you about it.

The code you say doesn’t work will in fact work fine, and BitArrays get copied around like that all the time. Exactly what compiler error are you seeing?

You are totally right. No Compile-errors until here. But the error occours only then, when I try to “cout” the bitArray. I can´t get along with the Syntax of BitArray for

1.) showing all active Channels (I guess by counting all ones together (?) )
2.) showing the value, which bitArray just have in this moment

  1. Yes, just call countNumberOfSetBits
  2. No idea what you’re talking about
  1. Thank you, jules. This what I was searching for. I wonder, why I didn´t find it myself :oops:

2)[quote=“jules”]2) No idea what you’re talking about[/quote]Want to show active/inactive Channels (printf the bitArray) , e.g. [1,0,1,0,0] for a active Channel 1 and 3. Inactive Channel 2,4,5.

BitArray::toString (2)

Yes! Again:[quote=“pooz”]Thank you, jules. This what I was searching for. I wonder, why I didn´t find it myself :oops: [/quote]
I mistakenly thought, I can handle a BitArray like a normal array.

A little BitArray request: Let all add/set/clear functions return BitArray& so I can do constructs such as:

functionTakingBitArray( BitArray().setBit(2).setBit(34).setBit(45) );


That’s quite neat!

…but thinking about it, I don’t really like the idea of a non-const method that returns the object itself… If it was a “withSetBit() const” method that returns a new array, that’d feel ok…

You mean like the = operator ? :wink: Since I already “have” the object and can do:
BitArray ba;

what’s the difference (beside it being a bit verbose)? And a lot of classes (boost f.i. and the std lib) have this pattern…

True, the = operator does use that pattern, but it just feels wrong somehow. I can’t actually think of a good case against it though!