diff options
author | Daniel Wilhelm <daniel@wili.li> | 2014-04-18 16:59:06 +0200 |
---|---|---|
committer | Daniel Wilhelm <daniel@wili.li> | 2014-04-18 16:59:06 +0200 |
commit | 4046be06720932a57a0f49416b0144b2858824d0 (patch) | |
tree | 678c37cab05960f48923a23bb46d9e01be89d35a /library/globalFunctions.h | |
parent | 1.19 (diff) | |
download | FreeFileSync-4046be06720932a57a0f49416b0144b2858824d0.tar.gz FreeFileSync-4046be06720932a57a0f49416b0144b2858824d0.tar.bz2 FreeFileSync-4046be06720932a57a0f49416b0144b2858824d0.zip |
2.0
Diffstat (limited to 'library/globalFunctions.h')
-rw-r--r-- | library/globalFunctions.h | 88 |
1 files changed, 52 insertions, 36 deletions
diff --git a/library/globalFunctions.h b/library/globalFunctions.h index 622babcb..689fa5f1 100644 --- a/library/globalFunctions.h +++ b/library/globalFunctions.h @@ -6,9 +6,14 @@ #include <vector> #include <set> #include <wx/string.h> -#include <wx/stream.h> -#include <wx/stopwatch.h> #include <wx/longlong.h> +#include <memory> +#include <sstream> + +class wxInputStream; +class wxOutputStream; +class wxStopWatch; + namespace globalFunctions { @@ -25,10 +30,13 @@ namespace globalFunctions return(d < 0 ? -d : d); } - std::string numberToString(const unsigned int number); //convert number to string - std::string numberToString(const int number); //convert number to string - std::string numberToString(const long number); //convert number to string - std::string numberToString(const float number); //convert number to string + template <class T> + inline std::string numberToString(const T& number) //convert number to string the C++ way + { + std::stringstream ss; + ss << number; + return ss.str(); + } wxString numberToWxString(const unsigned int number); //convert number to wxString wxString numberToWxString(const int number); //convert number to wxString @@ -54,6 +62,43 @@ namespace globalFunctions { return wxLongLong(number.GetHi(), number.GetLo()); } + + + //Note: the following lines are a performance optimization for deleting elements from a vector. It is incredibly faster to create a new +//vector and leave specific elements out than to delete row by row and force recopying of most elements for each single deletion (linear vs quadratic runtime) + template <class T> + void removeRowsFromVector(const std::set<int>& rowsToRemove, std::vector<T>& grid) + { + if (rowsToRemove.size() > 0) + { + std::vector<T> temp; + + std::set<int>::const_iterator rowToSkipIndex = rowsToRemove.begin(); + int rowToSkip = *rowToSkipIndex; + + for (int i = 0; i < int(grid.size()); ++i) + { + if (i != rowToSkip) + temp.push_back(grid[i]); + else + { + ++rowToSkipIndex; + if (rowToSkipIndex != rowsToRemove.end()) + rowToSkip = *rowToSkipIndex; + } + } + grid.swap(temp); + } + } + + + template <class T> + inline + void mergeVectors(const std::vector<T>& input, std::vector<T>& changing) + { + for (typename std::vector<T>::const_iterator i = input.begin(); i != input.end(); ++i) //nested dependent typename: see Meyers effective C++ + changing.push_back(*i); + } } @@ -67,7 +112,7 @@ public: private: bool resultWasShown; - wxStopWatch timer; + std::auto_ptr<wxStopWatch> timer; }; //two macros for quick performance measurements @@ -106,7 +151,6 @@ public: wxString show() const { - return errorMessage; } @@ -115,32 +159,4 @@ private: }; -//Note: the following lines are a performance optimization for deleting elements from a vector. It is incredibly faster to create a new -//vector and leave specific elements out than to delete row by row and force recopying of most elements for each single deletion (linear vs quadratic runtime) -template <class T> -void removeRowsFromVector(std::vector<T>& grid, const std::set<int>& rowsToRemove) -{ - if (rowsToRemove.size() > 0) - { - std::vector<T> temp; - - std::set<int>::iterator rowToSkipIndex = rowsToRemove.begin(); - int rowToSkip = *rowToSkipIndex; - - for (int i = 0; i < int(grid.size()); ++i) - { - if (i != rowToSkip) - temp.push_back(grid[i]); - else - { - ++rowToSkipIndex; - if (rowToSkipIndex != rowsToRemove.end()) - rowToSkip = *rowToSkipIndex; - } - } - grid.swap(temp); - } -} - - #endif // GLOBALFUNCTIONS_H_INCLUDED |