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/10/18 22:21:45 UTC
svn commit: r1399831 [2/2] - in
/activemq/activemq-cpp/trunk/activemq-cpp/src/main: ./ decaf/internal/
decaf/internal/util/
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/util/HexStringParser.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/util/HexStringParser.cpp?rev=1399831&r1=1399830&r2=1399831&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/util/HexStringParser.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/util/HexStringParser.cpp Thu Oct 18 20:21:44 2012
@@ -45,58 +45,58 @@ const std::string HexStringParser::HEX_P
"[\\x00-\\x20]*([+-]?)" + HEX_SIGNIFICANT + BINARY_EXPONENT + FLOAT_TYPE_SUFFIX + "[\\x00-\\x20]*";
////////////////////////////////////////////////////////////////////////////////
-HexStringParser::HexStringParser( int exponentWidth, int mantissaWidth ) : EXPONENT_WIDTH(exponentWidth),
- MANTISSA_WIDTH(mantissaWidth),
- EXPONENT_BASE(0),
- MAX_EXPONENT(0),
- MIN_EXPONENT(),
- MANTISSA_MASK(),
- sign(0),
- exponent(0),
- mantissa(0),
- abandonedNumber() {
- this->EXPONENT_BASE = ~( -1 << (exponentWidth - 1) );
- this->MAX_EXPONENT = ~( -1 << exponentWidth );
- this->MIN_EXPONENT = -( MANTISSA_WIDTH + 1 );
- this->MANTISSA_MASK = ~( -1 << mantissaWidth );
+HexStringParser::HexStringParser(int exponentWidth, int mantissaWidth) : EXPONENT_WIDTH(exponentWidth),
+ MANTISSA_WIDTH(mantissaWidth),
+ EXPONENT_BASE(0),
+ MAX_EXPONENT(0),
+ MIN_EXPONENT(),
+ MANTISSA_MASK(),
+ sign(0),
+ exponent(0),
+ mantissa(0),
+ abandonedNumber() {
+ this->EXPONENT_BASE = ~(-1 << (exponentWidth - 1));
+ this->MAX_EXPONENT = ~(-1 << exponentWidth);
+ this->MIN_EXPONENT = -(MANTISSA_WIDTH + 1);
+ this->MANTISSA_MASK = ~(-1 << mantissaWidth);
}
////////////////////////////////////////////////////////////////////////////////
-double HexStringParser::parseDouble( const std::string& hexString ) {
+double HexStringParser::parseDouble(const std::string& hexString) {
- HexStringParser parser( DOUBLE_EXPONENT_WIDTH, DOUBLE_MANTISSA_WIDTH );
- long long result = parser.parse( hexString );
- return Double::longBitsToDouble( result );
+ HexStringParser parser(DOUBLE_EXPONENT_WIDTH, DOUBLE_MANTISSA_WIDTH);
+ long long result = parser.parse(hexString);
+ return Double::longBitsToDouble(result);
}
////////////////////////////////////////////////////////////////////////////////
-float HexStringParser::parseFloat( const std::string& hexString ) {
+float HexStringParser::parseFloat(const std::string& hexString) {
- HexStringParser parser( FLOAT_EXPONENT_WIDTH, FLOAT_MANTISSA_WIDTH );
- int result = (int)parser.parse( hexString );
- return Float::intBitsToFloat( result );
+ HexStringParser parser(FLOAT_EXPONENT_WIDTH, FLOAT_MANTISSA_WIDTH);
+ int result = (int) parser.parse(hexString);
+ return Float::intBitsToFloat(result);
}
////////////////////////////////////////////////////////////////////////////////
-long long HexStringParser::parse( const std::string& hexString ) {
+long long HexStringParser::parse(const std::string& hexString) {
- std::string* hexSegments = getSegmentsFromHexString( hexString );
+ std::string* hexSegments = getSegmentsFromHexString(hexString);
std::string signStr = hexSegments[0];
std::string significantStr = hexSegments[1];
std::string exponentStr = hexSegments[2];
delete hexSegments;
- parseHexSign( signStr );
- parseExponent( exponentStr );
- parseMantissa( significantStr );
+ parseHexSign(signStr);
+ parseExponent(exponentStr);
+ parseMantissa(significantStr);
- sign <<= ( MANTISSA_WIDTH + EXPONENT_WIDTH );
+ sign <<= (MANTISSA_WIDTH + EXPONENT_WIDTH);
exponent <<= MANTISSA_WIDTH;
return sign | exponent | mantissa;
}
////////////////////////////////////////////////////////////////////////////////
-std::string* HexStringParser::getSegmentsFromHexString( DECAF_UNUSED const std::string& hexString ) {
+std::string* HexStringParser::getSegmentsFromHexString(DECAF_UNUSED const std::string& hexString) {
// apr_pool_t* thePool = NULL;
// apr_pool_create( &thePool, NULL );
@@ -106,8 +106,7 @@ std::string* HexStringParser::getSegment
// std::vector<std::string> hexSegments;
//
-
- // TODO
+// TODO
// Matcher matcher = PATTERN.matcher(hexString);
// if( !matcher.matches() ) {
// throw NumberFormatException(
@@ -132,15 +131,15 @@ void HexStringParser::parseExponent(cons
std::string newExponentStr = exponentStr;
char leadingChar = newExponentStr.at(0);
- int expSign = ( leadingChar == '-' ? -1 : 1 );
- if( !Character::isDigit( leadingChar ) ) {
- newExponentStr = newExponentStr.substr( 1, newExponentStr.size() );
+ int expSign = (leadingChar == '-' ? -1 : 1);
+ if (!Character::isDigit(leadingChar)) {
+ newExponentStr = newExponentStr.substr(1, newExponentStr.size());
}
try {
- exponent = expSign * Long::parseLong( exponentStr );
- checkedAddExponent( EXPONENT_BASE );
- } catch( exceptions::NumberFormatException& e ) {
+ exponent = expSign * Long::parseLong(exponentStr);
+ checkedAddExponent(EXPONENT_BASE);
+ } catch (exceptions::NumberFormatException& e) {
exponent = expSign * Long::MAX_VALUE;
}
}
@@ -148,58 +147,56 @@ void HexStringParser::parseExponent(cons
////////////////////////////////////////////////////////////////////////////////
void HexStringParser::parseMantissa(const std::string& significantStr) {
- StringTokenizer tokenizer( significantStr, "\\." );
+ StringTokenizer tokenizer(significantStr, "\\.");
std::vector<std::string> strings;
- tokenizer.toArray( strings );
+ tokenizer.toArray(strings);
std::string strIntegerPart = strings[0];
std::string strDecimalPart = strings.size() > 1 ? strings[1] : "";
- std::string significand =
- getNormalizedSignificand( strIntegerPart, strDecimalPart) ;
+ std::string significand = getNormalizedSignificand(strIntegerPart, strDecimalPart);
- if( significand == "0" ) {
+ if (significand == "0") {
setZero();
return;
}
- int offset = getOffset( strIntegerPart, strDecimalPart );
- checkedAddExponent( offset );
+ int offset = getOffset(strIntegerPart, strDecimalPart);
+ checkedAddExponent(offset);
- if( exponent >= MAX_EXPONENT ) {
+ if (exponent >= MAX_EXPONENT) {
setInfinite();
return;
}
- if( exponent <= MIN_EXPONENT ) {
+ if (exponent <= MIN_EXPONENT) {
setZero();
return;
}
- if( significand.length() > MAX_SIGNIFICANT_LENGTH ) {
- abandonedNumber = significand.substr( MAX_SIGNIFICANT_LENGTH );
- significand = significand.substr( 0, MAX_SIGNIFICANT_LENGTH );
+ if (significand.length() > MAX_SIGNIFICANT_LENGTH) {
+ abandonedNumber = significand.substr(MAX_SIGNIFICANT_LENGTH);
+ significand = significand.substr(0, MAX_SIGNIFICANT_LENGTH);
}
- mantissa = Long::parseLong( significand, HEX_RADIX );
+ mantissa = Long::parseLong(significand, HEX_RADIX);
- if( exponent >= 1 ) {
+ if (exponent >= 1) {
processNormalNumber();
- } else{
+ } else {
processSubNormalNumber();
}
}
////////////////////////////////////////////////////////////////////////////////
-void HexStringParser::checkedAddExponent( long long offset ) {
+void HexStringParser::checkedAddExponent(long long offset) {
long long result = exponent + offset;
- int expSign = Long::signum( exponent );
+ int expSign = Long::signum(exponent);
- if( expSign * Long::signum( offset ) > 0 &&
- expSign * Long::signum( result ) < 0 ) {
+ if (expSign * Long::signum(offset) > 0 && expSign * Long::signum(result) < 0) {
exponent = expSign * Long::MAX_VALUE;
} else {
@@ -210,7 +207,7 @@ void HexStringParser::checkedAddExponent
////////////////////////////////////////////////////////////////////////////////
void HexStringParser::processNormalNumber() {
int desiredWidth = MANTISSA_WIDTH + 2;
- fitMantissaInDesiredWidth( desiredWidth );
+ fitMantissaInDesiredWidth(desiredWidth);
round();
mantissa = mantissa & MANTISSA_MASK;
}
@@ -218,27 +215,27 @@ void HexStringParser::processNormalNumbe
////////////////////////////////////////////////////////////////////////////////
void HexStringParser::processSubNormalNumber() {
int desiredWidth = MANTISSA_WIDTH + 1;
- desiredWidth += (int)exponent;//lends bit from mantissa to exponent
+ desiredWidth += (int) exponent; //lends bit from mantissa to exponent
exponent = 0;
- fitMantissaInDesiredWidth( desiredWidth );
+ fitMantissaInDesiredWidth(desiredWidth);
round();
mantissa = mantissa & MANTISSA_MASK;
}
////////////////////////////////////////////////////////////////////////////////
-void HexStringParser::fitMantissaInDesiredWidth(int desiredWidth){
- int bitLength = countBitsLength( mantissa );
- if( bitLength > desiredWidth ) {
- discardTrailingBits( bitLength - desiredWidth );
+void HexStringParser::fitMantissaInDesiredWidth(int desiredWidth) {
+ int bitLength = countBitsLength(mantissa);
+ if (bitLength > desiredWidth) {
+ discardTrailingBits(bitLength - desiredWidth);
} else {
- mantissa <<= ( desiredWidth - bitLength );
+ mantissa <<= (desiredWidth - bitLength);
}
}
////////////////////////////////////////////////////////////////////////////////
-void HexStringParser::discardTrailingBits( long long num ) {
- long long mask = ~( -1L << num );
- abandonedNumber += (char)( mantissa & mask );
+void HexStringParser::discardTrailingBits(long long num) {
+ long long mask = ~(-1L << num);
+ abandonedNumber += (char) (mantissa & mask);
mantissa >>= num;
}
@@ -246,72 +243,69 @@ void HexStringParser::discardTrailingBit
void HexStringParser::round() {
std::string result = abandonedNumber;
- replaceAll( result, "0+", "" );
+ replaceAll(result, "0+", "");
- bool moreThanZero = ( result.length() > 0 ? true : false );
+ bool moreThanZero = (result.length() > 0 ? true : false);
- int lastDiscardedBit = (int)( mantissa & 1L );
+ int lastDiscardedBit = (int) (mantissa & 1L);
mantissa >>= 1;
- int tailBitInMantissa = (int)( mantissa & 1L );
+ int tailBitInMantissa = (int) (mantissa & 1L);
- if( lastDiscardedBit == 1 && ( moreThanZero || tailBitInMantissa == 1 ) ) {
+ if (lastDiscardedBit == 1 && (moreThanZero || tailBitInMantissa == 1)) {
- int oldLength = countBitsLength( mantissa );
+ int oldLength = countBitsLength(mantissa);
mantissa += 1L;
- int newLength = countBitsLength( mantissa );
+ int newLength = countBitsLength(mantissa);
//Rounds up to exponent when whole bits of mantissa are one-bits.
- if( oldLength >= MANTISSA_WIDTH && newLength > oldLength ) {
- checkedAddExponent( 1 );
+ if (oldLength >= MANTISSA_WIDTH && newLength > oldLength) {
+ checkedAddExponent(1);
}
}
}
////////////////////////////////////////////////////////////////////////////////
-std::string HexStringParser::getNormalizedSignificand(
- const std::string& strIntegerPart, const std::string& strDecimalPart ) {
+std::string HexStringParser::getNormalizedSignificand(const std::string& strIntegerPart, const std::string& strDecimalPart) {
std::string significand = strIntegerPart + strDecimalPart;
- replaceFirst( significand, "^0x", "" );
+ replaceFirst(significand, "^0x", "");
- if( significand.length() == 0 ) {
+ if (significand.length() == 0) {
significand = "0";
}
return significand;
}
////////////////////////////////////////////////////////////////////////////////
-int HexStringParser::getOffset(
- const std::string& strIntegerPart, const std::string& strDecimalPart ) {
+int HexStringParser::getOffset(const std::string& strIntegerPart, const std::string& strDecimalPart) {
std::string strIntegerPart2 = strIntegerPart;
- replaceFirst( strIntegerPart2, "^0+", "" );
+ replaceFirst(strIntegerPart2, "^0+", "");
//If the Integer part is a nonzero number.
- if( strIntegerPart.length() != 0 ) {
- std::string leadingNumber = strIntegerPart.substr( 0, 1 );
- return (int)( ( strIntegerPart.length() - 1) * 4 +
- countBitsLength(Long::parseLong( leadingNumber,HEX_RADIX ) ) - 1 );
+ if (strIntegerPart.length() != 0) {
+ std::string leadingNumber = strIntegerPart.substr(0, 1);
+ return (int) ((strIntegerPart.length() - 1) * 4 + countBitsLength(Long::parseLong(leadingNumber, HEX_RADIX)) - 1);
}
//If the Integer part is a zero number.
int i;
- for( i = 0; (std::size_t)i < strDecimalPart.length() && strDecimalPart.at(i) == '0'; i++ ) {};
+ for (i = 0; (std::size_t) i < strDecimalPart.length() && strDecimalPart.at(i) == '0'; i++) {
+ };
- if( (std::size_t)i == strDecimalPart.length() ) {
+ if ((std::size_t) i == strDecimalPart.length()) {
return 0;
}
- std::string leadingNumber = strDecimalPart.substr( i,i + 1 );
+ std::string leadingNumber = strDecimalPart.substr(i, i + 1);
- return (-i - 1) * 4 +
- countBitsLength( Long::parseLong( leadingNumber, HEX_RADIX) ) - 1;
+ return (-i - 1) * 4 + countBitsLength(Long::parseLong(leadingNumber, HEX_RADIX)) - 1;
}
////////////////////////////////////////////////////////////////////////////////
int HexStringParser::countBitsLength(long long value) {
- int leadingZeros = Long::numberOfLeadingZeros( value );
+ int leadingZeros = Long::numberOfLeadingZeros(value);
return Long::SIZE - leadingZeros;
}
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/util/HexStringParser.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/util/HexStringParser.h?rev=1399831&r1=1399830&r2=1399831&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/util/HexStringParser.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/util/HexStringParser.h Thu Oct 18 20:21:44 2012
@@ -21,9 +21,9 @@
#include <decaf/util/Config.h>
#include <string>
-namespace decaf{
-namespace internal{
-namespace util{
+namespace decaf {
+namespace internal {
+namespace util {
class HexStringParser {
private:
@@ -63,9 +63,10 @@ namespace util{
* @param exponentWidth - Width of the exponent for the type to parse
* @param mantissaWidth - Width of the mantissa for the type to parse
*/
- HexStringParser( int exponentWidth, int mantissaWidth );
+ HexStringParser(int exponentWidth, int mantissaWidth);
- virtual ~HexStringParser() {}
+ virtual ~HexStringParser() {
+ }
/**
* Parses a hex string using the specs given in the constructor
@@ -74,7 +75,7 @@ namespace util{
* @param hexString - string to parse
* @returns the bits parsed from the string
*/
- long long parse( const std::string& hexString );
+ long long parse(const std::string& hexString);
private:
@@ -82,7 +83,7 @@ namespace util{
* Parses the sign field.
* @param sign string to parse
*/
- void parseHexSign( const std::string& signStr ) {
+ void parseHexSign(const std::string& signStr) {
this->sign = signStr.compare("-") == 0 ? 1 : 0;
}
@@ -90,13 +91,13 @@ namespace util{
* Parses the exponent field.
* @param exponent string to parse
*/
- void parseExponent( const std::string& exponentStr );
+ void parseExponent(const std::string& exponentStr);
/*
* Parses the mantissa field.
* @param mantissa string to parse
*/
- void parseMantissa( const std::string& significantStr );
+ void parseMantissa(const std::string& significantStr);
void setInfinite() {
exponent = MAX_EXPONENT;
@@ -113,21 +114,21 @@ namespace util{
* overflow or underflow happens.
* @param the offset to set
*/
- void checkedAddExponent( long long offset );
+ void checkedAddExponent(long long offset);
void processNormalNumber();
void processSubNormalNumber();
- int countBitsLength( long long value );
+ int countBitsLength(long long value);
/*
* Adjusts the mantissa to desired width for further analysis.
*/
- void fitMantissaInDesiredWidth( int desiredWidth );
+ void fitMantissaInDesiredWidth(int desiredWidth);
/*
* Stores the discarded bits to abandonedNumber.
*/
- void discardTrailingBits( long long num );
+ void discardTrailingBits(long long num);
/*
* The value is rounded up or down to the nearest infinitely precise result.
@@ -139,8 +140,7 @@ namespace util{
/*
* Returns the normalized significand after removing the leading zeros.
*/
- std::string getNormalizedSignificand( const std::string& strIntegerPart,
- const std::string& strDecimalPart );
+ std::string getNormalizedSignificand(const std::string& strIntegerPart, const std::string& strDecimalPart);
/*
* Calculates the offset between the normalized number and unnormalized
@@ -148,55 +148,51 @@ namespace util{
* characters "0x1." followed by a lower-case hexadecimal representation of
* the rest of the significand as a fraction.
*/
- int getOffset( const std::string& strIntegerPart,
- const std::string& strDecimalPart );
+ int getOffset(const std::string& strIntegerPart, const std::string& strDecimalPart);
- public: // Statics
+ public:
+ // Statics
/*
* Parses the hex string to a double number.
* @param hexString - string to parse
* @returns the parsed double value
*/
- static double parseDouble( const std::string& hexString );
+ static double parseDouble(const std::string& hexString);
/*
* Parses the hex string to a float number.
* @param hexString - string to parse
* @returns the parsed float value
*/
- static float parseFloat( const std::string& hexString );
+ static float parseFloat(const std::string& hexString);
-
- private: // Static
+ private:
+ // Static
/*
* Analyzes the hex string and extracts the sign and digit segments.
* @param hexString - string to parse
* @returns array of three strings holding the segments caller owns
*/
- static std::string* getSegmentsFromHexString( const std::string& hexString );
+ static std::string* getSegmentsFromHexString(const std::string& hexString);
- std::string& replaceFirst( std::string& target,
- const std::string& find,
- const std::string& replace ) {
+ std::string& replaceFirst(std::string& target, const std::string& find, const std::string& replace) {
std::string::size_type pos = std::string::npos;
- if( ( pos = target.find_first_of( find, 0 ) ) != std::string::npos ) {
- return target.replace( pos, find.length(), replace );
+ if ((pos = target.find_first_of(find, 0)) != std::string::npos) {
+ return target.replace(pos, find.length(), replace);
}
return target;
}
- std::string& replaceAll( std::string& target,
- const std::string& find,
- const std::string& replace ) {
+ std::string& replaceAll(std::string& target, const std::string& find, const std::string& replace) {
std::string::size_type pos = std::string::npos;
- while( ( pos = target.find( find ) ) != std::string::npos ) {
- target.replace( pos, find.length(), replace );
+ while ((pos = target.find(find)) != std::string::npos) {
+ target.replace(pos, find.length(), replace);
}
return target;
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/util/ResourceLifecycleManager.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/util/ResourceLifecycleManager.cpp?rev=1399831&r1=1399830&r2=1399831&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/util/ResourceLifecycleManager.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/util/ResourceLifecycleManager.cpp Thu Oct 18 20:21:44 2012
@@ -33,36 +33,35 @@ ResourceLifecycleManager::ResourceLifecy
////////////////////////////////////////////////////////////////////////////////
ResourceLifecycleManager::~ResourceLifecycleManager() {
- try{
+ try {
this->destroyResources();
}
- DECAF_CATCH_NOTHROW( Exception )
DECAF_CATCHALL_NOTHROW()
}
////////////////////////////////////////////////////////////////////////////////
-void ResourceLifecycleManager::addResource( Resource* value ) {
+void ResourceLifecycleManager::addResource(Resource* value) {
- if( value == NULL ) {
+ if (value == NULL) {
return;
}
- this->resources.add( value );
+ this->resources.add(value);
}
////////////////////////////////////////////////////////////////////////////////
void ResourceLifecycleManager::destroyResources() {
- try{
+ try {
- std::auto_ptr< Iterator<Resource*> > iterator( this->resources.iterator() );
+ std::auto_ptr<Iterator<Resource*> > iterator(this->resources.iterator());
- while( iterator->hasNext() ) {
+ while (iterator->hasNext()) {
delete iterator->next();
}
this->resources.clear();
}
- DECAF_CATCH_RETHROW( Exception )
- DECAF_CATCHALL_THROW( Exception )
+ DECAF_CATCH_RETHROW(Exception)
+ DECAF_CATCHALL_THROW(Exception)
}
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/util/ResourceLifecycleManager.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/util/ResourceLifecycleManager.h?rev=1399831&r1=1399830&r2=1399831&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/util/ResourceLifecycleManager.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/util/ResourceLifecycleManager.h Thu Oct 18 20:21:44 2012
@@ -42,7 +42,7 @@ namespace util {
virtual ~ResourceLifecycleManager();
- virtual void addResource( Resource* value );
+ virtual void addResource(Resource* value);
protected:
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/util/TimerTaskHeap.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/util/TimerTaskHeap.cpp?rev=1399831&r1=1399830&r2=1399831&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/util/TimerTaskHeap.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/util/TimerTaskHeap.cpp Thu Oct 18 20:21:44 2012
@@ -32,7 +32,7 @@ TimerTaskHeap::~TimerTaskHeap() {
////////////////////////////////////////////////////////////////////////////////
Pointer<TimerTask> TimerTaskHeap::peek() {
- if( heap.empty() ) {
+ if (heap.empty()) {
return Pointer<TimerTask>();
}
@@ -50,20 +50,20 @@ std::size_t TimerTaskHeap::size() const
}
////////////////////////////////////////////////////////////////////////////////
-void TimerTaskHeap::insert( const Pointer<TimerTask>& task ) {
+void TimerTaskHeap::insert(const Pointer<TimerTask>& task) {
- heap.push_back( task );
+ heap.push_back(task);
upHeap();
}
////////////////////////////////////////////////////////////////////////////////
-void TimerTaskHeap::remove( std::size_t pos ) {
+void TimerTaskHeap::remove(std::size_t pos) {
// possible to delete any position of the heap
- if( pos < heap.size() ) {
+ if (pos < heap.size()) {
heap[pos] = heap.back();
heap.pop_back();
- downHeap( pos );
+ downHeap(pos);
}
}
@@ -71,9 +71,9 @@ void TimerTaskHeap::remove( std::size_t
void TimerTaskHeap::upHeap() {
std::size_t current = heap.size() - 1;
- std::size_t parent = ( current - 1 ) / 2;
+ std::size_t parent = (current - 1) / 2;
- while( current != 0 && heap[current]->when < heap[parent]->when) {
+ while (current != 0 && heap[current]->when < heap[parent]->when) {
// swap the two
Pointer<TimerTask> tmp = heap[current];
@@ -82,25 +82,25 @@ void TimerTaskHeap::upHeap() {
// update parent and current positions.
current = parent;
- parent = ( current - 1 ) / 2;
+ parent = (current - 1) / 2;
}
}
////////////////////////////////////////////////////////////////////////////////
-void TimerTaskHeap::downHeap( std::size_t pos ) {
+void TimerTaskHeap::downHeap(std::size_t pos) {
std::size_t current = pos;
std::size_t child = 2 * current + 1;
- while( child < heap.size() && !heap.empty() ) {
+ while (child < heap.size() && !heap.empty()) {
// compare the children if they exist
- if( child + 1 < heap.size() && heap[child + 1]->when < heap[child]->when) {
+ if (child + 1 < heap.size() && heap[child + 1]->when < heap[child]->when) {
child++;
}
// compare selected child with parent
- if( heap[current]->when < heap[child]->when ) {
+ if (heap[current]->when < heap[child]->when) {
break;
}
@@ -122,7 +122,7 @@ void TimerTaskHeap::reset() {
////////////////////////////////////////////////////////////////////////////////
void TimerTaskHeap::adjustMinimum() {
- downHeap( 0 );
+ downHeap(0);
}
////////////////////////////////////////////////////////////////////////////////
@@ -130,10 +130,10 @@ std::size_t TimerTaskHeap::deleteIfCance
std::size_t result = 0;
- for( std::size_t i = 0; i < heap.size(); ++i ) {
- if( heap[i]->cancelled ) {
+ for (std::size_t i = 0; i < heap.size(); ++i) {
+ if (heap[i]->cancelled) {
result++;
- remove( i );
+ remove(i);
// re-try this point
i--;
}
@@ -143,10 +143,10 @@ std::size_t TimerTaskHeap::deleteIfCance
}
////////////////////////////////////////////////////////////////////////////////
-std::size_t TimerTaskHeap::find( const Pointer<TimerTask>& task ) const {
+std::size_t TimerTaskHeap::find(const Pointer<TimerTask>& task) const {
- for( std::size_t i = 0; i < heap.size(); ++i ) {
- if( heap[i] == task ) {
+ for (std::size_t i = 0; i < heap.size(); ++i) {
+ if (heap[i] == task) {
return i;
}
}
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/util/TimerTaskHeap.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/util/TimerTaskHeap.h?rev=1399831&r1=1399830&r2=1399831&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/util/TimerTaskHeap.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/util/TimerTaskHeap.h Thu Oct 18 20:21:44 2012
@@ -42,7 +42,7 @@ namespace util {
static const int DEFAULT_HEAP_SIZE = 256;
// Dynamic Array of TimerTasks used to represent the heap
- std::vector< Pointer<TimerTask> > heap;
+ std::vector<Pointer<TimerTask> > heap;
public:
@@ -74,7 +74,7 @@ namespace util {
* @param task
* The TimerTask to insert into the heap.
*/
- void insert( const Pointer<TimerTask>& task );
+ void insert(const Pointer<TimerTask>& task);
/**
* Removes the Task at the specified position from the heap, resorts the heap from the
@@ -83,7 +83,7 @@ namespace util {
* @param pos
* The position at which to remove the TimerTask and begin a resort of the heap.
*/
- void remove( std::size_t pos );
+ void remove(std::size_t pos);
/**
* Clear all contents from the heap.
@@ -110,12 +110,12 @@ namespace util {
*
* @returns the position in the Heap where the Task is stored, or npos.
*/
- std::size_t find( const Pointer<TimerTask>& task ) const;
+ std::size_t find(const Pointer<TimerTask>& task) const;
private:
void upHeap();
- void downHeap( std::size_t pos );
+ void downHeap(std::size_t pos);
};