From fbe76102e941b9f1edaf236788e42678f05fdf9a Mon Sep 17 00:00:00 2001 From: Daniel Wilhelm Date: Fri, 18 Apr 2014 17:08:06 +0200 Subject: 3.9 --- shared/globalFunctions.h | 239 ----------------------------------------------- 1 file changed, 239 deletions(-) delete mode 100644 shared/globalFunctions.h (limited to 'shared/globalFunctions.h') diff --git a/shared/globalFunctions.h b/shared/globalFunctions.h deleted file mode 100644 index fe65889f..00000000 --- a/shared/globalFunctions.h +++ /dev/null @@ -1,239 +0,0 @@ -// ************************************************************************** -// * 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-2010 ZenJu (zhnmju123 AT gmx.de) * -// ************************************************************************** -// -#ifndef GLOBALFUNCTIONS_H_INCLUDED -#define GLOBALFUNCTIONS_H_INCLUDED - -#include -#include -#include -#include -#include -#include -#include -#include - -class wxStopWatch; - - -namespace globalFunctions -{ -//------------------------------------------------ -// FUNCTIONS -//------------------------------------------------ -inline -int round(double d) //little rounding function -{ - return static_cast(d < 0 ? d - .5 : d + .5); -} - -template -inline -T abs(const T& d) //absolute value -{ - return(d < 0 ? -d : d); -} - - -//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); - - -size_t getDigitCount(size_t number); //count number of digits - -//serialization: read/write numbers: int, long, unsigned int ... ect -template T readNumber(std::istream& stream); -template 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 -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 Performance -{ -public: - wxDEPRECATED(Performance()); //generate compiler warnings as a reminder to remove code after measurements - ~Performance(); - void showResult(); - -private: - bool resultWasShown; - std::auto_ptr timer; -}; - -//two macros for quick performance measurements -#define PERF_START Performance a; -#define PERF_STOP a.showResult(); - - -//############################################################################ -class wxFile; -class DebugLog -{ -public: - wxDEPRECATED(DebugLog()); - ~DebugLog(); - void write(const wxString& logText); - -private: - wxString assembleFileName(); - wxString logfileName; - int lineCount; - wxFile* logFile; //logFile.close(); <- not needed -}; -extern DebugLog logDebugInfo; -wxString getCodeLocation(const wxString file, const 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--------------------------------------------------- -template -inline -std::basic_string globalFunctions::numberToString(const T& number) //convert number to string the C++ way -{ - std::basic_ostringstream ss; - ss << number; - return ss.str(); -} - - -template -inline -T globalFunctions::stringToNumber(const std::basic_string& input) //convert number to string the C++ way -{ - 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); -} - - -//Note: the following lines are a performance optimization for deleting elements from a vector: linear runtime at most! -template -void globalFunctions::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 globalFunctions::custom_binary_search(ForwardIterator first, ForwardIterator last, const T& value, Compare comp) -{ - first = lower_bound(first, last, value, comp); - if (first != last && !comp(value, *first)) - return first; - else - return last; -} - - -template -inline -T globalFunctions::readNumber(std::istream& stream) -{ - T result = 0; - stream.read(reinterpret_cast(&result), sizeof(T)); - return result; -} - - -template -inline -void globalFunctions::writeNumber(std::ostream& stream, T number) -{ - stream.write(reinterpret_cast(&number), sizeof(T)); -} - - -#endif // GLOBALFUNCTIONS_H_INCLUDED -- cgit