You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ta...@apache.org on 2012/07/12 21:59:02 UTC

svn commit: r1360895 [1/2] - in /activemq/activemq-cpp/trunk/activemq-cpp/src: main/ main/decaf/lang/exceptions/ main/decaf/util/ test/ test/decaf/util/

Author: tabish
Date: Thu Jul 12 19:59:01 2012
New Revision: 1360895

URL: http://svn.apache.org/viewvc?rev=1360895&view=rev
Log:
Add class BitSet to be used in message audit functionality. 

Added:
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/exceptions/NegativeArraySizeException.h   (with props)
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/exceptions/OutOfMemoryError.h   (with props)
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/BitSet.cpp   (with props)
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/BitSet.h   (with props)
    activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/BitSetTest.cpp   (with props)
    activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/BitSetTest.h   (with props)
Modified:
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/Makefile.am
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/Config.h
    activemq/activemq-cpp/trunk/activemq-cpp/src/test/Makefile.am
    activemq/activemq-cpp/trunk/activemq-cpp/src/test/testRegistry.cpp

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/Makefile.am
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/Makefile.am?rev=1360895&r1=1360894&r2=1360895&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/Makefile.am (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/Makefile.am Thu Jul 12 19:59:01 2012
@@ -421,6 +421,7 @@ cc_sources = \
     decaf/util/AbstractSet.cpp \
     decaf/util/ArrayList.cpp \
     decaf/util/Arrays.cpp \
+    decaf/util/BitSet.cpp \
     decaf/util/Collection.cpp \
     decaf/util/Comparator.cpp \
     decaf/util/ConcurrentModificationException.cpp \
@@ -945,8 +946,10 @@ h_sources = \
     decaf/lang/exceptions/IndexOutOfBoundsException.h \
     decaf/lang/exceptions/InterruptedException.h \
     decaf/lang/exceptions/InvalidStateException.h \
+    decaf/lang/exceptions/NegativeArraySizeException.h \
     decaf/lang/exceptions/NullPointerException.h \
     decaf/lang/exceptions/NumberFormatException.h \
+    decaf/lang/exceptions/OutOfMemoryError.h \
     decaf/lang/exceptions/RuntimeException.h \
     decaf/lang/exceptions/UnsupportedOperationException.h \
     decaf/net/BindException.h \
@@ -1026,6 +1029,7 @@ h_sources = \
     decaf/util/AbstractSet.h \
     decaf/util/ArrayList.h \
     decaf/util/Arrays.h \
+    decaf/util/BitSet.h \
     decaf/util/Collection.h \
     decaf/util/Comparator.h \
     decaf/util/ConcurrentModificationException.h \

Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/exceptions/NegativeArraySizeException.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/exceptions/NegativeArraySizeException.h?rev=1360895&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/exceptions/NegativeArraySizeException.h (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/exceptions/NegativeArraySizeException.h Thu Jul 12 19:59:01 2012
@@ -0,0 +1,125 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef _DECAF_LANG_EXCEPTIONS_NEGATIVEARRAYSIZEEXCEPTION_H_
+#define _DECAF_LANG_EXCEPTIONS_NEGATIVEARRAYSIZEEXCEPTION_H_
+
+#include <decaf/lang/exceptions/RuntimeException.h>
+
+namespace decaf{
+namespace lang{
+namespace exceptions{
+
+    /*
+     * Thrown if an application tries to create an array with negative size.
+     *
+     * @since 1.0
+     */
+    class DECAF_API NegativeArraySizeException : public RuntimeException {
+    public:
+
+        /**
+         * Default Constructor
+         */
+        NegativeArraySizeException() : RuntimeException() {
+        }
+
+        /**
+         * Conversion Constructor from some other Decaf Exception
+         *
+         * @param ex
+         *      The Exception whose data is to be copied into this one.
+         */
+        NegativeArraySizeException(const Exception& ex) : RuntimeException() {
+            *(Exception*) this = ex;
+        }
+
+        /**
+         * Copy Constructor
+         *
+         * @param ex
+         *      The Exception whose data is to be copied into this one.
+         */
+        NegativeArraySizeException(const NegativeArraySizeException& ex) : RuntimeException() {
+            *(Exception*) this = ex;
+        }
+
+        /**
+         * Constructor - Initializes the file name and line number where
+         * this message occurred.  Sets the message to report, using an
+         * optional list of arguments to parse into the message
+         * @param file The file name where exception occurs
+         * @param lineNumber The line number where the exception occurred.
+         * @param cause The exception that was the cause for this one to be thrown.
+         * @param msg The message to report
+         * @param ... list of primitives that are formatted into the message
+         */
+        NegativeArraySizeException(const char* file, const int lineNumber, const std::exception* cause, const char* msg, ...) : RuntimeException(cause) {
+
+            va_list vargs;
+            va_start(vargs, msg);
+            buildMessage(msg, vargs);
+
+            // Set the first mark for this exception.
+            setMark(file, lineNumber);
+        }
+
+        /**
+         * Constructor
+         * @param cause Pointer to the exception that caused this one to
+         * be thrown, the object is cloned caller retains ownership.
+         */
+        NegativeArraySizeException(const std::exception* cause) : RuntimeException(cause) {
+        }
+
+        /**
+         * Constructor - Initializes the file name and line number where
+         * this message occurred.  Sets the message to report, using an
+         * optional list of arguments to parse into the message
+         * @param file The file name where exception occurs
+         * @param lineNumber The line number where the exception occurred.
+         * @param msg The message to report
+         * @param ... list of primitives that are formatted into the message
+         */
+        NegativeArraySizeException(const char* file, const int lineNumber, const char* msg, ...) : RuntimeException() {
+
+            va_list vargs;
+            va_start(vargs, msg);
+            buildMessage(msg, vargs);
+
+            // Set the first mark for this exception.
+            setMark(file, lineNumber);
+        }
+
+        /**
+         * Clones this exception.  This is useful for cases where you need
+         * to preserve the type of the original exception as well as the message.
+         * All subclasses should override.
+         *
+         * @return an new Exception that is a copy of this one.
+         */
+        virtual NegativeArraySizeException* clone() const {
+            return new NegativeArraySizeException(*this);
+        }
+
+        virtual ~NegativeArraySizeException() throw () {
+        }
+
+    };
+
+}}}
+
+#endif /*_DECAF_LANG_EXCEPTIONS_NEGATIVEARRAYSIZEEXCEPTION_H_*/

Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/exceptions/NegativeArraySizeException.h
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/exceptions/OutOfMemoryError.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/exceptions/OutOfMemoryError.h?rev=1360895&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/exceptions/OutOfMemoryError.h (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/exceptions/OutOfMemoryError.h Thu Jul 12 19:59:01 2012
@@ -0,0 +1,125 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef _DECAF_LANG_EXCEPTIONS_OUTOFMEMORYERROR_H_
+#define _DECAF_LANG_EXCEPTIONS_OUTOFMEMORYERROR_H_
+
+#include <decaf/lang/Exception.h>
+
+namespace decaf{
+namespace lang{
+namespace exceptions{
+
+    /*
+     * Thrown when an allocation operation fails indicating not enough memory.
+     *
+     * @since 1.0
+     */
+    class DECAF_API OutOfMemoryError : public Exception {
+    public:
+
+        /**
+         * Default Constructor
+         */
+        OutOfMemoryError() : Exception() {}
+
+        /**
+         * Conversion Constructor from some other Exception
+         *
+         * @param ex
+         *      The Exception whose data is to be copied into this one.
+         */
+        OutOfMemoryError(const Exception& ex) : Exception() {
+            *(Exception*)this = ex;
+        }
+
+        /**
+         * Copy Constructor
+         *
+         * @param ex
+         *      The Exception whose data is to be copied into this one.
+         */
+        OutOfMemoryError(const OutOfMemoryError& ex) : Exception() {
+            *(Exception*) this = ex;
+        }
+
+        /**
+         * Constructor
+         * @param cause Pointer to the exception that caused this one to
+         * be thrown, the object is cloned caller retains ownership.
+         */
+        OutOfMemoryError(const std::exception* cause) : Exception( cause ) {}
+
+        /**
+         * Constructor - Initializes the file name and line number where
+         * this message occurred.  Sets the message to report, using an
+         * optional list of arguments to parse into the message
+         * @param file The file name where exception occurs
+         * @param lineNumber The line number where the exception occurred.
+         * @param msg The message to report
+         * @param ... list of primitives that are formatted into the message
+         */
+        OutOfMemoryError(const char* file, const int lineNumber,
+                           const char* msg, ...) : Exception()
+        {
+            va_list vargs;
+            va_start(vargs, msg);
+            buildMessage(msg, vargs);
+
+            // Set the first mark for this exception.
+            setMark(file, lineNumber);
+        }
+
+        /**
+         * Constructor - Initializes the file name and line number where
+         * this message occurred.  Sets the message to report, using an
+         * optional list of arguments to parse into the message
+         * @param file The file name where exception occurs
+         * @param lineNumber The line number where the exception occurred.
+         * @param cause The exception that was the cause for this one to be thrown.
+         * @param msg The message to report
+         * @param ... list of primitives that are formatted into the message
+         */
+        OutOfMemoryError(const char* file, const int lineNumber,
+                           const std::exception* cause,
+                           const char* msg, ...) : Exception( cause )
+        {
+            va_list vargs ;
+            va_start(vargs, msg);
+            buildMessage(msg, vargs);
+
+            // Set the first mark for this exception.
+            setMark(file, lineNumber);
+        }
+
+        /**
+         * Clones this exception.  This is useful for cases where you need
+         * to preserve the type of the original exception as well as the message.
+         * All subclasses should override.
+         *
+         * @return an new Exception instance that is a copy of this one.
+         */
+        virtual OutOfMemoryError* clone() const{
+            return new OutOfMemoryError( *this );
+        }
+
+        virtual ~OutOfMemoryError() throw() {}
+
+    };
+
+}}}
+
+#endif /*_DECAF_LANG_EXCEPTIONS_OUTOFMEMORYERROR_H_*/

Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/exceptions/OutOfMemoryError.h
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/exceptions/OutOfMemoryError.h
------------------------------------------------------------------------------
    svn:executable = *

Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/BitSet.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/BitSet.cpp?rev=1360895&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/BitSet.cpp (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/BitSet.cpp Thu Jul 12 19:59:01 2012
@@ -0,0 +1,791 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "BitSet.h"
+
+#include <decaf/lang/exceptions/IndexOutOfBoundsException.h>
+#include <decaf/lang/exceptions/NegativeArraySizeException.h>
+#include <decaf/lang/exceptions/OutOfMemoryError.h>
+
+#include <decaf/lang/System.h>
+#include <decaf/lang/Integer.h>
+#include <decaf/lang/Math.h>
+
+using namespace std;
+using namespace decaf;
+using namespace decaf::lang;
+using namespace decaf::lang::exceptions;
+using namespace decaf::util;
+
+////////////////////////////////////////////////////////////////////////////////
+namespace {
+
+    static const int OFFSET = 6;
+    static const int ELM_SIZE = 1 << OFFSET;
+    static const int RIGHT_BITS = ELM_SIZE - 1;
+
+    static long long TWO_N_ARRAY[64] = {
+        0x0000000000000001ULL, 0x0000000000000002ULL, 0x0000000000000004ULL,
+        0x0000000000000008ULL, 0x0000000000000010ULL, 0x0000000000000020ULL,
+        0x0000000000000040ULL, 0x0000000000000080ULL, 0x0000000000000100ULL,
+        0x0000000000000200ULL, 0x0000000000000400ULL, 0x0000000000000800ULL,
+        0x0000000000001000ULL, 0x0000000000002000ULL, 0x0000000000004000ULL,
+        0x0000000000008000ULL, 0x0000000000010000ULL, 0x0000000000020000ULL,
+        0x0000000000040000ULL, 0x0000000000080000ULL, 0x0000000000100000ULL,
+        0x0000000000200000ULL, 0x0000000000400000ULL, 0x0000000000800000ULL,
+        0x0000000001000000ULL, 0x0000000002000000ULL, 0x0000000004000000ULL,
+        0x0000000008000000ULL, 0x0000000010000000ULL, 0x0000000020000000ULL,
+        0x0000000040000000ULL, 0x0000000080000000ULL, 0x0000000100000000ULL,
+        0x0000000200000000ULL, 0x0000000400000000ULL, 0x0000000800000000ULL,
+        0x0000001000000000ULL, 0x0000002000000000ULL, 0x0000004000000000ULL,
+        0x0000008000000000ULL, 0x0000010000000000ULL, 0x0000020000000000ULL,
+        0x0000040000000000ULL, 0x0000080000000000ULL, 0x0000100000000000ULL,
+        0x0000200000000000ULL, 0x0000400000000000ULL, 0x0000800000000000ULL,
+        0x0001000000000000ULL, 0x0002000000000000ULL, 0x0004000000000000ULL,
+        0x0008000000000000ULL, 0x0010000000000000ULL, 0x0020000000000000ULL,
+        0x0040000000000000ULL, 0x0080000000000000ULL, 0x0100000000000000ULL,
+        0x0200000000000000ULL, 0x0400000000000000ULL, 0x0800000000000000ULL,
+        0x1000000000000000ULL, 0x2000000000000000ULL, 0x4000000000000000ULL,
+        0x8000000000000000ULL };
+
+    int pop(unsigned long long x) {
+        x = x - ((x >> 1) & 0x55555555);
+        x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
+        x = (x + (x >> 4)) & 0x0f0f0f0f;
+        x = x + (x >> 8);
+        x = x + (x >> 16);
+        return (int) x & 0x0000003f;
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+BitSet::BitSet() : bits(new unsigned long long[1]), bitsSize(1), needClear(false), actualArrayLength(0), isLengthActual(true) {
+    bits[0] = 0ULL;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+BitSet::BitSet(int bitCount) : bits(0), bitsSize(0), needClear(false), actualArrayLength(0), isLengthActual(true) {
+
+    if (bitCount < 0) {
+        throw NegativeArraySizeException(__FILE__, __LINE__, "");
+    }
+
+    bitsSize = (bitCount >> OFFSET) + ((bitCount & RIGHT_BITS) > 0 ? 1 : 0);
+    try {
+        bits = new unsigned long long[bitsSize];
+
+        if (bits == NULL) {
+            throw OutOfMemoryError(__FILE__, __LINE__, "Failed to allocate bit array.");
+        }
+
+        for (int i = 0; i < bitsSize; ++i) {
+            bits[i] = 0ULL;
+        }
+    } catch (std::bad_alloc& e) {
+        throw OutOfMemoryError(__FILE__, __LINE__, "Failed to allocate bit array.");
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+BitSet::BitSet(unsigned long long* bits, int bitsSize, bool needClear, int actualArrayLength, bool isLengthActual) :
+    bits(bits), bitsSize(bitsSize), needClear(needClear), actualArrayLength(actualArrayLength), isLengthActual(isLengthActual) {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+BitSet::~BitSet() {
+    try {
+        delete [] bits;
+    }
+    DECAF_CATCHALL_NOTHROW()
+}
+
+////////////////////////////////////////////////////////////////////////////////
+BitSet::BitSet(const BitSet& set) : bits(0), bitsSize(0), needClear(false), actualArrayLength(0), isLengthActual(true) {
+
+    this->actualArrayLength = set.actualArrayLength;
+    this->isLengthActual = set.isLengthActual;
+    this->needClear = set.needClear;
+    this->bitsSize = set.bitsSize;
+
+    try {
+        bits = new unsigned long long[bitsSize];
+
+        if (bits == NULL) {
+            throw OutOfMemoryError(__FILE__, __LINE__, "Failed to allocate bit array.");
+        }
+
+        System::arraycopy(set.bits, 0, bits, 0, set.bitsSize);
+
+    } catch (std::bad_alloc& e) {
+        throw OutOfMemoryError(__FILE__, __LINE__, "Failed to allocate bit array.");
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+BitSet& BitSet::operator= (const BitSet& set) {
+
+    delete [] this->bits;
+
+    this->actualArrayLength = set.actualArrayLength;
+    this->isLengthActual = set.isLengthActual;
+    this->needClear = set.needClear;
+    this->bitsSize = set.bitsSize;
+
+    try {
+        bits = new unsigned long long[bitsSize];
+
+        if (bits == NULL) {
+            throw OutOfMemoryError(__FILE__, __LINE__, "Failed to allocate bit array.");
+        }
+
+        System::arraycopy(set.bits, 0, bits, 0, set.bitsSize);
+
+    } catch (std::bad_alloc& e) {
+        throw OutOfMemoryError(__FILE__, __LINE__, "Failed to allocate bit array.");
+    }
+
+    return *this;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void BitSet::AND(const BitSet& set) {
+
+    unsigned long long* bsBits = set.bits;
+
+    if (!needClear) {
+        return;
+    }
+
+    int length1 = actualArrayLength, length2 = set.actualArrayLength;
+    if (length1 <= length2) {
+        for (int i = 0; i < length1; i++) {
+            bits[i] &= bsBits[i];
+        }
+    } else {
+        for (int i = 0; i < length2; i++) {
+            bits[i] &= bsBits[i];
+        }
+        for (int i = length2; i < length1; i++) {
+            bits[i] = 0;
+        }
+        actualArrayLength = length2;
+    }
+    isLengthActual = !((actualArrayLength > 0) && (bits[actualArrayLength - 1] == 0));
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void BitSet::andNot(const BitSet& set) {
+	unsigned long long* bsBits = set.bits;
+
+    if (!needClear) {
+        return;
+    }
+
+    int range = actualArrayLength < set.actualArrayLength ? actualArrayLength : set.actualArrayLength;
+    for (int i = 0; i < range; i++) {
+        bits[i] &= ~bsBits[i];
+    }
+
+    if (actualArrayLength < range) {
+        actualArrayLength = range;
+    }
+
+    isLengthActual = !((actualArrayLength > 0) && (bits[actualArrayLength - 1] == 0));
+}
+
+////////////////////////////////////////////////////////////////////////////////
+int BitSet::cardinality() {
+    if (!needClear) {
+        return 0;
+    }
+    int count = 0;
+    int length = bitsSize;
+    // FIXME: need to test performance, if still not satisfied, change it to
+    // 256-bits table based
+    for (int idx = 0; idx < length; idx++) {
+        count += pop(bits[idx] & 0xffffffffL);
+        count += pop((bits[idx] >> 32));
+    }
+    return count;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void BitSet::clear() {
+    if (needClear) {
+        for (int i = 0; i < bitsSize; i++) {
+            bits[i] = 0ULL;
+        }
+        actualArrayLength = 0;
+        isLengthActual = true;
+        needClear = false;
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void BitSet::clear(int index) {
+
+    if (index < 0) {
+        throw IndexOutOfBoundsException(__FILE__, __LINE__, "Index given was negative");
+    }
+
+    if (!needClear) {
+        return;
+    }
+    int arrayPos = index >> OFFSET;
+    if (arrayPos < actualArrayLength) {
+        bits[arrayPos] &= ~(TWO_N_ARRAY[index & RIGHT_BITS]);
+        if (bits[actualArrayLength - 1] == 0) {
+            isLengthActual = false;
+        }
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void BitSet::clear(int fromIndex, int toIndex) {
+    if (fromIndex < 0 || toIndex < 0 || toIndex < fromIndex) {
+        throw IndexOutOfBoundsException(__FILE__, __LINE__, "Invalid from or to index given");
+    }
+
+    if (!needClear) {
+        return;
+    }
+
+    int last = (actualArrayLength << OFFSET);
+    if (fromIndex >= last || fromIndex == toIndex) {
+        return;
+    }
+    if (toIndex > last) {
+        toIndex = last;
+    }
+
+    int idx1 = fromIndex >> OFFSET;
+    int idx2 = (toIndex - 1) >> OFFSET;
+    unsigned long long factor1 = (~0ULL) << (fromIndex & RIGHT_BITS);
+    unsigned long long factor2 = (~0ULL) >> (ELM_SIZE - (toIndex & RIGHT_BITS));
+
+    if (idx1 == idx2) {
+        bits[idx1] &= ~(factor1 & factor2);
+    } else {
+        bits[idx1] &= ~factor1;
+        bits[idx2] &= ~factor2;
+        for (int i = idx1 + 1; i < idx2; i++) {
+            bits[i] = 0ULL;
+        }
+    }
+
+    if ((actualArrayLength > 0) && (bits[actualArrayLength - 1] == 0)) {
+        isLengthActual = false;
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void BitSet::OR(const BitSet& set) {
+    int setActualLen = set.getActualArrayLength();
+
+    if (setActualLen > bitsSize) {
+        unsigned long long* tempBits = new unsigned long long[setActualLen];
+        System::arraycopy(set.bits, 0, tempBits, 0, set.actualArrayLength);
+        for (int i = 0; i < actualArrayLength; i++) {
+            tempBits[i] |= bits[i];
+        }
+        delete [] bits;
+        bits = tempBits;
+        actualArrayLength = setActualLen;
+        isLengthActual = true;
+    } else {
+        unsigned long long* bsBits = set.bits;
+        for (int i = 0; i < setActualLen; i++) {
+            bits[i] |= bsBits[i];
+        }
+        if (setActualLen > actualArrayLength) {
+            actualArrayLength = setActualLen;
+            isLengthActual = true;
+        }
+    }
+    needClear = true;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool BitSet::equals(const BitSet& set) const {
+
+    if (this == &set) {
+        return true;
+    }
+
+    unsigned long long* bsBits = set.bits;
+    int length1 = this->actualArrayLength;
+    int length2 = set.actualArrayLength;
+    if (this->isLengthActual && set.isLengthActual && length1 != length2) {
+        return false;
+    }
+
+    // If one of the BitSets is larger than the other, check to see if
+    // any of its extra bits are set. If so return false.
+    if (length1 <= length2) {
+        for (int i = 0; i < length1; i++) {
+            if (bits[i] != bsBits[i]) {
+                return false;
+            }
+        }
+        for (int i = length1; i < length2; i++) {
+            if (bsBits[i] != 0) {
+                return false;
+            }
+        }
+    } else {
+        for (int i = 0; i < length2; i++) {
+            if (bits[i] != bsBits[i]) {
+                return false;
+            }
+        }
+        for (int i = length2; i < length1; i++) {
+            if (bits[i] != 0) {
+                return false;
+            }
+        }
+    }
+    return true;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void BitSet::flip(int index) {
+    if (index < 0) {
+        throw IndexOutOfBoundsException(__FILE__, __LINE__, "Index given was negative");
+    }
+
+    int len = (index >> OFFSET) + 1;
+    if (len > bitsSize) {
+        ensureCapacity(len);
+    }
+    bits[len - 1] ^= TWO_N_ARRAY[index & RIGHT_BITS];
+    if (len > actualArrayLength) {
+        actualArrayLength = len;
+    }
+    isLengthActual = !((actualArrayLength > 0) && (bits[actualArrayLength - 1] == 0));
+    needClear = true;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void BitSet::flip(int fromIndex, int toIndex) {
+    if (fromIndex < 0 || toIndex < 0 || toIndex < fromIndex) {
+        throw IndexOutOfBoundsException(__FILE__, __LINE__, "Invalid from or to index given");
+    }
+
+    if (fromIndex == toIndex) {
+        return;
+    }
+    int len2 = ((toIndex - 1) >> OFFSET) + 1;
+    if (len2 > bitsSize) {
+        ensureCapacity(len2);
+    }
+
+    int idx1 = fromIndex >> OFFSET;
+    int idx2 = (toIndex - 1) >> OFFSET;
+    unsigned long long factor1 = (~0ULL) << (fromIndex & RIGHT_BITS);
+    unsigned long long factor2 = (~0ULL) >> (ELM_SIZE - (toIndex & RIGHT_BITS));
+
+    if (idx1 == idx2) {
+        bits[idx1] ^= (factor1 & factor2);
+    } else {
+        bits[idx1] ^= factor1;
+        bits[idx2] ^= factor2;
+        for (int i = idx1 + 1; i < idx2; i++) {
+            bits[i] ^= (~0ULL);
+        }
+    }
+    if (len2 > actualArrayLength) {
+        actualArrayLength = len2;
+    }
+    isLengthActual = !((actualArrayLength > 0) && (bits[actualArrayLength - 1] == 0));
+    needClear = true;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool BitSet::get(int index) const {
+
+    if (index < 0) {
+        throw IndexOutOfBoundsException(__FILE__, __LINE__, "Index given was negative");
+    }
+
+    int arrayPos = index >> OFFSET;
+    if (arrayPos < actualArrayLength) {
+        return (bits[arrayPos] & TWO_N_ARRAY[index & RIGHT_BITS]) != 0;
+    }
+    return false;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+BitSet BitSet::get(int fromIndex, int toIndex) const {
+    if (fromIndex < 0 || toIndex < 0 || toIndex < fromIndex) {
+        throw IndexOutOfBoundsException(__FILE__, __LINE__, "Invalid from or to index given");
+    }
+
+    int last = actualArrayLength << OFFSET;
+    if (fromIndex >= last || fromIndex == toIndex) {
+        return BitSet(0);
+    }
+    if (toIndex > last) {
+        toIndex = last;
+    }
+
+    int idx1 = fromIndex >> OFFSET;
+    int idx2 = (toIndex - 1) >> OFFSET;
+    unsigned long long factor1 = (~0ULL) << (fromIndex & RIGHT_BITS);
+    unsigned long long factor2 = (~0ULL) >> (ELM_SIZE - (toIndex & RIGHT_BITS));
+
+    if (idx1 == idx2) {
+        unsigned long long result = (bits[idx1] & (factor1 & factor2)) >> (fromIndex % ELM_SIZE);
+        if (result == 0) {
+            return BitSet(0);
+        }
+
+        unsigned long long* newBits = new unsigned long long[1];
+        newBits[0] = result;
+        return BitSet(newBits, 1, needClear, 1, true);
+    }
+
+    int newBitsSize = idx2 - idx1 + 1;
+    unsigned long long* newbits = new unsigned long long[newBitsSize];
+
+    // first fill in the first and last indexes in the new bitset
+    newbits[0] = bits[idx1] & factor1;
+    newbits[newBitsSize - 1] = bits[idx2] & factor2;
+
+    // fill in the in between elements of the new bitset
+    for (int i = 1; i < idx2 - idx1; i++) {
+        newbits[i] = bits[idx1 + i];
+    }
+
+    // shift all the elements in the new bitset to the right by fromIndex % ELM_SIZE
+    int numBitsToShift = fromIndex & RIGHT_BITS;
+    int actualLen = newBitsSize;
+    if (numBitsToShift != 0) {
+        for (int i = 0; i < newBitsSize; i++) {
+            // shift the current element to the right regardless of sign
+            newbits[i] = newbits[i] >> (numBitsToShift);
+
+            // apply the last x bits of newbits[i+1] to the current element
+            if (i != newBitsSize - 1) {
+                newbits[i] |= newbits[i + 1] << (ELM_SIZE - (numBitsToShift));
+            }
+
+            if (newbits[i] != 0) {
+                actualLen = i + 1;
+            }
+        }
+    }
+
+    return BitSet(newbits, newBitsSize, needClear, actualLen, newbits[actualLen - 1] != 0);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool BitSet::intersects(const BitSet& set) const {
+	unsigned long long* bsBits = set.bits;
+    int length1 = actualArrayLength;
+    int length2 = set.actualArrayLength;
+
+    if (length1 <= length2) {
+        for (int i = 0; i < length1; i++) {
+            if ((bits[i] & bsBits[i]) != 0ULL) {
+                return true;
+            }
+        }
+    } else {
+        for (int i = 0; i < length2; i++) {
+            if ((bits[i] & bsBits[i]) != 0ULL) {
+                return true;
+            }
+        }
+    }
+
+    return false;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool BitSet::isEmpty() const {
+    if (!needClear) {
+        return true;
+    }
+
+    for (int idx = 0; idx < bitsSize; idx++) {
+        if (bits[idx] != 0ULL) {
+            return false;
+        }
+    }
+    return true;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+int BitSet::length() const {
+
+    int idx = actualArrayLength - 1;
+    while (idx >= 0 && bits[idx] == 0) {
+        --idx;
+    }
+    actualArrayLength = idx + 1;
+    if (idx == -1) {
+        return 0;
+    }
+    int i = ELM_SIZE - 1;
+    long val = bits[idx];
+    while ((val & (TWO_N_ARRAY[i])) == 0 && i > 0) {
+        i--;
+    }
+    return (idx << OFFSET) + i + 1;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+int BitSet::nextClearBit(int index) const {
+    if (index < 0) {
+        throw IndexOutOfBoundsException(__FILE__, __LINE__, "Index given was negative");
+    }
+
+    int length = actualArrayLength;
+    int bssize = length << OFFSET;
+    if (index >= bssize) {
+        return index;
+    }
+
+    int idx = index >> OFFSET;
+    // first check in the same bit set element
+    if (bits[idx] != (~0ULL)) {
+        for (int j = index % ELM_SIZE; j < ELM_SIZE; j++) {
+            if (((bits[idx] & (TWO_N_ARRAY[j])) == 0)) {
+                return idx * ELM_SIZE + j;
+            }
+        }
+    }
+    idx++;
+    while (idx < length && bits[idx] == (~0ULL)) {
+        idx++;
+    }
+    if (idx == length) {
+        return bssize;
+    }
+
+    // we know for sure there is a bit set to true in this element
+    // since the bitset value is not 0ULL
+    for (int j = 0; j < ELM_SIZE; j++) {
+        if (((bits[idx] & (TWO_N_ARRAY[j])) == 0)) {
+            return (idx << OFFSET) + j;
+        }
+    }
+
+    return bssize;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+int BitSet::nextSetBit(int index) const {
+    if (index < 0) {
+        throw IndexOutOfBoundsException(__FILE__, __LINE__, "Index given was negative");
+    }
+
+    if (index >= actualArrayLength << OFFSET) {
+        return -1;
+    }
+
+    int idx = index >> OFFSET;
+    // first check in the same bit set element
+    if (bits[idx] != 0ULL) {
+        for (int j = index & RIGHT_BITS; j < ELM_SIZE; j++) {
+            if (((bits[idx] & (TWO_N_ARRAY[j])) != 0)) {
+                return (idx << OFFSET) + j;
+            }
+        }
+    }
+
+    idx++;
+    while (idx < actualArrayLength && bits[idx] == 0ULL) {
+        idx++;
+    }
+    if (idx == actualArrayLength) {
+        return -1;
+    }
+
+    // we know for sure there is a bit set to true in this element
+    // since the bitset value is not 0ULL
+    for (int j = 0; j < ELM_SIZE; j++) {
+        if (((bits[idx] & (TWO_N_ARRAY[j])) != 0)) {
+            return (idx << OFFSET) + j;
+        }
+    }
+
+    return -1;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void BitSet::set(int index) {
+
+    if (index < 0) {
+        throw IndexOutOfBoundsException(__FILE__, __LINE__, "Index given was negative");
+    }
+
+    int len = (index >> OFFSET) + 1;
+    if (len > bitsSize) {
+        ensureCapacity(len);
+    }
+    bits[len - 1] |= TWO_N_ARRAY[index & RIGHT_BITS];
+    if (len > actualArrayLength) {
+        actualArrayLength = len;
+        isLengthActual = true;
+    }
+
+    this->needClear = true;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void BitSet::set(int index, bool value) {
+
+    if (value) {
+        set(index);
+    } else {
+        clear(index);
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void BitSet::set(int fromIndex, int toIndex) {
+
+    if (fromIndex < 0 || toIndex < 0 || toIndex < fromIndex) {
+        throw IndexOutOfBoundsException(__FILE__, __LINE__, "Invalid from or to index given");
+    }
+
+    if (fromIndex == toIndex) {
+        return;
+    }
+    int len2 = ((toIndex - 1) >> OFFSET) + 1;
+    if (len2 > bitsSize) {
+        ensureCapacity(len2);
+    }
+
+    int idx1 = fromIndex >> OFFSET;
+    int idx2 = (toIndex - 1) >> OFFSET;
+    unsigned long long factor1 = (~0ULL) << (fromIndex & RIGHT_BITS);
+    unsigned long long factor2 = (~0ULL) >> (ELM_SIZE - (toIndex & RIGHT_BITS));
+
+    if (idx1 == idx2) {
+        bits[idx1] |= (factor1 & factor2);
+    } else {
+        bits[idx1] |= factor1;
+        bits[idx2] |= factor2;
+        for (int i = idx1 + 1; i < idx2; i++) {
+            bits[i] |= (~0ULL);
+        }
+    }
+    if (idx2 + 1 > actualArrayLength) {
+        actualArrayLength = idx2 + 1;
+        isLengthActual = true;
+    }
+
+    needClear = true;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void BitSet::set(int fromIndex, int toIndex, bool value) {
+
+    if (value) {
+        set(fromIndex, toIndex);
+    } else {
+        clear(fromIndex, toIndex);
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+int BitSet::size() const {
+    return bitsSize << OFFSET;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+std::string BitSet::toString() const {
+    std::string sb;
+    int bitCount = 0;
+
+    sb.append("{");
+    bool comma = false;
+    for (int i = 0; i < bitsSize; i++) {
+        if (bits[i] == 0) {
+            bitCount += ELM_SIZE;
+            continue;
+        }
+        for (int j = 0; j < ELM_SIZE; j++) {
+            if (((bits[i] & (TWO_N_ARRAY[j])) != 0)) {
+                if (comma) {
+                    sb.append(", ");
+                }
+                sb.append(Integer::toString(bitCount));
+                comma = true;
+            }
+            bitCount++;
+        }
+    }
+    sb.append("}");
+    return sb;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void BitSet::XOR(const BitSet& set) {
+    int setActualLength = set.getActualArrayLength();
+    if (setActualLength > bitsSize) {
+    	unsigned long long* tempBits = new unsigned long long[setActualLength];
+        System::arraycopy(set.bits, 0, tempBits, 0, set.actualArrayLength);
+        for (int i = 0; i < actualArrayLength; i++) {
+            tempBits[i] ^= bits[i];
+        }
+        delete [] bits;
+        bits = tempBits;
+        actualArrayLength = setActualLength;
+        isLengthActual = !((actualArrayLength > 0) && (bits[actualArrayLength - 1] == 0));
+    } else {
+    	unsigned long long* bsBits = set.bits;
+        for (int i = 0; i < setActualLength; i++) {
+            bits[i] ^= bsBits[i];
+        }
+        if (setActualLength > actualArrayLength) {
+            actualArrayLength = setActualLength;
+            isLengthActual = true;
+        }
+    }
+
+    this->needClear = true;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void BitSet::ensureCapacity(int length) {
+    int newSize = Math::max(length, bitsSize * 2);
+    unsigned long long* tempBits = new unsigned long long[newSize];
+    System::arraycopy(bits, 0, tempBits, 0, this->actualArrayLength);
+    for (int i = this->actualArrayLength; i < newSize; ++i) {
+        tempBits[i] = 0ULL;
+    }
+    delete [] bits;
+    bits = tempBits;
+    bitsSize = newSize;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+int BitSet::getActualArrayLength() const {
+    if (isLengthActual) {
+        return actualArrayLength;
+    }
+    int idx = actualArrayLength - 1;
+    while (idx >= 0 && bits[idx] == 0) {
+        --idx;
+    }
+    actualArrayLength = idx + 1;
+    isLengthActual = true;
+    return actualArrayLength;
+}

Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/BitSet.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/BitSet.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/BitSet.h?rev=1360895&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/BitSet.h (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/BitSet.h Thu Jul 12 19:59:01 2012
@@ -0,0 +1,394 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _DECAF_UTIL_BITSET_H_
+#define _DECAF_UTIL_BITSET_H_
+
+#include <decaf/util/Config.h>
+
+#include <string>
+
+namespace decaf {
+namespace util {
+
+    /**
+     * This class implements a vector of bits that grows as needed. Each component of
+     * the bit set has a boolean value. The bits of a BitSet are indexed by nonnegative
+     * integers. Individual indexed bits can be examined, set, or cleared. One BitSet
+     * may be used to modify the contents of another BitSet through logical AND, logical
+     * inclusive OR, and logical exclusive OR operations.
+     *
+     * By default, all bits in the set initially have the value false.
+     *
+     * Every bit set has a current size, which is the number of bits of space currently
+     * in use by the bit set. Note that the size is related to the implementation of a
+     * bit set, so it may change with implementation. The length of a bit set relates to
+     * logical length of a bit set and is defined independently of implementation.
+     *
+     * Unless otherwise noted, passing a null parameter to any of the methods in a
+     * BitSet will result in a NullPointerException.
+     *
+     * A BitSet is not safe for multi-threaded use without external synchronization.
+     *
+     * @since 1.0
+     */
+    class DECAF_API BitSet {
+    private:
+
+        // The actual array of 64 bit bits elements
+        unsigned long long* bits;
+        int bitsSize;
+
+        // Optimization, when the array is all zero there's no need to traverse
+        bool needClear;
+
+        // Lazily maintained actual array length and state.
+        mutable int actualArrayLength;
+        mutable bool isLengthActual;
+
+    private:
+
+        BitSet(unsigned long long* bits, int bitsSize, bool needClear, int actualArrayLength, bool isLengthActual);
+
+    public:
+
+        /**
+         * Creates a new BitSet whose bits are all false.
+         */
+        BitSet();
+
+        /**
+         * Creates a bit set whose initial size is large enough to explicitly represent bits
+         * with indices in the range 0 through bitCount-1. All bits are initially false.  If the
+         * bitCount is not a multiple of 64 then the count is rounded to the next closest
+         * multiple of 64.
+         *
+         * @param bitCount
+         *      The number of bits this BitSet should hold.
+         *
+         * @throws NegativeArraySizeException if bitCount is negative.
+         */
+        BitSet(int bitCount);
+
+        /**
+         * Copy Constructor
+         */
+        BitSet(const BitSet& set);
+
+        /**
+         * Assignment
+         */
+        BitSet& operator= (const BitSet& set);
+
+        virtual ~BitSet();
+
+    public:
+
+        /**
+         * Performs a logical AND of this target bit set with the argument bit set. This bit
+         * set is modified so that each bit in it has the value true if and only if it both
+         * initially had the value true and the corresponding bit in the bit set argument
+         * also had the value true.
+         *
+         * @param set
+         *      The BitSet to perform this action against.
+         */
+        void AND(const BitSet& set);
+
+        /**
+         * Performs a logical OR of this bit set with the bit set argument. This bit set is
+         * modified so that a bit in it has the value true if and only if it either already had
+         * the value true or the corresponding bit in the bit set argument has the value true.
+         *
+         * @param set
+         *      The BitSet to perform this action against.
+         */
+        void OR(const BitSet& set);
+
+        /**
+         * Clears all of the bits in this BitSet whose corresponding bit is set in the specified BitSet.
+         *
+         * @param set
+         *      The BitSet to perform this action against.
+         */
+        void andNot(const BitSet& set);
+
+        /**
+         * Returns the number of bits set to true in this BitSet.
+         *
+         * @returns the number of bits set to true in this BitSet.
+         */
+        int cardinality();
+
+        /**
+         * Sets all of the bits in this BitSet to false.
+         */
+        void clear();
+
+        /**
+         * Sets the bit specified by the index to false.
+         *
+         * @param index
+         *      The index of the bit whose value is to be set to false
+         *
+         * @throws IndexOutOfBoundsException if the index value is negative.
+         */
+        void clear(int index);
+
+        /**
+         * Sets the bits from the specified fromIndex (inclusive) to the specified toIndex
+         * (exclusive) to false.
+         *
+         * @param fromIndex
+         *      The index (inclusive) to start setting bits to false.
+         * @param toIndex
+         *      The index (exclusive) to stop setting bits to false.
+         *
+         * @throws IndexOutOfBoundsException if fromIndex is negative, or toIndex is negative, or
+         *                                   fromIndex is larger than toIndex.
+         */
+        void clear(int fromIndex, int toIndex);
+
+        /**
+         * Compares this object against the specified object. The result is true if and only if
+         * is a Bitset object that has exactly the same set of bits set to true as this bit set.
+         * That is, for every nonnegative int index k,
+         *
+         *   set.get(k) == this->get(k)
+         *
+         * must be true. The current sizes of the two bit sets are not compared.
+         *
+         * @returns true if the sets are the same, false otherwise.
+         */
+        bool equals(const BitSet& set) const;
+
+        /**
+         * Sets the bit at the specified index to the complement of its current value.
+         *
+         * @param index
+         *      The index of the bit whose value is to be set to its compliment.
+         *
+         * @throws IndexOutOfBoundsException if the index value is negative.
+         */
+        void flip(int index);
+
+        /**
+         * Sets each bit from the specified fromIndex (inclusive) to the specified toIndex
+         * (exclusive) to the complement of its current value.
+         *
+         * @param fromIndex
+         *      The index (inclusive) to start setting bits to its compliment.
+         * @param toIndex
+         *      The index (exclusive) to stop setting bits to its compliment.
+         *
+         * @throws IndexOutOfBoundsException if fromIndex is negative, or toIndex is negative, or
+         *                                   fromIndex is larger than toIndex.
+         */
+        void flip(int fromIndex, int toIndex);
+
+        /**
+         * Returns the value of the bit with the specified index. The value is true if the bit
+         * with the given index is currently set in this BitSet; otherwise, the result is false.
+         *
+         * @param index
+         *      The index of the bit in question.
+         *
+         * @returns the value of the bit with the specified index.
+         *
+         * @throws IndexOutOfBoundsException if the index value is negative.
+         */
+        bool get(int index) const;
+
+        /**
+         * Returns a new BitSet composed of bits from this BitSet from fromIndex (inclusive) to
+         * toIndex (exclusive).
+         *
+         * @param fromIndex
+         *      The index (inclusive) to start at.
+         * @param toIndex
+         *      The index (exclusive) to stop at.
+         *
+         * @returns a new BitSet containing the specified values.
+         *
+         * @throws IndexOutOfBoundsException if fromIndex is negative, or toIndex is negative, or
+         *                                   fromIndex is larger than toIndex.
+         */
+        BitSet get(int fromIndex, int toIndex) const;
+
+        /**
+         * Returns true if the specified BitSet has any bits set to true that are also set to
+         * true in this BitSet.
+         *
+         * @param set
+         *      BitSet to intersect with.
+         *
+         * @returns boolean indicating whether this BitSet intersects the specified BitSet.
+         */
+        bool intersects(const BitSet& set) const;
+
+        /**
+         * Returns true if this BitSet contains no bits that are set to true.
+         *
+         * @returns true if the set is empty, false otherwise.
+         */
+        bool isEmpty() const;
+
+        /**
+         * Returns the "logical size" of this BitSet: the index of the highest set bit in the
+         * BitSet plus one. Returns zero if the BitSet contains no set bits.
+         *
+         * @returns the logical size of the BitSet.
+         */
+        int length() const;
+
+        /**
+         * Returns the index of the first bit that is set to false that occurs on or after the
+         * specified starting index.
+         *
+         * @param index
+         *      The index to start the search from (inclusive).
+         *
+         * @returns the index of the next clear bit.
+         *
+         * @throws IndexOutOfBoundsException if the index value is negative.
+         */
+        int nextClearBit(int index) const;
+
+        /**
+         * Returns the index of the first bit that is set to true that occurs on or after the
+         * specified starting index.
+         *
+         * @param index
+         *      The index to start the search from (inclusive).
+         *
+         * @returns the index of the next set bit.
+         *
+         * @throws IndexOutOfBoundsException if the index value is negative.
+         */
+        int nextSetBit(int index) const;
+
+        /**
+         * Sets the bit at the specified index to true.
+         *
+         * @param index
+         *      The index to set to true.
+         *
+         * @throws IndexOutOfBoundsException if the index value is negative.
+         */
+        void set(int index);
+
+        /**
+         * Sets the bit at the specified index to the specified value.
+         *
+         * @param index
+         *      The index to set.
+         * @param value
+         *      The value to assign to the given bit.
+         *
+         * @throws IndexOutOfBoundsException if the index value is negative.
+         */
+        void set(int index, bool value);
+
+        /**
+         * Sets the bits from the specified fromIndex (inclusive) to the specified toIndex
+         * (exclusive) to true.
+         *
+         * @param fromIndex
+         *      The index (inclusive) to start at.
+         * @param toIndex
+         *      The index (exclusive) to stop at.
+         *
+         * @throws IndexOutOfBoundsException if fromIndex is negative, or toIndex is negative, or
+         *                                   fromIndex is larger than toIndex.
+         */
+        void set(int fromIndex, int toIndex);
+
+        /**
+         * Sets the bits from the specified fromIndex (inclusive) to the specified toIndex
+         * (exclusive) to the value given.
+         *
+         * @param fromIndex
+         *      The index (inclusive) to start at.
+         * @param toIndex
+         *      The index (exclusive) to stop at.
+         * @param value
+         *      The boolean value to assign to the target bits.
+         *
+         * @throws IndexOutOfBoundsException if fromIndex is negative, or toIndex is negative, or
+         *                                   fromIndex is larger than toIndex.
+         */
+        void set(int fromIndex, int toIndex, bool value);
+
+        /**
+         * Returns the number of bits of space actually in use by this BitSet to represent bit
+         * values. The maximum element in the set is the size - 1st element.
+         *
+         * @returns the number of bits currently in this bit set.
+         */
+        int size() const;
+
+        /**
+         * Returns a string representation of this bit set. For every index for which this BitSet
+         * contains a bit in the set state, the decimal representation of that index is included
+         * in the result. Such indices are listed in order from lowest to highest, separated by
+         * ", " (a comma and a space) and surrounded by braces, resulting in the usual mathematical
+         * notation for a set of integers.
+         *
+         * @returns string representation of the BitSet.
+         */
+        std::string toString() const;
+
+        /**
+         * Performs a logical XOR of this bit set with the bit set argument. This bit set is modified
+         * so that a bit in it has the value true if and only if one of the following statements holds:
+         *
+         *   * The bit initially has the value true, and the corresponding bit in the argument has
+         *     the value false.
+         *   * The bit initially has the value false, and the corresponding bit in the argument has
+         *     the value true.
+         *
+         * @param set
+         *      The BitSet to use.
+         */
+        void XOR(const BitSet& set);
+
+    private:
+
+        /**
+         * Increase the size of the internal array to accommodate length bits.
+         * The new array max index will be a multiple of 64.
+         *
+         * @param length
+         *      the index the new array needs to be able to access.
+         */
+        void ensureCapacity(int length);
+
+        /**
+         * Gets the actual length of the BitSet bit array which is maintained in a
+         * sometimes lazy fashion to avoid excessive array traversals.  The actual
+         * length is the number of non-zero array elements in the physical array
+         * used to back this BitSet.
+         *
+         * @return the actual array length.
+         */
+        int getActualArrayLength() const;
+
+    };
+
+}}
+
+#endif /* _DECAF_UTIL_BITSET_H_ */

Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/BitSet.h
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/Config.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/Config.h?rev=1360895&r1=1360894&r2=1360895&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/Config.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/Config.h Thu Jul 12 19:59:01 2012
@@ -29,6 +29,10 @@
 #define DECAF_API
 #endif
 
+#ifndef NULL
+#define NULL 0
+#endif
+
 //
 // The purpose of this header is to try to detect the supported headers
 // of the platform when the ./configure script is not being used to generate

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/Makefile.am
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/Makefile.am?rev=1360895&r1=1360894&r2=1360895&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/Makefile.am (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/Makefile.am Thu Jul 12 19:59:01 2012
@@ -193,6 +193,7 @@ cc_sources = \
     decaf/util/AbstractSequentialListTest.cpp \
     decaf/util/ArrayListTest.cpp \
     decaf/util/ArraysTest.cpp \
+    decaf/util/BitSetTest.cpp \
     decaf/util/DateTest.cpp \
     decaf/util/Endian.cpp \
     decaf/util/LinkedListTest.cpp \
@@ -426,6 +427,7 @@ h_sources = \
     decaf/util/AbstractSequentialListTest.h \
     decaf/util/ArrayListTest.h \
     decaf/util/ArraysTest.h \
+    decaf/util/BitSetTest.h \
     decaf/util/DateTest.h \
     decaf/util/Endian.h \
     decaf/util/LinkedListTest.h \