From 6b8be12de4e16b51bead4811897fce2812d03ca5 Mon Sep 17 00:00:00 2001
From: Moritz Maxeiner <mm@ucw.sh>
Date: Tue, 19 Nov 2019 20:51:03 +0100
Subject: [PATCH] misc

---
 .clang-format                      | 121 +++++++
 .gitignore                         |   3 +-
 .style.yapf                        |  52 ---
 licence.txt => LICENSE             |   0
 SrcBehaviorLoader/PluginLoader.cpp | 519 ++++++++++++++---------------
 SrcBehaviorLoader/PluginLoader.h   | 156 ++++-----
 6 files changed, 456 insertions(+), 395 deletions(-)
 create mode 100644 .clang-format
 delete mode 100644 .style.yapf
 rename licence.txt => LICENSE (100%)

diff --git a/.clang-format b/.clang-format
new file mode 100644
index 0000000..5518241
--- /dev/null
+++ b/.clang-format
@@ -0,0 +1,121 @@
+---
+Language:        Cpp
+TabWidth:        3
+IndentWidth:     3
+AccessModifierOffset: -3
+ConstructorInitializerIndentWidth: 0
+ContinuationIndentWidth: 3
+ColumnLimit:     79
+BinPackArguments: false
+BinPackParameters: false
+AlignAfterOpenBracket: Align
+AlignConsecutiveAssignments: true
+AlignConsecutiveDeclarations: true
+AlignOperands:   true
+AlignEscapedNewlines: Right
+AlignTrailingComments: true
+PenaltyBreakAssignment: 100
+PenaltyBreakBeforeFirstCallParameter: 19
+PenaltyBreakComment: 300
+PenaltyBreakFirstLessLess: 120
+PenaltyBreakString: 1000
+PenaltyBreakTemplateDeclaration: 10
+PenaltyExcessCharacter: 1000000
+PenaltyReturnTypeOnItsOwnLine: 1000
+AllowAllArgumentsOnNextLine: false # clang-format >= 9
+AllowAllConstructorInitializersOnNextLine: false # clang-format >= 9
+AllowAllParametersOfDeclarationOnNextLine: false
+AllowShortBlocksOnASingleLine: false
+AllowShortCaseLabelsOnASingleLine: false
+AllowShortFunctionsOnASingleLine: All
+AllowShortIfStatementsOnASingleLine: false
+AllowShortLoopsOnASingleLine: false
+AlwaysBreakAfterDefinitionReturnType: None
+AlwaysBreakAfterReturnType: None
+AlwaysBreakBeforeMultilineStrings: false
+AlwaysBreakTemplateDeclarations: true
+BreakBeforeBraces: Custom
+BraceWrapping:
+  AfterClass:      true
+  AfterControlStatement: false
+  AfterEnum:       false
+  AfterFunction:   true
+  AfterNamespace:  true
+  AfterObjCDeclaration: false
+  AfterStruct:     true
+  AfterUnion:      false
+  AfterExternBlock: false
+  BeforeCatch:     false
+  BeforeElse:      false
+  IndentBraces:    false
+  SplitEmptyFunction: true
+  SplitEmptyRecord: true
+  SplitEmptyNamespace: true
+BreakBeforeBinaryOperators: None
+BreakBeforeInheritanceComma: false
+BreakInheritanceList: BeforeColon
+BreakBeforeTernaryOperators: true
+BreakConstructorInitializers: BeforeComma
+BreakAfterJavaFieldAnnotations: false
+BreakStringLiterals: true
+CommentPragmas:  '^ IWYU pragma:'
+CompactNamespaces: false
+ConstructorInitializerAllOnOneLineOrOnePerLine: false
+Cpp11BracedListStyle: true
+DerivePointerAlignment: false
+DisableFormat:   false
+ExperimentalAutoDetectBinPacking: false
+FixNamespaceComments: false
+ForEachMacros:
+  - foreach
+  - Q_FOREACH
+  - BOOST_FOREACH
+IncludeBlocks:   Preserve
+IncludeCategories:
+  - Regex:           '^"(llvm|llvm-c|clang|clang-c)/'
+    Priority:        2
+  - Regex:           '^(<|"(gtest|gmock|isl|json)/)'
+    Priority:        3
+  - Regex:           '.*'
+    Priority:        1
+IncludeIsMainRegex: '(Test)?$'
+IndentCaseLabels: false
+IndentPPDirectives: None
+IndentWrappedFunctionNames: false
+JavaScriptQuotes: Leave
+JavaScriptWrapImports: true
+KeepEmptyLinesAtTheStartOfBlocks: true
+MacroBlockBegin: ''
+MacroBlockEnd:   ''
+MaxEmptyLinesToKeep: 1
+NamespaceIndentation: All
+ObjCBinPackProtocolList: Auto
+ObjCBlockIndentWidth: 2
+ObjCSpaceAfterProperty: false
+ObjCSpaceBeforeProtocolList: true
+PointerAlignment: Left
+ReflowComments:  true
+SortIncludes:    false
+SortUsingDeclarations: true
+SpaceAfterCStyleCast: true
+SpaceAfterTemplateKeyword: false
+SpaceBeforeAssignmentOperators: true
+SpaceBeforeCpp11BracedList: false
+SpaceBeforeCtorInitializerColon: true
+SpaceBeforeInheritanceColon: true
+SpaceBeforeParens: ControlStatements
+SpaceBeforeRangeBasedForLoopColon: true
+SpaceInEmptyParentheses: false
+SpacesBeforeTrailingComments: 1
+SpacesInAngles:  false
+SpacesInContainerLiterals: false
+SpacesInCStyleCastParentheses: false
+SpacesInParentheses: false
+SpacesInSquareBrackets: false
+Standard:        Cpp11
+StatementMacros:
+  - Q_UNUSED
+  - QT_REQUIRE_VERSION
+UseTab:          ForIndentation
+...
+
diff --git a/.gitignore b/.gitignore
index c795b05..5acb669 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,2 @@
-build
\ No newline at end of file
+build
+.vscode
diff --git a/.style.yapf b/.style.yapf
deleted file mode 100644
index 104ea26..0000000
--- a/.style.yapf
+++ /dev/null
@@ -1,52 +0,0 @@
-[style]
-align_closing_bracket_with_visual_indent = true
-allow_multiline_lambdas = false
-allow_multiline_dictionary_keys = false
-allow_split_before_default_or_named_assigns = true
-allow_split_before_dict_value = true
-arithmetic_precedence_indication = false
-blank_line_before_nested_class_or_def = false
-blank_line_before_class_docstring = false
-blank_line_before_module_docstring = false
-blank_lines_around_top_level_definition = 2
-coalesce_brackets = false
-column_limit = 99
-continuation_align_style = 'space'
-continuation_indent_width = 4
-dedent_closing_brackets = true
-disable_ending_comma_heuristic = false
-each_dict_entry_on_separate_line = true
-i18n_comment = ''
-i18n_function_call = ''
-indent_dictionary_value = true
-indent_width = 4
-indent_blank_lines = false
-join_multiple_lines = true
-no_spaces_around_selected_binary_operators = set()
-space_between_ending_comma_and_closing_bracket = true
-spaces_around_power_operator = true
-spaces_around_default_or_named_assign = false
-spaces_before_comment = 2
-split_arguments_when_comma_terminated = false
-split_all_comma_separated_values = true
-split_before_arithmetic_operator = true
-split_before_bitwise_operator = true
-split_before_closing_bracket = true
-split_before_dict_set_generator = true
-split_before_dot = true
-split_before_expression_after_opening_paren = true
-split_before_first_argument = false
-split_before_logical_operator = true
-split_before_named_assigns = true
-split_complex_comprehension = true
-split_penalty_after_opening_bracket = 300
-split_penalty_after_unary_operator = 10000
-split_penalty_arithmetic_operator = 300
-split_penalty_before_if_expr = 0
-split_penalty_bitwise_operator = 300
-split_penalty_comprehension = 80
-split_penalty_excess_character = 7000
-split_penalty_for_added_line_split = 30
-split_penalty_import_names = 0
-split_penalty_logical_operator = 300
-use_tabs = false
diff --git a/licence.txt b/LICENSE
similarity index 100%
rename from licence.txt
rename to LICENSE
diff --git a/SrcBehaviorLoader/PluginLoader.cpp b/SrcBehaviorLoader/PluginLoader.cpp
index b0dd853..b8bbdc1 100644
--- a/SrcBehaviorLoader/PluginLoader.cpp
+++ b/SrcBehaviorLoader/PluginLoader.cpp
@@ -14,333 +14,320 @@
 #define MAX_KEY_LENGTH 255
 #define MAX_VALUE_NAME 16383
 
