// ************************************************************************** // * This file is part of the FreeFileSync project. It is distributed under * // * GNU General Public License: http://www.gnu.org/licenses/gpl.html * // * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * // ************************************************************************** // #ifndef GLOBALFUNCTIONS_H_INCLUDED #define GLOBALFUNCTIONS_H_INCLUDED #include #include #include #include #include //#include //#include namespace common { //little rounding function inline int round(double d) { return static_cast(d < 0 ? d - 0.5 : d + 0.5); } //absolute value template inline T abs(const T& d) { return d < 0 ? -d : d; } size_t getDigitCount(size_t number); //count number of digits //Note: the following lines are a performance optimization for deleting elements from a vector: linear runtime at most! template void removeRowsFromVector(const std::set& rowsToRemove, std::vector& grid); //enhanced binary search template: returns an iterator template ForwardIterator custom_binary_search(ForwardIterator first, ForwardIterator last, const T& value, Compare comp = std::less()); } //############################################################################ class wxFile; class DebugLog { public: wxDEPRECATED(DebugLog(const wxString& filePrefix = wxString())); ~DebugLog(); void write(const wxString& logText); private: wxString assembleFileName(); wxString logfileName; wxString prefix; int lineCount; wxFile* logFile; //logFile.close(); <- not needed }; extern DebugLog logDebugInfo; wxString getCodeLocation(const wxString& file, int line); //small macro for writing debug information into a logfile #define WRITE_DEBUG_LOG(x) logDebugInfo.write(getCodeLocation(__TFILE__, __LINE__) + x); //speed alternative: wxLogDebug(wxT("text")) + DebugView //---------------Inline Implementation--------------------------------------------------- //Note: the following lines are a performance optimization for deleting elements from a vector: linear runtime at most! template void common::removeRowsFromVector(const std::set& rowsToRemove, std::vector& grid) { if (rowsToRemove.empty()) return; std::set::const_iterator rowToSkipIndex = rowsToRemove.begin(); size_t rowToSkip = *rowToSkipIndex; if (rowToSkip >= grid.size()) return; typename std::vector::iterator insertPos = grid.begin() + rowToSkip; for (size_t i = rowToSkip; i < grid.size(); ++i) { if (i != rowToSkip) { *insertPos = grid[i]; ++insertPos; } else { ++rowToSkipIndex; if (rowToSkipIndex != rowsToRemove.end()) rowToSkip = *rowToSkipIndex; } } grid.erase(insertPos, grid.end()); } //enhanced binary search template: returns an iterator template inline ForwardIterator common::custom_binary_search(ForwardIterator first, ForwardIterator last, const T& value, Compare comp) { first = std::lower_bound(first, last, value, comp); if (first != last && !comp(value, *first)) return first; else return last; } #endif // GLOBALFUNCTIONS_H_INCLUDED