From 4226e548662339ea1ca37b45385a7cf9b237ff1e Mon Sep 17 00:00:00 2001 From: Daniel Wilhelm Date: Fri, 18 Apr 2014 17:07:43 +0200 Subject: 3.8 --- shared/globalFunctions.h | 72 +++++++++++++++++++++++------------------------- 1 file changed, 35 insertions(+), 37 deletions(-) (limited to 'shared/globalFunctions.h') diff --git a/shared/globalFunctions.h b/shared/globalFunctions.h index daf495b5..fe65889f 100644 --- a/shared/globalFunctions.h +++ b/shared/globalFunctions.h @@ -37,19 +37,22 @@ T abs(const T& d) //absolute value return(d < 0 ? -d : d); } -template -std::string numberToString(const T& number); //convert number to string the C++ way -template -void stringToNumber(const std::string& input, T& number); //convert string to number the C++ way +//number conversion C++ ANSI/wide char versions +template +std::basic_string numberToString(const T& number); //convert number to string the C++ way + +template +T stringToNumber(const std::basic_string& input); //convert number to string the C++ way +//number conversion wxWidgets +template wxString numberToString(const T& number); +template T stringToNumber(const wxString& input); -int wxStringToInt( const wxString& number); //convert wxString to number -double wxStringToDouble(const wxString& number); //convert wxString to number size_t getDigitCount(size_t number); //count number of digits -//read/write numbers: int, long, unsigned int ... ect +//serialization: read/write numbers: int, long, unsigned int ... ect template T readNumber(std::istream& stream); template void writeNumber(std::ostream& stream, T number); @@ -64,10 +67,6 @@ wxLongLong convertToSigned(const wxULongLong number) template void removeRowsFromVector(const std::set& rowsToRemove, std::vector& grid); -//bubble sort using swap() instead of assignment: useful if assignment is very expensive -template -void bubbleSwapSort(VectorData& folderCmp, CompareFct compare); - //enhanced binary search template: returns an iterator template ForwardIterator custom_binary_search(ForwardIterator first, ForwardIterator last, const T& value, Compare comp = std::less()); @@ -135,22 +134,41 @@ wxString getCodeLocation(const wxString file, const int line); //---------------Inline Implementation--------------------------------------------------- -template +template inline -std::string globalFunctions::numberToString(const T& number) //convert number to string the C++ way +std::basic_string globalFunctions::numberToString(const T& number) //convert number to string the C++ way { - std::ostringstream ss; + std::basic_ostringstream ss; ss << number; return ss.str(); } -template +template inline -void globalFunctions::stringToNumber(const std::string& input, T& number) //convert number to string the C++ way +T globalFunctions::stringToNumber(const std::basic_string& input) //convert number to string the C++ way { - std::istringstream ss(input); + std::basic_istringstream ss(input); + T number; ss >> number; + return number; +} + + +template +inline +wxString globalFunctions::numberToString(const T& number) +{ + return numberToString(number).c_str(); +} + + +template +inline +T globalFunctions::stringToNumber(const wxString& input) +{ + const std::basic_string inputConv = input.c_str(); + return stringToNumber(inputConv); } @@ -187,26 +205,6 @@ void globalFunctions::removeRowsFromVector(const std::set& rowsToRemove, } -//bubble sort using swap() instead of assignment: useful if assignment is very expensive -template -void globalFunctions::bubbleSwapSort(VectorData& folderCmp, CompareFct compare) -{ - for (int i = folderCmp.size() - 2; i >= 0; --i) - { - bool swapped = false; - for (int j = 0; j <= i; ++j) - if (compare(folderCmp[j + 1], folderCmp[j])) - { - folderCmp[j + 1].swap(folderCmp[j]); - swapped = true; - } - - if (!swapped) - return; - } -} - - //enhanced binary search template: returns an iterator template inline -- cgit