-std::vector<std::string> QueryKey(HKEY hKey, std::string path) 
+std::vector<std::string> QueryKey(HKEY hKey, std::string path)
 {
-    //See https://docs.microsoft.com/en-us/windows/desktop/sysinfo/enumerating-registry-subkeys
-    std::vector<std::string> list;
-    TCHAR    achClass[MAX_PATH] = TEXT("");  // buffer for class name 
-    DWORD    cchClassName = MAX_PATH;  // size of class string 
-    DWORD    cSubKeys=0;               // number of subkeys 
-    DWORD    cbMaxSubKey;              // longest subkey size 
-    DWORD    cchMaxClass;              // longest class string 
-    DWORD    cValues;              // number of values for key 
-    DWORD    cchMaxValue;          // longest value name 
-    DWORD    cbMaxValueData;       // longest value data 
-    DWORD    cbSecurityDescriptor; // size of security descriptor 
-    FILETIME ftLastWriteTime;      // last write time 
-
-    DWORD i, retCode;
-
-    TCHAR  achValue[MAX_VALUE_NAME]; 
-    DWORD cchValue = MAX_VALUE_NAME; 
-
-    // Get the class name and the value count. 
-    retCode = RegQueryInfoKey(
-        hKey,                    // key handle 
-        achClass,                // buffer for class name 
-        &cchClassName,           // size of class string 
-        NULL,                    // reserved 
-        &cSubKeys,               // number of subkeys 
-        &cbMaxSubKey,            // longest subkey size 
-        &cchMaxClass,            // longest class string 
-        &cValues,                // number of values for this key 
-        &cchMaxValue,            // longest value name 
-        &cbMaxValueData,         // longest value data 
-        &cbSecurityDescriptor,   // security descriptor 
-        &ftLastWriteTime);       // last write time 
- 
-    // Enumerate the key values. 
-    if (cValues) 
-    {
-           //printf( "\nNumber of values: %d\n", cValues);
-
-        for (i=0, retCode=ERROR_SUCCESS; i<cValues; i++) 
-        { 
-            cchValue = MAX_VALUE_NAME; 
-            achValue[0] = '\0'; 
-            retCode = RegEnumValue(hKey, i, 
-                achValue, 
-                &cchValue, 
-                NULL, 
-                NULL,
-                NULL,
-                NULL);
- 
-            if (retCode == ERROR_SUCCESS ) 
-            { 
-                CRegKey regKey;
-                CHAR szBuffer[512];
-                ULONG dwBufferSize = sizeof(szBuffer);
-
-                if(auto error_code = regKey.Open(HKEY_LOCAL_MACHINE, path.c_str(), KEY_READ); error_code != ERROR_SUCCESS)
-                {
-                    qWarning() << "Error opening windows registry path " << path.c_str() << ": " << error_code;
-                    regKey.Close();
-                    continue;
-                }
-                if(auto error_code = regKey.QueryStringValue(achValue,szBuffer,&dwBufferSize); error_code != ERROR_SUCCESS)
-                {
-                    qWarning() << "Error opening windows registry value " << achValue << ": " << error_code;
-                    regKey.Close();
-                    continue;
-                }
-
-                std::string fp = szBuffer;
-                std::replace( fp.begin(), fp.end(), '\\', '/');
-                list.push_back(fp);
-            } 
-        }
-    }
-    return list;
+	// See
+	// https://docs.microsoft.com/en-us/windows/desktop/sysinfo/enumerating-registry-subkeys
+	std::vector<std::string> list;
+	TCHAR    achClass[MAX_PATH] = TEXT(""); // buffer for class name
+	DWORD    cchClassName       = MAX_PATH; // size of class string
+	DWORD    cSubKeys           = 0;        // number of subkeys
+	DWORD    cbMaxSubKey;                   // longest subkey size
+	DWORD    cchMaxClass;                   // longest class string
+	DWORD    cValues;                       // number of values for key
+	DWORD    cchMaxValue;                   // longest value name
+	DWORD    cbMaxValueData;                // longest value data
+	DWORD    cbSecurityDescriptor;          // size of security descriptor
+	FILETIME ftLastWriteTime;               // last write time
+
+	DWORD i, retCode;
+
+	TCHAR achValue[MAX_VALUE_NAME];
+	DWORD cchValue = MAX_VALUE_NAME;
+
+	// Get the class name and the value count.
+	retCode = RegQueryInfoKey(hKey,            // key handle
+	                          achClass,        // buffer for class name
+	                          &cchClassName,   // size of class string
+	                          NULL,            // reserved
+	                          &cSubKeys,       // number of subkeys
+	                          &cbMaxSubKey,    // longest subkey size
+	                          &cchMaxClass,    // longest class string
+	                          &cValues,        // number of values for this key
+	                          &cchMaxValue,    // longest value name
+	                          &cbMaxValueData, // longest value data
+	                          &cbSecurityDescriptor, // security descriptor
+	                          &ftLastWriteTime);     // last write time
+
+	// Enumerate the key values.
+	if (cValues) {
+		// printf( "\nNumber of values: %d\n", cValues);
+
+		for (i = 0, retCode = ERROR_SUCCESS; i < cValues; i++) {
+			cchValue    = MAX_VALUE_NAME;
+			achValue[0] = '\0';
+			retCode =
+			   RegEnumValue(hKey, i, achValue, &cchValue, NULL, NULL, NULL, NULL);
+
+			if (retCode == ERROR_SUCCESS) {
+				CRegKey regKey;
+				CHAR    szBuffer[512];
+				ULONG   dwBufferSize = sizeof(szBuffer);
+
+				if (auto error_code = regKey.Open(HKEY_LOCAL_MACHINE,
+				                                  path.c_str(),
+				                                  KEY_READ);
+				    error_code != ERROR_SUCCESS) {
+					qWarning() << "Error opening windows registry path "
+					           << path.c_str() << ": " << error_code;
+					regKey.Close();
+					continue;
+				}
+				if (auto error_code = regKey.QueryStringValue(achValue,
+				                                              szBuffer,
+				                                              &dwBufferSize);
+				    error_code != ERROR_SUCCESS) {
+					qWarning() << "Error opening windows registry value "
+					           << achValue << ": " << error_code;
+					regKey.Close();
+					continue;
+				}
+
+				std::string fp = szBuffer;
+				std::replace(fp.begin(), fp.end(), '\\', '/');
+				list.push_back(fp);
+			}
+		}
+	}
+	return list;
 }
 #endif
 
 std::vector<std::string> PluginLoader::queryRegistryBehaviors(std::string path)
 {
-    std::vector<std::string> list;
-    
-    #ifdef _WIN32
-    HKEY hTestKey;
-
-    if( RegOpenKeyEx( HKEY_LOCAL_MACHINE,
-        TEXT(path.c_str()),
-        0,
-        KEY_READ,
-        &hTestKey) == ERROR_SUCCESS)
-    {
-        list = QueryKey(hTestKey, path);
-    }
-
-    RegCloseKey(hTestKey);
-    #endif
-
-    return list;
+	std::vector<std::string> list;
+
+#ifdef _WIN32
+	HKEY hTestKey;
+
+	if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
+	                 TEXT(path.c_str()),
+	                 0,
+	                 KEY_READ,
+	                 &hTestKey) == ERROR_SUCCESS) {
+		list = QueryKey(hTestKey, path);
+	}
+
+	RegCloseKey(hTestKey);
+#endif
+
+	return list;
 }
 
 #ifdef _WIN32
