parallel processing: rename FilesystemCommand to PlainFilesystemCommand v_0
authorFrantišek Kučera <franta-hg@frantovo.cz>
Mon, 20 Jan 2020 13:11:50 +0100
branchv_0
changeset 53 170a993745be
parent 52 fea625f0a096
child 54 ef726975c34b
parallel processing: rename FilesystemCommand to PlainFilesystemCommand
src/FilesystemCommand.h
src/PlainFilesystemCommand.h
src/relpipe-in-filesystem.cpp
--- a/src/FilesystemCommand.h	Mon Jan 20 12:39:22 2020 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,73 +0,0 @@
-/**
- * Relational pipes
- * Copyright © 2019 František Kučera (Frantovo.cz, GlobalCode.info)
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, version 3 of the License.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-#pragma once
-
-#include "FilesystemCommandBase.h"
-
-namespace relpipe {
-namespace in {
-namespace filesystem {
-
-namespace fs = std::filesystem;
-using namespace relpipe::writer;
-
-class FilesystemCommand : public FilesystemCommandBase {
-private:
-	std::map<string_t, std::shared_ptr<AttributeFinder>> attributeFinders = createAttributeFinders();
-
-public:
-
-	void process(std::istream& input, std::ostream& output, Configuration& configuration) {
-		std::shared_ptr<RelationalWriter> writer(Factory::create(output));
-
-		string_t relationName = configuration.relation.empty() ? L"filesystem" : configuration.relation;
-
-		std::vector<AttributeMetadata> attributesMetadata;
-		for (RequestedField field : configuration.fields) {
-			std::shared_ptr<AttributeFinder> finder = attributeFinders[field.group];
-			if (finder) for (AttributeMetadata m : finder->toMetadata(writer.get(), relationName, field)) attributesMetadata.push_back(m);
-			else throw RelpipeWriterException(L"Unsupported field group: " + field.group);
-		}
-
-		writer->startRelation(relationName, attributesMetadata, true);
-
-
-		for (std::stringstream originalName; readNext(input, originalName); reset(originalName)) {
-			fs::path file(originalName.str().empty() ? "." : originalName.str()); // interpret empty string as current directory (e.g. result of: find -printf '%P\0')
-			bool exists = false;
-
-			try {
-				exists = fs::exists(file);
-			} catch (const fs::filesystem_error& e) {
-				// we probably do not have permissions to given directory → pretend that the file does not exist
-			}
-
-			for (auto& finder : attributeFinders) finder.second->startFile(file, originalName.str(), exists);
-
-			for (RequestedField field : configuration.fields) {
-				std::shared_ptr<AttributeFinder> finder = attributeFinders[field.group]; // should not be nullptr, because already checked while writing the relation metadata
-				finder->writeField(writer.get(), relationName, field);
-			}
-
-			for (auto& finder : attributeFinders) finder.second->endFile();
-		}
-	}
-};
-
-}
-}
-}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/PlainFilesystemCommand.h	Mon Jan 20 13:11:50 2020 +0100
@@ -0,0 +1,73 @@
+/**
+ * Relational pipes
+ * Copyright © 2019 František Kučera (Frantovo.cz, GlobalCode.info)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 3 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+#pragma once
+
+#include "FilesystemCommandBase.h"
+
+namespace relpipe {
+namespace in {
+namespace filesystem {
+
+namespace fs = std::filesystem;
+using namespace relpipe::writer;
+
+class PlainFilesystemCommand : public FilesystemCommandBase {
+private:
+	std::map<string_t, std::shared_ptr<AttributeFinder>> attributeFinders = createAttributeFinders();
+
+public:
+
+	void process(std::istream& input, std::ostream& output, Configuration& configuration) {
+		std::shared_ptr<RelationalWriter> writer(Factory::create(output));
+
+		string_t relationName = configuration.relation.empty() ? L"filesystem" : configuration.relation;
+
+		std::vector<AttributeMetadata> attributesMetadata;
+		for (RequestedField field : configuration.fields) {
+			std::shared_ptr<AttributeFinder> finder = attributeFinders[field.group];
+			if (finder) for (AttributeMetadata m : finder->toMetadata(writer.get(), relationName, field)) attributesMetadata.push_back(m);
+			else throw RelpipeWriterException(L"Unsupported field group: " + field.group);
+		}
+
+		writer->startRelation(relationName, attributesMetadata, true);
+
+
+		for (std::stringstream originalName; readNext(input, originalName); reset(originalName)) {
+			fs::path file(originalName.str().empty() ? "." : originalName.str()); // interpret empty string as current directory (e.g. result of: find -printf '%P\0')
+			bool exists = false;
+
+			try {
+				exists = fs::exists(file);
+			} catch (const fs::filesystem_error& e) {
+				// we probably do not have permissions to given directory → pretend that the file does not exist
+			}
+
+			for (auto& finder : attributeFinders) finder.second->startFile(file, originalName.str(), exists);
+
+			for (RequestedField field : configuration.fields) {
+				std::shared_ptr<AttributeFinder> finder = attributeFinders[field.group]; // should not be nullptr, because already checked while writing the relation metadata
+				finder->writeField(writer.get(), relationName, field);
+			}
+
+			for (auto& finder : attributeFinders) finder.second->endFile();
+		}
+	}
+};
+
+}
+}
+}
--- a/src/relpipe-in-filesystem.cpp	Mon Jan 20 12:39:22 2020 +0100
+++ b/src/relpipe-in-filesystem.cpp	Mon Jan 20 13:11:50 2020 +0100
@@ -29,7 +29,7 @@
 #include <relpipe/cli/CLI.h>
 #include <relpipe/cli/RelpipeCLIException.h>
 
-#include "FilesystemCommand.h"
+#include "PlainFilesystemCommand.h"
 #include "ParallelFilesystemCommand.h"
 #include "CLIParser.h"
 
@@ -48,7 +48,7 @@
 		CLIParser cliParser;
 		Configuration configuration = cliParser.parse(cli.arguments());
 		std::unique_ptr<FilesystemCommandBase> command;
-		if (configuration.parallelism == 1) command = std::make_unique<FilesystemCommand>();
+		if (configuration.parallelism == 1) command = std::make_unique<PlainFilesystemCommand>();
 		else command = std::make_unique<ParallelFilesystemCommand>();
 		command->process(cin, cout, configuration);
 		resultCode = CLI::EXIT_CODE_SUCCESS;