diff options
author | Daniel Wilhelm <daniel@wili.li> | 2014-04-18 17:11:56 +0200 |
---|---|---|
committer | Daniel Wilhelm <daniel@wili.li> | 2014-04-18 17:11:56 +0200 |
commit | 98ecf620f7de377dc8ae9ad7fbd1e3b24477e138 (patch) | |
tree | faadc6d8822c20cd3bc6f50b2a98e6c580585949 /shared/global_func.h | |
parent | 3.16 (diff) | |
download | FreeFileSync-98ecf620f7de377dc8ae9ad7fbd1e3b24477e138.tar.gz FreeFileSync-98ecf620f7de377dc8ae9ad7fbd1e3b24477e138.tar.bz2 FreeFileSync-98ecf620f7de377dc8ae9ad7fbd1e3b24477e138.zip |
3.17
Diffstat (limited to 'shared/global_func.h')
-rw-r--r-- | shared/global_func.h | 107 |
1 files changed, 7 insertions, 100 deletions
diff --git a/shared/global_func.h b/shared/global_func.h index e0f5434a..9dd1faf7 100644 --- a/shared/global_func.h +++ b/shared/global_func.h @@ -12,57 +12,20 @@ #include <vector> #include <set> #include <wx/string.h> -#include <wx/longlong.h> -#include <memory> -#include <sstream> - -class wxStopWatch; +//#include <memory> +//#include <sstream> namespace common { -//------------------------------------------------ -// FUNCTIONS -//------------------------------------------------ -inline -int round(double d) //little rounding function -{ - return static_cast<int>(d < 0 ? d - .5 : d + .5); -} - -template <class T> -inline -T abs(const T& d) //absolute value -{ - return d < 0 ? -d : d; -} - - -//formatted number conversion C++ ANSI/wide char versions -template <class CharType, class T> -std::basic_string<CharType> numberToString(const T& number); //convert number to string the C++ way - -template <class T, class CharType> -T stringToNumber(const std::basic_string<CharType>& input); //convert number to string the C++ way - -//formatted number conversion wxWidgets -template <class T> wxString numberToString(const T& number); -template <class T> T stringToNumber(const wxString& input); +//little rounding function +inline int round(double d) { return static_cast<int>(d < 0 ? d - .5 : d + .5); } +//absolute value +template <class T> inline T abs(const T& d) { return d < 0 ? -d : d; } size_t getDigitCount(size_t number); //count number of digits -//serialization: read/write numbers: int, long, unsigned int ... ect -template <class T> T readNumber(std::istream& stream); -template <class T> void writeNumber(std::ostream& stream, T number); - -inline -wxLongLong convertToSigned(const wxULongLong number) -{ - return wxLongLong(number.GetHi(), number.GetLo()); -} - - //Note: the following lines are a performance optimization for deleting elements from a vector: linear runtime at most! template <class T> void removeRowsFromVector(const std::set<size_t>& rowsToRemove, std::vector<T>& grid); @@ -118,43 +81,6 @@ wxString getCodeLocation(const wxString file, const int line); //---------------Inline Implementation--------------------------------------------------- -template <class CharType, class T> -inline -std::basic_string<CharType> common::numberToString(const T& number) //convert number to string the C++ way -{ - std::basic_ostringstream<CharType> ss; - ss << number; - return ss.str(); -} - - -template <class T, class CharType> -inline -T common::stringToNumber(const std::basic_string<CharType>& input) //convert number to string the C++ way -{ - T number = 0; - std::basic_istringstream<CharType>(input) >> number; - return number; -} - - -template <class T> -inline -wxString common::numberToString(const T& number) -{ - return numberToString<wxChar, T>(number).c_str(); -} - - -template <class T> -inline -T common::stringToNumber(const wxString& input) -{ - const std::basic_string<wxChar> inputConv(input.c_str()); - return stringToNumber<T, wxChar>(inputConv); -} - - //Note: the following lines are a performance optimization for deleting elements from a vector: linear runtime at most! template <class T> void common::removeRowsFromVector(const std::set<size_t>& rowsToRemove, std::vector<T>& grid) @@ -200,23 +126,4 @@ ForwardIterator common::custom_binary_search(ForwardIterator first, ForwardItera return last; } - -template <class T> -inline -T common::readNumber(std::istream& stream) -{ - T result = 0; - stream.read(reinterpret_cast<char*>(&result), sizeof(T)); - return result; -} - - -template <class T> -inline -void common::writeNumber(std::ostream& stream, T number) -{ - stream.write(reinterpret_cast<const char*>(&number), sizeof(T)); -} - - -#endif // GLOBALFUNCTIONS_H_INCLUDED +#endif // GLOBALFUNCTIONS_H_INCLUDED
\ No newline at end of file |