From 4df630d60e595e04dfa1bc393bf04619ace79bff Mon Sep 17 00:00:00 2001
From: am0ebe <am0ebe@gmx.de>
Date: Fri, 18 Feb 2022 18:57:42 +0100
Subject: [PATCH] files check stuff

---
 camtron.sublime-project-snippet |  4 +--
 examples/Demo.cpp               | 28 ++++++-----------
 src/algorithms/tools.cpp        | 56 ++++++++++++++-------------------
 src/algorithms/tools.h          |  4 +--
 4 files changed, 36 insertions(+), 56 deletions(-)

diff --git a/camtron.sublime-project-snippet b/camtron.sublime-project-snippet
index 2326b27..fac2dc5 100644
--- a/camtron.sublime-project-snippet
+++ b/camtron.sublime-project-snippet
@@ -1,6 +1,6 @@
 	{
 					"name": "run",
-					"shell_cmd": "bgs_demo -i ../../dataset/video.tar -a 100 -o ../../output -c ../../config/centerConfigFile.xml -p ../../config/camParam.xml",
+					"shell_cmd": "bgs_demo -i ../../dataset/video.tar -a 100 -o ../../output -c ../../config/centerConfigFile.xml -p ../../config/camParam.xml | c++filt -t",
 				},
 				{
 					"name": "clean",
@@ -8,7 +8,7 @@
 				},
 				{
 					"name": "run: single",
-					"shell_cmd": "echo 'run...' && $file_base_name",
+					"shell_cmd": "echo 'run...' && $file_base_name | c++filt -t",
 				},
 				{
 					"name": "opencv: single",
diff --git a/examples/Demo.cpp b/examples/Demo.cpp
index c56922c..42bcfa7 100644
--- a/examples/Demo.cpp
+++ b/examples/Demo.cpp
@@ -171,29 +171,19 @@ void parse(int argc, char** argv)
 	cout << "amountFiles: " << amountFiles << endl;
 	cout << boolalpha << "testMode: " << testMode << endl;
 
-	bool check = Tools::checkFile(camParamFile,"camParamFile") && \
-		Tools::checkFile(centerFile,"centerFile")  && \
-		Tools::checkFile(inputFile,"inputFile")  && \
-		Tools::checkDir(outputDir,"outputDir");
-
-	list<tuple <string, string, bool>> tuplelist;
-	tuple <string, string, bool> filedir = make_tuple("camParamFile",camParamFile,false);
-	tuple <string, string, bool> filedir = make_tuple("centerFile",centerFile,false);
-	tuple <string, string, bool> filedir = make_tuple("inputFile",inputFile,false);
-	tuple <string, string, bool> filedir = make_tuple("outputDir",outputDir,true);
-
-if( checkFileDir(\
-	"camParamFile", camParamFile, \
-	"centerFile", centerFile, \
-	"inputFile", inputFile, \
-	"outputDir", outputDir) )
+	vector<String> x ={
+		"camParamFile", camParamFile,
+		"centerFile", centerFile,
+		"inputFile", inputFile,
+		"outputDir", outputDir
+	};
+	if( !Tools::check(x))
 		exit(error::config_filedir);
 
-	if(check)
-		exit(error::config_filedir);
+	Tools::maybeAppendSepToDir(outputDir);
 	Tools::print_ruler();
 
-	exit(1232);
+	exit(-1);
 }
 
 void read_camParamFile()
diff --git a/src/algorithms/tools.cpp b/src/algorithms/tools.cpp
index f9fac38..aed3233 100644
--- a/src/algorithms/tools.cpp
+++ b/src/algorithms/tools.cpp
@@ -12,43 +12,33 @@ void Tools::print_ruler()
 	std::cout << "######################################" << std::endl;
 }
 
-
-bool Tools::checkFile(std::string path, std::string name="path")
+bool Tools::maybeAppendSepToDir(String& d)
 {
-	bool check = std::filesystem::exists(path);
-	if (!check)
-		std::cerr << name << ": " << path << " [not found!] " << std::endl;
-	else
-		std::cout << name << ": " << path << std::endl;
-
-	return check;
+    const char SEP = std::filesystem::path::preferred_separator;
+    if( d.back() != SEP )
+        d += SEP;
 }
 
-bool Tools::checkDir(std::string& path, std::string name="path")
+auto Tools::check(vector<String>& x)
 {
-	const char SEP = std::filesystem::path::preferred_separator;
-	if( ! path.ends_with(SEP) )
-		path += SEP;
-
-	bool check = std::filesystem::exists(path);
-	if (!check)
-	{
-		try {
-			std::filesystem::create_directories(path);
-			std::cout << name << ": " << path << " [created!] " << std::endl;
-			check = true;
-		}
-		catch (std::filesystem::filesystem_error &e) {
-			std::cerr << name << ": " << path << " [not found + cant create it!] " << std::endl;
-			check = false;
-		}
-	}
-	else
-	{
-		std::cout << name << ": " << path << std::endl;
-	}
-
-	return check;
+    bool checkAll = true;
+    String name, path;
+
+    for (int i{0}; i<x.size()-1; i++)
+    {
+        name = x[i];
+        path = x[++i];
+
+        bool check = std::filesystem::exists(path);
+        if (!check)
+            std::cerr << name << ": " << path << " [not found!] " << std::endl;
+        else
+            std::cout << name << ": " << path << std::endl;
+
+        checkAll &= check;
+    }
+
+    return checkAll;
 }
 
 std::string Tools::mNzero(int i)
diff --git a/src/algorithms/tools.h b/src/algorithms/tools.h
index 3d34e36..2406fe5 100644
--- a/src/algorithms/tools.h
+++ b/src/algorithms/tools.h
@@ -26,8 +26,8 @@ class Tools
 {
 public:
 
-	static bool checkDir(std::string& path, std::string name);
-	static bool checkFile(std::string path, std::string name);
+	static void maybeAppendSepToDir(std::String& d)
+	static bool check(std::vector<std::String>& x)
 
 	//! print ruler
 	static void print_ruler();
-- 
GitLab