-const char * WinGetEnv(const char * name)
+const char* WinGetEnv(const char* name)
 {
-    const DWORD buffSize = 65535;
-    static char buffer[buffSize];
-    if (GetEnvironmentVariableA(name, buffer, buffSize))
-    {
-        return buffer;
-    }
-    else
-    {
-        return 0;
-    }
+	const DWORD buffSize = 65535;
+	static char buffer[buffSize];
+	if (GetEnvironmentVariableA(name, buffer, buffSize)) {
+		return buffer;
+	} else {
+		return 0;
+	}
 }
-bool WinSetEnv(const char* name, const char* toWhat){
-    return SetEnvironmentVariableA(name, toWhat);
+bool WinSetEnv(const char* name, const char* toWhat)
+{
+	return SetEnvironmentVariableA(name, toWhat);
 }
 #endif
 
 bool is_shared_library(std::filesystem::path const& p)
 {
-       auto extension = p.extension();
-       return extension == ".so" || extension == ".dylib" || extension == ".dll";
+	auto extension = p.extension();
+	return extension == ".so" || extension == ".dylib" || extension == ".dll";
 }
 
 const char* PluginLoader::addDllPath(std::string f)
 {
-    //Get the directory of the DLL/*.so and add it to the PATH env variable.
-    //This way dependencies can be shipped in the same directory
-    #ifdef _WIN32
-        QFileInfo finf(f.c_str());
-        //rather than the buggy _getenv: https://docs.microsoft.com/de-de/windows/desktop/api/winbase/nf-winbase-getenvironmentvariable
-        auto old_path = WinGetEnv("PATH");
-        auto path = std::ostringstream();
-        if(old_path){
-            path << old_path << ";" << finf.absolutePath().toStdString().c_str();
-            WinSetEnv("PATH", path.str().c_str());
-        }else{
-            qWarning() << "Failed to get and modify PATH enviromental variable.";
-        }
-        return old_path;
-    #endif
-    
-    return "";
+// Get the directory of the DLL/*.so and add it to the PATH env variable.
+// This way dependencies can be shipped in the same directory
+#ifdef _WIN32
+	QFileInfo finf(f.c_str());
+	// rather than the buggy _getenv:
+	// https://docs.microsoft.com/de-de/windows/desktop/api/winbase/nf-winbase-getenvironmentvariable
+	auto old_path = WinGetEnv("PATH");
+	auto path     = std::ostringstream();
+	if (old_path) {
+		path << old_path << ";" << finf.absolutePath().toStdString().c_str();
+		WinSetEnv("PATH", path.str().c_str());
+	} else {
+		qWarning() << "Failed to get and modify PATH enviromental variable.";
+	}
+	return old_path;
+#endif
+
+	return "";
 }
 
-void PluginLoader::delDllPath(const char* oldPath){
-    //reset path. We don't want some weird cross-effects
-    #ifdef _WIN32
-        if(oldPath){
-            WinSetEnv("PATH", oldPath);
-        }
-    #endif
+void PluginLoader::delDllPath(const char* oldPath)
+{
+// reset path. We don't want some weird cross-effects
+#ifdef _WIN32
+	if (oldPath) {
+		WinSetEnv("PATH", oldPath);
+	}
+#endif
 }
 
 bool endsWith(std::string value, std::string ending)
 {
-    std::transform(value.begin(), value.end(), value.begin(), ::tolower);
-    std::transform(ending.begin(), ending.end(), ending.begin(), ::tolower);
-    if (ending.size() > value.size()) return false;
-    return std::equal(ending.rbegin(), ending.rend(), value.rbegin());
+	std::transform(value.begin(), value.end(), value.begin(), ::tolower);
+	std::transform(ending.begin(), ending.end(), ending.begin(), ::tolower);
+	if (ending.size() > value.size())
+		return false;
+	return std::equal(ending.rbegin(), ending.rend(), value.rbegin());
 }
 
-bool validSuffix(std::string f, std::string suffix){
-    return (endsWith(f,suffix+".dll") || endsWith(f,suffix+".so"));
+bool validSuffix(std::string f, std::string suffix)
+{
+	return (endsWith(f, suffix + ".dll") || endsWith(f, suffix + ".so"));
 }
 
-std::vector<std::string> PluginLoader::searchDirectoriesForPlugins(std::vector<std::string> list, std::string suffix){
-    //Search directories
-    std::vector<std::string> filesFromFolders;
-
-    for (auto f: list)
-    {
-        auto path = std::filesystem::path(f);
-        if (path.empty())
-        {
-            continue;
-        }
-        if (std::filesystem::is_directory(path))
-        {
-            try
-            {
-                for (auto& e : std::filesystem::directory_iterator(path))
-                {
-                    auto p = e.path();
-                    if (is_shared_library(p) && p.replace_extension().extension() == suffix)
-                    {
-                        filesFromFolders.push_back(e.path().string());
-                    }
-                }
-            }
-            catch (std::filesystem::filesystem_error const& e)
-            {
-                qWarning() << e.what();
-            }
-        }
-        else if (is_shared_library(path))
-        {
-            filesFromFolders.push_back(f);
-        }
-        else
-        {
-            qWarning() << "Neither a directory, nor a shared library:" << f.data();
-        }
-    }
-
-    return filesFromFolders;
+std::vector<std::string> PluginLoader::searchDirectoriesForPlugins(
+   std::vector<std::string> list,
+   std::string              suffix)
+{
+	// Search directories
+	std::vector<std::string> filesFromFolders;
+
+	for (auto f : list) {
+		auto path = std::filesystem::path(f);
+		if (path.empty()) {
+			continue;
+		}
+		if (std::filesystem::is_directory(path)) {
+			try {
+				for (auto& e : std::filesystem::directory_iterator(path)) {
+					auto p = e.path();
+					if (is_shared_library(p) &&
+					    p.replace_extension().extension() == suffix) {
+						filesFromFolders.push_back(e.path().string());
+					}
+				}
+			} catch (std::filesystem::filesystem_error const& e) {
+				qWarning() << e.what();
+			}
+		} else if (is_shared_library(path)) {
+			filesFromFolders.push_back(f);
+		} else {
+			qWarning() << "Neither a directory, nor a shared library:"
+			           << f.data();
+		}
+	}
+
+	return filesFromFolders;
 }
 
-PluginLoader::PluginLoader(QObject *parent)
+PluginLoader::PluginLoader(QObject* parent)
 {
-    m_MetaData = nullptr;
-    m_PluginLoader = new QPluginLoader(this);
-    m_PluginListModel = new QStringListModel();
+	m_MetaData        = nullptr;
+	m_PluginLoader    = new QPluginLoader(this);
+	m_PluginListModel = new QStringListModel();
 }
 PluginLoader::~PluginLoader()
 {
-    delete m_PluginLoader;
-    delete m_PluginListModel;
+	delete m_PluginLoader;
+	delete m_PluginListModel;
 }
 
 bool PluginLoader::loadPluginFromFilename(QString const& filename)
 {
-    bool retval = false;
-    if (m_PluginLoader->isLoaded()) {
-        m_PluginLoader->unload();
-    }
-
-    bool isLib = QLibrary::isLibrary(filename);
-
-    if (isLib) {
-        
-        auto oldPath = PluginLoader::addDllPath(filename.toStdString());
-        m_PluginLoader->setFileName(filename);
-
-        readMetaDataFromPlugin();
-
-        retval = m_PluginLoader->load();
-        QString s = m_PluginLoader->errorString();
-        std::string ss = s.toStdString();
-        addPluginnameToLists(getCurrentPluginName(), filename);
-
-        if (!m_PluginLoader->isLoaded())
-        {
-            qWarning() << ss.c_str();
-            retval = false;
-        }
-        PluginLoader::delDllPath(oldPath);
-    }
-    else {
-        retval = false;
-    }
-
-    return retval;
+	bool retval = false;
+	if (m_PluginLoader->isLoaded()) {
+		m_PluginLoader->unload();
+	}
+
+	bool isLib = QLibrary::isLibrary(filename);
+
+	if (isLib) {
+
+		auto oldPath = PluginLoader::addDllPath(filename.toStdString());
+		m_PluginLoader->setFileName(filename);
+
+		readMetaDataFromPlugin();
+
+		retval         = m_PluginLoader->load();
+		QString     s  = m_PluginLoader->errorString();
+		std::string ss = s.toStdString();
+		addPluginnameToLists(getCurrentPluginName(), filename);
+
+		if (!m_PluginLoader->isLoaded()) {
+			qWarning() << ss.c_str();
+			retval = false;
+		}
+		PluginLoader::delDllPath(oldPath);
+	} else {
+		retval = false;
+	}
+
+	return retval;
 }
 
 void PluginLoader::addPluginnameToLists(QString mstring, QString filename)
-{    
-    if (!m_PluginList.contains(mstring))
-        m_PluginList.append(mstring);
-    m_PluginListModel->setStringList(m_PluginList);
-    m_PluginMap.insert(std::pair<QString, QString>(mstring, filename));
+{
+	if (!m_PluginList.contains(mstring))
+		m_PluginList.append(mstring);
+	m_PluginListModel->setStringList(m_PluginList);
+	m_PluginMap.insert(std::pair<QString, QString>(mstring, filename));
 }
 
-bool PluginLoader::loadPluginFromName(QString name) {
-    QString filename = m_PluginMap.find(name)->second;
-    return loadPluginFromFilename(filename);
+bool PluginLoader::loadPluginFromName(QString name)
+{
+	QString filename = m_PluginMap.find(name)->second;
+	return loadPluginFromFilename(filename);
 }
 
-int PluginLoader::addToPluginList(QString filename, QString suffix) {
-    if (!validSuffix(filename.toStdString(), suffix.toStdString()))
-        return 1;
-
-    bool isLib = QLibrary::isLibrary(filename);
-
-    if (isLib) {
-
-        QPluginLoader loader;
-        loader.setFileName(filename);
-        QJsonValue pluginMeda(loader.metaData().value("MetaData"));
-        QJsonObject metaObj = pluginMeda.toObject();
-        QString mstring = metaObj.value("name").toString();
-        addPluginnameToLists(mstring, filename);
-    }
-    else {
-        return 2;
-        qWarning() << "Error reading plugin: " << filename;
-    }
-    return 0;
+int PluginLoader::addToPluginList(QString filename, QString suffix)
+{
+	if (!validSuffix(filename.toStdString(), suffix.toStdString()))
+		return 1;
+
+	bool isLib = QLibrary::isLibrary(filename);
+
+	if (isLib) {
+
+		QPluginLoader loader;
+		loader.setFileName(filename);
+		QJsonValue  pluginMeda(loader.metaData().value("MetaData"));
+		QJsonObject metaObj = pluginMeda.toObject();
+		QString     mstring = metaObj.value("name").toString();
+		addPluginnameToLists(mstring, filename);
+	} else {
+		return 2;
+		qWarning() << "Error reading plugin: " << filename;
+	}
+	return 0;
 }
 
-QStringListModel* PluginLoader::getPluginList() {
-    return m_PluginListModel;
-}
+QStringListModel* PluginLoader::getPluginList() { return m_PluginListModel; }
 
-QObject* PluginLoader::getPluginInstance() {
-    return (m_PluginLoader->instance());
+QObject* PluginLoader::getPluginInstance()
+{
+	return (m_PluginLoader->instance());
 }
 
 QJsonObject PluginLoader::getPluginMetaData() const
 {
-    if (m_MetaData == nullptr)
-        qFatal("(getPluginMetaData) No plugin loaded");
-    return *m_MetaData;
+	if (m_MetaData == nullptr)
+		qFatal("(getPluginMetaData) No plugin loaded");
+	return *m_MetaData;
 }
 
 void PluginLoader::readMetaDataFromPlugin()
 {
-    m_MetaData = std::make_shared<QJsonObject>(m_PluginLoader->metaData().value("MetaData").toObject());
+	m_MetaData = std::make_shared<QJsonObject>(
+	   m_PluginLoader->metaData().value("MetaData").toObject());
 }
 
-bool PluginLoader::getIsPluginLoaded() {
-    return m_isPluginLoaded;
-}
+bool PluginLoader::getIsPluginLoaded() { return m_isPluginLoaded; }
 
-QString PluginLoader::getCurrentPluginName() {
-    if (m_MetaData == nullptr)
-        return "Error name";
-    return m_MetaData->value("name").toString();
+QString PluginLoader::getCurrentPluginName()
+{
+	if (m_MetaData == nullptr)
+		return "Error name";
+	return m_MetaData->value("name").toString();
 }
-const std::map<QString, QString> &PluginLoader::getPluginMap() const
+const std::map<QString, QString>& PluginLoader::getPluginMap() const
 {
-    return m_PluginMap;
+	return m_PluginMap;
 }
-
-
-
diff --git a/SrcBehaviorLoader/PluginLoader.h b/SrcBehaviorLoader/PluginLoader.h
index 2a41531..747c9c2 100644
--- a/SrcBehaviorLoader/PluginLoader.h
+++ b/SrcBehaviorLoader/PluginLoader.h
@@ -10,96 +10,100 @@
 
 /**
  * \class PluginLoader
- * This class loads Qt-Plugins, the related metadata and files the plugin depends on.
- * \author Hauke Mönck, Gregor Barth
+ * This class loads Qt-Plugins, the related metadata and files the plugin
+ * depends on. \author Hauke Mönck, Gregor Barth
  */
 
 class PluginLoader : QObject
 {
-    Q_OBJECT
+	Q_OBJECT
 public:
-    explicit PluginLoader(QObject *parent = 0);
-    
-    ~PluginLoader();
-
-    /**
-    * Loads a file as a QT plugin and reads it's name from the metadata.
-    * It will then be added to the stringlist and is selectable via "loadPluginFromName".
-    * This function does not actually set the plugin instance.
-    */
-    int addToPluginList(QString filename, QString suffix);
-    
-    /**
-    * Returns a QStrinListModel with the names of all seen Plugins.
-    */
-    QStringListModel* getPluginList();
-
-    /**
-    * Loads a BioTracker Plugin from a file path. It returns true if the Plugin could be loaded, otherwise false.
-    * The loaded plugin acts as singleton!
-    */
-    bool loadPluginFromFilename(QString const& filename);
-
-    /**
-    * Loads a plugin from it's name (given in the metadata) instead of the filename.
-    * Only works if it is already known to the pluginloader, i.e. was loaded manually or automatically before or
-    * or has been added to the pluginlist via "addToPluginList"
-    */
-    bool loadPluginFromName(QString name);
-
-    QJsonObject getPluginMetaData() const;
-
-    static std::vector<std::string> queryRegistryBehaviors(std::string path);
-
-    static std::vector<std::string> searchDirectoriesForPlugins(std::vector<std::string> list, std::string suffix);
-
-    //return oldPath
-    static const char* addDllPath(std::string file);
-
-    static void delDllPath(const char* oldPath);
-
-    // Is a plugin loaded or not?
-    bool getIsPluginLoaded();
-
-    // Gets the name of the currently loaded plugin
-    QString getCurrentPluginName();
-    
-    /**
-    * Returns the Instance of the BioTracker Plugin.
-    */
-    QObject *getPluginInstance();
-
-    /**
-    * Returns a map containing the mapping "plugin name -> filename"
-    */
-    std::map<QString, QString> const& getPluginMap() const;
+	explicit PluginLoader(QObject* parent = 0);
 
-private:
+	~PluginLoader();
+
+	/**
+	 * Loads a file as a QT plugin and reads it's name from the metadata.
+	 * It will then be added to the stringlist and is selectable via
+	 * "loadPluginFromName". This function does not actually set the plugin
+	 * instance.
+	 */
+	int addToPluginList(QString filename, QString suffix);
+
+	/**
+	 * Returns a QStrinListModel with the names of all seen Plugins.
+	 */
+	QStringListModel* getPluginList();
+
+	/**
+	 * Loads a BioTracker Plugin from a file path. It returns true if the Plugin
+	 * could be loaded, otherwise false. The loaded plugin acts as singleton!
+	 */
+	bool loadPluginFromFilename(QString const& filename);
+
+	/**
+	 * Loads a plugin from it's name (given in the metadata) instead of the
+	 * filename. Only works if it is already known to the pluginloader, i.e. was
+	 * loaded manually or automatically before or or has been added to the
+	 * pluginlist via "addToPluginList"
+	 */
+	bool loadPluginFromName(QString name);
+
+	QJsonObject getPluginMetaData() const;
+
+	static std::vector<std::string> queryRegistryBehaviors(std::string path);
+
+	static std::vector<std::string> searchDirectoriesForPlugins(
+	   std::vector<std::string> list,
+	   std::string              suffix);
 
-    void addPluginnameToLists(QString name, QString filename);
+	// return oldPath
+	static const char* addDllPath(std::string file);
+
+	static void delDllPath(const char* oldPath);
+
+	// Is a plugin loaded or not?
+	bool getIsPluginLoaded();
+
+	// Gets the name of the currently loaded plugin
+	QString getCurrentPluginName();
+
+	/**
+	 * Returns the Instance of the BioTracker Plugin.
+	 */
+	QObject* getPluginInstance();
+
+	/**
+	 * Returns a map containing the mapping "plugin name -> filename"
+	 */
+	std::map<QString, QString> const& getPluginMap() const;
+
+private:
+	void addPluginnameToLists(QString name, QString filename);
 
-    //a map containing the mapping "plugin name -> filename"
-    std::map<QString, QString> m_PluginMap;
+	// a map containing the mapping "plugin name -> filename"
+	std::map<QString, QString> m_PluginMap;
 
-    /**
-    * Gets the metadata from the currently loaded plugin.
-    * Currently this is nothing but the advertised name of the plugin
-    */
-    void readMetaDataFromPlugin();
+	/**
+	 * Gets the metadata from the currently loaded plugin.
+	 * Currently this is nothing but the advertised name of the plugin
+	 */
+	void readMetaDataFromPlugin();
 
-    // The QT object to actually load the plugins
-    QPluginLoader *m_PluginLoader;
+	// The QT object to actually load the plugins
+	QPluginLoader* m_PluginLoader;
 
-    std::shared_ptr<QJsonObject> m_MetaData;
+	std::shared_ptr<QJsonObject> m_MetaData;
 
-    //nomen est omen
-    bool m_isPluginLoaded;
+	// nomen est omen
+	bool m_isPluginLoaded;
 
-    // List of all available plugins 
-    QStringList m_PluginList;
+	// List of all available plugins
+	QStringList m_PluginList;
 
-    // Entire ListModel of the metadata (actually containing all metadata, not only name)
-    QStringListModel* m_PluginListModel;
+	// Entire ListModel of the metadata (actually containing all metadata, not
+	// only name)
+	QStringListModel* m_PluginListModel;
 };
 
 #endif // PLUGINLOADER_H
-- 
GitLab