include/BALL/COMMON/global.h | 26 +++++------ include/BALL/DATATYPE/bitVector.h | 2 +- include/BALL/DATATYPE/hashMap.h | 9 +--- include/BALL/DATATYPE/string.h | 11 +++-- include/BALL/DATATYPE/string.iC | 5 ++ include/BALL/SYSTEM/binaryFileAdaptor.h | 53 +++++++++++----------- source/COMMON/exception.C | 6 +-- source/COMMON/hash.C | 2 +- source/COMMON/init.C | 4 +- source/COMMON/logStream.C | 6 +-- source/COMMON/version.C | 2 +- source/STRUCTURE/BONDORDERS/FPTBondOrderStrategy.C | 41 +++++++++-------- source/STRUCTURE/kekulizer.C | 8 ++-- 13 files changed, 91 insertions(+), 84 deletions(-) diff --git a/include/BALL/COMMON/global.h b/include/BALL/COMMON/global.h index 11d9246..02c81c6 100644 --- a/include/BALL/COMMON/global.h +++ b/include/BALL/COMMON/global.h @@ -9,7 +9,7 @@ # include #endif -#include +#include #include #ifdef BALL_HAS_BASETSD_H @@ -223,28 +223,28 @@ namespace BALL ASCII__SEMICOLON = ';' }; - static const Distance INVALID_DISTANCE = INT_MIN; - static const Distance DISTANCE_MIN = (INT_MIN + 1); - static const Distance DISTANCE_MAX = INT_MAX; + static const Distance INVALID_DISTANCE = std::numeric_limits::max(); + static const Distance DISTANCE_MIN = (std::numeric_limits::min() + 1); + static const Distance DISTANCE_MAX = std::numeric_limits::max(); - static const Handle INVALID_HANDLE = INT_MAX; + static const Handle INVALID_HANDLE = std::numeric_limits::max(); static const Handle HANDLE_MIN = 0 ; - static const Handle HANDLE_MAX = INT_MAX - 1; + static const Handle HANDLE_MAX = std::numeric_limits::max() - 1; static const Index INVALID_INDEX = -1; static const Index INDEX_MIN = 0; - static const Index INDEX_MAX = INT_MAX; + static const Index INDEX_MAX = std::numeric_limits::max(); - static const Position INVALID_POSITION = INT_MAX; + static const Position INVALID_POSITION = std::numeric_limits::max(); static const Position POSITION_MIN = 0; - static const Position POSITION_MAX = INT_MAX - 1; + static const Position POSITION_MAX = std::numeric_limits::max() - 1; # undef SIZE_MAX - static const Size INVALID_SIZE = INT_MAX; + static const Size INVALID_SIZE = std::numeric_limits::max(); static const Size SIZE_MIN = 0; - static const Size SIZE_MAX = INT_MAX - 1; - - + static const Size SIZE_MAX = std::numeric_limits::max() - 1; + + } #endif // BALL_COMMON_GLOBAL_H diff --git a/include/BALL/DATATYPE/bitVector.h b/include/BALL/DATATYPE/bitVector.h index 991f08e..dc7ead6 100644 --- a/include/BALL/DATATYPE/bitVector.h +++ b/include/BALL/DATATYPE/bitVector.h @@ -18,7 +18,7 @@ #endif -#include +#include #define BALL_BLOCK_BITS 8 #define BALL_BLOCK_MASK (BALL_BLOCK_BITS - 1) diff --git a/include/BALL/DATATYPE/hashMap.h b/include/BALL/DATATYPE/hashMap.h index 329db2b..f185b8c 100644 --- a/include/BALL/DATATYPE/hashMap.h +++ b/include/BALL/DATATYPE/hashMap.h @@ -236,7 +236,7 @@ namespace BALL template const T& HashMap::operator [] (const Key& key) const { - ConstIterator it = find(key); + ConstIterator it = this->find(key); if (it == Base::end()) { throw IllegalKey(__FILE__, __LINE__); @@ -272,12 +272,7 @@ namespace BALL T& HashMap::operator [] (const Key& key) { - Iterator it = find(key); - if (it == Base::end()) - { - it = insert(ValueType(key, T())).first; - } - return it->second; + return BALL_MAP_NAME::operator[] (key); } } // namespace BALL diff --git a/include/BALL/DATATYPE/string.h b/include/BALL/DATATYPE/string.h index 1172180..aa11c35 100644 --- a/include/BALL/DATATYPE/string.h +++ b/include/BALL/DATATYPE/string.h @@ -27,10 +27,10 @@ #endif #include -#include -#include -#include -#include +#include +#include +#include +#include #include #include @@ -155,6 +155,9 @@ namespace BALL /// STL string copy constructor String(const string& string); + /// Copy constructor + String(const String& s); + #ifdef BALL_STD_STRING_HAS_RVALUE_REFERENCES /// Move constructor String(String&& s); diff --git a/include/BALL/DATATYPE/string.iC b/include/BALL/DATATYPE/string.iC index b255849..c347588 100644 --- a/include/BALL/DATATYPE/string.iC +++ b/include/BALL/DATATYPE/string.iC @@ -8,6 +8,11 @@ String::String() { } +BALL_INLINE String::String(const String& s) + : string(s) +{ +} + #ifdef BALL_STD_STRING_HAS_RVALUE_REFERENCES BALL_INLINE String::String(String&& s) diff --git a/include/BALL/SYSTEM/binaryFileAdaptor.h b/include/BALL/SYSTEM/binaryFileAdaptor.h index 64f0f5d..6488e18 100644 --- a/include/BALL/SYSTEM/binaryFileAdaptor.h +++ b/include/BALL/SYSTEM/binaryFileAdaptor.h @@ -10,6 +10,33 @@ namespace BALL { + /** Coping with endianness. This function swaps the bytes of a variable + of type T if this type is of size 2n. + */ + template + void swapBytes(T& t) + { + if (sizeof(T) % 2 != 0) + { + Log.error() << "Cannot swap types of uneven size." << std::endl; + return; + } + + char* tmp = reinterpret_cast(&t); + std::reverse(tmp, tmp + sizeof(T)); + } + + //In the following some specialisations of swapBytes are provided for efficiency reasons + //These should also cover BALL types like Size, Position and Index + template<> BALL_EXPORT void swapBytes(unsigned short&); + template<> BALL_EXPORT void swapBytes(short&); + template<> BALL_EXPORT void swapBytes(unsigned int&); + template<> BALL_EXPORT void swapBytes(int&); + template<> BALL_EXPORT void swapBytes(unsigned long&); + template<> BALL_EXPORT void swapBytes(long&); + template<> BALL_EXPORT void swapBytes(float&); + template<> BALL_EXPORT void swapBytes(double&); + /** * Helper class for data conversion. * BinaryFileAdaptors are used to read and write binary data from and to @@ -152,32 +179,6 @@ namespace BALL return is; } - /** Coping with endianness. This function swaps the bytes of a variable - of type T if this type is of size 2n. - */ - template - void swapBytes(T& t) - { - if (sizeof(T) % 2 != 0) - { - Log.error() << "Cannot swap types of uneven size." << std::endl; - return; - } - - char* tmp = reinterpret_cast(&t); - std::reverse(tmp, tmp + sizeof(T)); - } - - //In the following some specialisations of swapBytes are provided for efficiency reasons - //These should also cover BALL types like Size, Position and Index - template<> BALL_EXPORT void swapBytes(unsigned short&); - template<> BALL_EXPORT void swapBytes(short&); - template<> BALL_EXPORT void swapBytes(unsigned int&); - template<> BALL_EXPORT void swapBytes(int&); - template<> BALL_EXPORT void swapBytes(unsigned long&); - template<> BALL_EXPORT void swapBytes(long&); - template<> BALL_EXPORT void swapBytes(float&); - template<> BALL_EXPORT void swapBytes(double&); } //namespace BALL #ifndef BALL_NO_INLINE_FUNCTIONS diff --git a/source/COMMON/exception.C b/source/COMMON/exception.C index e7855ce..464f971 100644 --- a/source/COMMON/exception.C +++ b/source/COMMON/exception.C @@ -9,10 +9,10 @@ #include #include #include -#include -#include // for getenv in terminate() +#include +#include // for getenv in terminate() #include -#include // for SIGSEGV and kill +#include // for SIGSEGV and kill #ifdef BALL_HAS_UNISTD_H # include // fot getpid diff --git a/source/COMMON/hash.C b/source/COMMON/hash.C index 0d81493..ffe75de 100644 --- a/source/COMMON/hash.C +++ b/source/COMMON/hash.C @@ -72,7 +72,7 @@ namespace BALL Index index = 0; Index temp_index; -# define BALL_BITS_IN_HASHVALUE_ (sizeof(Index) * CHAR_BIT) +# define BALL_BITS_IN_HASHVALUE_ (sizeof(Index) * std::numeric_limits::digits) # define BALL_THREE_QUARTERS_ ((Index)((BALL_BITS_IN_HASHVALUE_ * 3) / 4)) # define BALL_ONE_EIGHTH_ ((Index)(BALL_BITS_IN_HASHVALUE_ / 8)) # define BALL_HIGH_BITS_ (~((Index)(~0) >> BALL_ONE_EIGHTH_)) diff --git a/source/COMMON/init.C b/source/COMMON/init.C index d426756..856fe68 100644 --- a/source/COMMON/init.C +++ b/source/COMMON/init.C @@ -4,8 +4,8 @@ #include -#include -#include +#include +#include namespace BALL { diff --git a/source/COMMON/logStream.C b/source/COMMON/logStream.C index 12b9184..0340e24 100644 --- a/source/COMMON/logStream.C +++ b/source/COMMON/logStream.C @@ -26,9 +26,9 @@ namespace BALL // at this point, it is not yet possible to // include BALL/COMMON/limits.h (which were a // much nicer solution...). Ugly header dependencies... - const int LogStreamBuf::MIN_LEVEL = INT_MIN; - const int LogStreamBuf::MAX_LEVEL = INT_MAX; - const Time LogStreamBuf::MAX_TIME = INT_MAX; + const int LogStreamBuf::MIN_LEVEL = std::numeric_limits::min(); + const int LogStreamBuf::MAX_LEVEL = std::numeric_limits::max(); + const Time LogStreamBuf::MAX_TIME = std::numeric_limits