src: refactored lib/utility

* removed unused utilityMath
* removed some unused functions from utility
* moved time related utility functions to TimeStamp
* moved path objects from utility to app/paths
* moved objects in lib to lib/app
* removed duplicate confirm methods in DialogView
* moved utilityFile to utility/file
* removed uint typedef and replaced with size_t everywhere
* removed boost header in utilityUuid
This commit is contained in:
Eberhard Graether
2019-07-17 15:10:05 +02:00
parent 70febae55b
commit 8e3ca182b9
92 changed files with 306 additions and 438 deletions
-18
View File
@@ -1,18 +0,0 @@
#include "AppPath.h"
FilePath AppPath::m_appPath(L"");
FilePath AppPath::getAppPath()
{
return m_appPath;
}
bool AppPath::setAppPath(const FilePath& path)
{
if(!path.empty())
{
m_appPath = path;
return true;
}
return false;
}
-16
View File
@@ -1,16 +0,0 @@
#ifndef APP_PATH_H
#define APP_PATH_H
#include "FilePath.h"
class AppPath
{
public:
static FilePath getAppPath();
static bool setAppPath(const FilePath& path);
private:
static FilePath m_appPath;
};
#endif // APP_PATH_H
-48
View File
@@ -1,48 +0,0 @@
#include "ResourcePaths.h"
#include "AppPath.h"
FilePath ResourcePaths::getColorSchemesPath()
{
return AppPath::getAppPath().concatenate(L"data/color_schemes/");
}
FilePath ResourcePaths::getSyntaxHighlightingRulesPath()
{
return AppPath::getAppPath().concatenate(L"data/syntax_highlighting_rules/");
}
FilePath ResourcePaths::getFallbackPath()
{
return AppPath::getAppPath().concatenate(L"data/fallback/");
}
FilePath ResourcePaths::getFontsPath()
{
return AppPath::getAppPath().concatenate(L"data/fonts/");
}
FilePath ResourcePaths::getGuiPath()
{
return AppPath::getAppPath().concatenate(L"data/gui/");
}
FilePath ResourcePaths::getLicensePath()
{
return AppPath::getAppPath().concatenate(L"data/license/");
}
FilePath ResourcePaths::getJavaPath()
{
return AppPath::getAppPath().concatenate(L"data/java/");
}
FilePath ResourcePaths::getPythonPath()
{
return AppPath::getAppPath().concatenate(L"data/python/");
}
FilePath ResourcePaths::getCxxCompilerHeaderPath()
{
return AppPath::getAppPath().concatenate(L"data/cxx/include/").getCanonical();
}
-22
View File
@@ -1,22 +0,0 @@
#ifndef RESOURCE_PATHS_H
#define RESOURCE_PATHS_H
#include <string>
#include "FilePath.h"
class ResourcePaths
{
public:
static FilePath getColorSchemesPath();
static FilePath getSyntaxHighlightingRulesPath();
static FilePath getFallbackPath();
static FilePath getFontsPath();
static FilePath getGuiPath();
static FilePath getLicensePath();
static FilePath getJavaPath();
static FilePath getPythonPath();
static FilePath getCxxCompilerHeaderPath();
};
#endif // RESOURCE_PATHS_H
+39
View File
@@ -5,6 +5,45 @@ TimeStamp TimeStamp::now()
return TimeStamp(boost::posix_time::microsec_clock::local_time());
}
double TimeStamp::durationSeconds(const TimeStamp& start)
{
return double(TimeStamp::now().deltaMS(start)) / 1000.0;
}
std::string TimeStamp::secondsToString(double secs)
{
std::stringstream ss;
int hours = int(secs / 3600);
secs -= hours * 3600;
int minutes = int(secs / 60);
secs -= minutes * 60;
int seconds = int(secs);
secs -= seconds;
int milliSeconds = secs * 1000;
if (hours > 9)
{
ss << hours;
}
else
{
ss << std::setw(2) << std::setfill('0') << hours;
}
ss << ":" << std::setw(2) << std::setfill('0') << minutes;
ss << ":" << std::setw(2) << std::setfill('0') << seconds;
if (!hours && !minutes)
{
ss << ":" << std::setw(3) << std::setfill('0') << milliSeconds;
}
return ss.str();
}
TimeStamp::TimeStamp()
: m_time(boost::posix_time::not_a_date_time)
{
+3
View File
@@ -8,6 +8,9 @@ class TimeStamp
public:
static TimeStamp now();
static double durationSeconds(const TimeStamp& start);
static std::string secondsToString(double seconds);
TimeStamp();
TimeStamp(boost::posix_time::ptime t);
TimeStamp(std::string s);
-28
View File
@@ -1,28 +0,0 @@
#include "UserPaths.h"
FilePath UserPaths::s_userDataPath;
FilePath UserPaths::getUserDataPath()
{
return s_userDataPath;
}
void UserPaths::setUserDataPath(const FilePath& path)
{
s_userDataPath = path;
}
FilePath UserPaths::getAppSettingsPath()
{
return getUserDataPath().concatenate(L"ApplicationSettings.xml");
}
FilePath UserPaths::getWindowSettingsPath()
{
return getUserDataPath().concatenate(L"window_settings.ini");
}
FilePath UserPaths::getLogPath()
{
return getUserDataPath().concatenate(L"log/");
}
-22
View File
@@ -1,22 +0,0 @@
#ifndef USER_PATHS_H
#define USER_PATHS_H
#include <string>
#include "FilePath.h"
class UserPaths
{
public:
static FilePath getUserDataPath();
static void setUserDataPath(const FilePath& path);
static FilePath getAppSettingsPath();
static FilePath getWindowSettingsPath();
static FilePath getLogPath();
private:
static FilePath s_userDataPath;
};
#endif // USER_PATHS_H
@@ -1,13 +1,14 @@
#include "CommandlineCommandConfig.h"
#include <functional>
#include <iostream>
#include <utility>
#include "ApplicationSettings.h"
#include "CommandlineHelper.h"
#include "CommandLineParser.h"
#include "FilePath.h"
#include "ApplicationSettings.h"
#include "logging.h"
namespace commandline {
@@ -1,5 +1,7 @@
#include "CommandlineCommandIndex.h"
#include <iostream>
#include "CommandlineHelper.h"
#include "CommandLineParser.h"
@@ -3,6 +3,7 @@
#include "FilePath.h"
#include "FileSystem.h"
#include "logging.h"
#include "utility.h"
std::vector<FilePath> utility::partitionFilePathsBySize(std::vector<FilePath> filePaths, int partitionCount)
@@ -16,6 +16,7 @@ namespace utility
FilePath getExpandedPath(const FilePath& path);
std::vector<FilePath> getExpandedPaths(const std::vector<FilePath>& paths);
FilePath getExpandedAndAbsolutePath(const FilePath& path, const FilePath& baseDirectory);
FilePath getAsRelativeIfShorter(const FilePath& absolutePath, const FilePath& baseDirectory);
std::vector<FilePath> getAsRelativeIfShorter(const std::vector<FilePath>& absolutePaths, const FilePath& baseDirectory);
}
@@ -4,7 +4,7 @@
#include "logging.h"
#include "TimeStamp.h"
#include "utility.h"
#include "utilityApp.h"
std::string SharedMemoryGarbageCollector::s_memoryNamePrefix = "grbg_cllctr_";
std::string SharedMemoryGarbageCollector::s_instancesKeyName = "running_instances";
+2 -2
View File
@@ -4,9 +4,9 @@
#include "logging.h"
#include "MessageStatus.h"
#include "utility.h"
#include "Version.h"
#include "utilityApp.h"
#include "utilityString.h"
#include "Version.h"
std::shared_ptr<LogManager> LogManager::getInstance()
{
@@ -2,14 +2,15 @@
#include "tinyxml.h"
#include "IndexerCommandCxx.h"
#include "ApplicationSettings.h"
#include "SourceGroupSettingsCxxSonargraph.h"
#include "IndexerCommandCxx.h"
#include "FileSystem.h"
#include "logging.h"
#include "SonargraphSoftwareSystem.h"
#include "utilitySonargraph.h"
#include "SourceGroupSettingsCxxSonargraph.h"
#include "utility.h"
#include "utilityFile.h"
#include "utilitySonargraph.h"
#include "utilityXml.h"
namespace Sonargraph
@@ -2,16 +2,17 @@
#include "tinyxml.h"
#include "FileSystem.h"
#include "IndexerCommandJava.h"
#include "LanguageType.h"
#include "SourceGroupSettingsJavaSonargraph.h"
#include "FileSystem.h"
#include "SonargraphSoftwareSystem.h"
#include "logging.h"
#include "SonargraphSourceRootPath.h"
#include "SonargraphSoftwareSystem.h"
#include "SonargraphXsdRootPath.h"
#include "utilitySonargraph.h"
#include "SourceGroupSettingsJavaSonargraph.h"
#include "utility.h"
#include "utilityFile.h"
#include "utilitySonargraph.h"
#include "utilityXml.h"
namespace Sonargraph
+8 -7
View File
@@ -10,9 +10,10 @@
#include <stack>
#include <thread>
#include "FilePath.h"
#include "TimeStamp.h"
#include "types.h"
#include "utility.h"
#include "utilityString.h"
struct TraceEvent
{
@@ -21,7 +22,7 @@ public:
: eventName("")
, id(0)
, depth(0)
, time(0.0f)
, time(0.0)
{
}
@@ -29,7 +30,7 @@ public:
: eventName(eventName)
, id(id)
, depth(depth)
, time(0.0f)
, time(0.0)
{
}
@@ -40,7 +41,7 @@ public:
std::string functionName;
std::string locationName;
float time;
double time;
};
@@ -84,7 +85,7 @@ private:
{
TraceEvent event;
size_t count;
float time;
double time;
};
static std::shared_ptr<AccumulatingTracer> s_instance;
@@ -121,13 +122,13 @@ ScopedTrace<TracerType>::ScopedTrace(
m_event->functionName = functionName;
m_event->locationName = utility::encodeToUtf8(FilePath(fileName).fileName()) + ":" + std::to_string(lineNumber);
m_timeStamp = utility::durationStart();
m_timeStamp = TimeStamp::now();
}
template <typename TracerType>
ScopedTrace<TracerType>::~ScopedTrace()
{
m_event->time = utility::duration(m_timeStamp);
m_event->time = TimeStamp::durationSeconds(m_timeStamp);
TracerType::getInstance()->finishEvent(m_event);
}
-2
View File
@@ -5,6 +5,4 @@
typedef size_t Id;
typedef unsigned int uint;
#endif // TYPES_H
-107
View File
@@ -1,107 +1,5 @@
#include "utility.h"
#include <iomanip>
#include <sstream>
#include <boost/date_time/time_clock.hpp>
ApplicationArchitectureType utility::getApplicationArchitectureType()
{
#if defined(__x86_64) || defined(__x86_64__) || defined(__amd64) || defined(_M_X64) || defined(WIN64)
return APPLICATION_ARCHITECTURE_X86_64;
#else
return APPLICATION_ARCHITECTURE_X86_32;
#endif
return APPLICATION_ARCHITECTURE_UNKNOWN;
}
TimeStamp utility::durationStart()
{
return TimeStamp::now();
}
float utility::duration(const TimeStamp& start)
{
TimeStamp now = durationStart();
return float(now.deltaMS(start)) / 1000.0f;
}
float utility::duration(std::function<void()> func)
{
const TimeStamp start = durationStart();
func();
return duration(start);
}
std::string utility::timeToString(const time_t time)
{
char buff[20];
strftime(buff, 20, "%Y-%m-%d %H:%M:%S", localtime(&time));
return std::string(buff);
}
std::string utility::timeToString(const boost::posix_time::ptime time)
{
return TimeStamp(time).toString();
}
std::string utility::timeToString(float secondsTotal)
{
std::stringstream ss;
int hours = int(secondsTotal / 3600);
secondsTotal -= hours * 3600;
int minutes = int(secondsTotal / 60);
secondsTotal -= minutes * 60;
int seconds = int(secondsTotal);
secondsTotal -= seconds;
int milliSeconds = secondsTotal * 1000;
if (hours > 9)
{
ss << hours;
}
else
{
ss << std::setw(2) << std::setfill('0') << hours;
}
ss << ":" << std::setw(2) << std::setfill('0') << minutes;
ss << ":" << std::setw(2) << std::setfill('0') << seconds;
if (!hours && !minutes)
{
ss << ":" << std::setw(3) << std::setfill('0') << milliSeconds;
}
return ss.str();
}
bool utility::intersectionPoint(Vec2f a1, Vec2f b1, Vec2f a2, Vec2f b2, Vec2f* i)
{
Vec2f p = a1;
Vec2f v = b1 - a1;
Vec2f q = a2;
Vec2f w = b2 - a2;
float denominator = v.x * w.y - v.y * w.x;
if (denominator != 0)
{
float t = (p.y * w.x - p.x * w.y + q.x * w.y - q.y * w.x) / denominator;
float s = (q.y * v.x - q.x * v.y + p.x * v.y - p.y * v.x) / -denominator;
if (t >= 0 && t <= 1 && s >= 0 && s <= 1)
{
*i = p + v * t;
return true;
}
}
return false;
}
size_t utility::digits(size_t n)
{
int digits = 1;
@@ -114,8 +12,3 @@ size_t utility::digits(size_t n)
return digits;
}
int utility::roundToInt(float n)
{
return (n > 0.0f) ? (n + 0.5f) : (n - 0.5f);
}
+9 -24
View File
@@ -5,29 +5,16 @@
#include <cstdarg>
#include <deque>
#include <functional>
#include <map>
#include <set>
#include <time.h>
#include <vector>
#include <unordered_set>
#include <boost/date_time/posix_time/posix_time.hpp>
#include "ApplicationArchitectureType.h"
#include "FilePath.h"
#include "Vector2.h"
#include "TimeStamp.h"
#include "utilityString.h"
namespace utility
{
TimeStamp durationStart();
float duration(const TimeStamp& start);
float duration(std::function<void()> func);
std::string timeToString(const time_t time);
std::string timeToString(const boost::posix_time::ptime time);
std::string timeToString(float seconds);
template<typename T>
std::vector<std::vector<T>> splitToEqualySizedParts(const std::vector<T>& values, const size_t desiredPartCount);
@@ -74,13 +61,15 @@ namespace utility
std::vector<T> createVectorFromElements(const Args&... args);
template<typename SourceType, typename TargetType>
std::vector<TargetType> convert(const std::vector<SourceType>& sourceContainer, std::function<TargetType(const SourceType&)> conversion);
std::vector<TargetType> convert(
const std::vector<SourceType>& sourceContainer, std::function<TargetType(const SourceType&)> conversion);
template<typename SourceType, typename TargetType>
std::vector<TargetType> convert(const std::vector<SourceType>& sourceContainer);
template<typename SourceType, typename TargetType>
std::set<TargetType> convert(const std::set<SourceType>& sourceContainer, std::function<TargetType(const SourceType&)> conversion);
std::set<TargetType> convert(
const std::set<SourceType>& sourceContainer, std::function<TargetType(const SourceType&)> conversion);
template<typename SourceType, typename TargetType>
std::set<TargetType> convert(const std::set<SourceType>& sourceContainer);
@@ -134,13 +123,7 @@ namespace utility
return false;
}
ApplicationArchitectureType getApplicationArchitectureType();
bool intersectionPoint(Vec2f a1, Vec2f b1, Vec2f a2, Vec2f b2, Vec2f* i);
size_t digits(size_t n);
int roundToInt(float n);
}
template<typename T>
@@ -286,7 +269,8 @@ std::vector<T> utility::createVectorFromElements(const Args&... args)
}
template<typename SourceType, typename TargetType>
std::vector<TargetType> utility::convert(const std::vector<SourceType>& sourceContainer, std::function<TargetType(const SourceType&)> conversion)
std::vector<TargetType> utility::convert(
const std::vector<SourceType>& sourceContainer, std::function<TargetType(const SourceType&)> conversion)
{
std::vector<TargetType> targetContainer;
targetContainer.reserve(sourceContainer.size());
@@ -310,7 +294,8 @@ std::vector<TargetType> utility::convert(const std::vector<SourceType>& sourceCo
}
template<typename SourceType, typename TargetType>
std::set<TargetType> utility::convert(const std::set<SourceType>& sourceContainer, std::function<TargetType(const SourceType&)> conversion)
std::set<TargetType> utility::convert(
const std::set<SourceType>& sourceContainer, std::function<TargetType(const SourceType&)> conversion)
{
std::set<TargetType> targetContainer;
for (const SourceType& sourceElement : sourceContainer)
-13
View File
@@ -1,13 +0,0 @@
#include "utilityMath.h"
unsigned long int utility::getPowerOfTwo(unsigned int exponent)
{
static const long int powerOfTwos[] =
{
1 << 0, 1 << 1, 1 << 2, 1 << 3, 1 << 4, 1 << 5, 1 << 6, 1 << 7,
1 << 8, 1 << 9, 1 << 10, 1 << 11, 1 << 12, 1 << 13, 1 << 14, 1 << 15,
1 << 16, 1 << 17, 1 << 18, 1 << 19, 1 << 20, 1 << 21, 1 << 22, 1 << 23,
1 << 24, 1 << 25, 1 << 26, 1 << 27, 1 << 28, 1 << 29, 1 << 30, 1 << 31
};
return powerOfTwos[exponent];
}
-9
View File
@@ -1,9 +0,0 @@
#ifndef UTILITY_MATH_H
#define UTILITY_MATH_H
namespace utility
{
unsigned long int getPowerOfTwo(unsigned int exponent);
}
#endif // UTILITY_MATH_H
+14 -10
View File
@@ -1,20 +1,24 @@
#include "utilityUuid.h"
#include <boost/lexical_cast.hpp>
#include <boost/uuid/uuid.hpp>
#include <boost/uuid/uuid_generators.hpp>
#include <boost/uuid/uuid_io.hpp>
boost::uuids::uuid utility::getUuid()
namespace utility
{
return boost::uuids::random_generator()();
}
boost::uuids::uuid getUuid()
{
return boost::uuids::random_generator()();
}
std::string utility::uuidToString(const boost::uuids::uuid& uuid)
{
return boost::lexical_cast<std::string>(uuid);
}
std::string uuidToString(const boost::uuids::uuid& uuid)
{
return boost::lexical_cast<std::string>(uuid);
}
std::string utility::getUuidString()
{
return utility::uuidToString(utility::getUuid());
std::string getUuidString()
{
return utility::uuidToString(utility::getUuid());
}
}
+4 -3
View File
@@ -1,13 +1,14 @@
#ifndef UTILITY_UUID_H
#define UTILITY_UUID_H
#include <boost/uuid/uuid.hpp>
#include <string>
// #include <boost/uuid/uuid.hpp>
namespace utility
{
boost::uuids::uuid getUuid();
std::string uuidToString(const boost::uuids::uuid& uuid);
// boost::uuids::uuid getUuid();
// std::string uuidToString(const boost::uuids::uuid& uuid);
std::string getUuidString();
}