src/RecfileCommand.h
author František Kučera <franta-hg@frantovo.cz>
Fri, 05 Apr 2019 18:02:19 +0200
branchv_0
changeset 0 515a697cc9cd
child 1 8dfb42e5c088
permissions -rw-r--r--
project skeleton
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     1
/**
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     2
 * Relational pipes
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     3
 * Copyright © 2019 František Kučera (Frantovo.cz, GlobalCode.info)
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     4
 *
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     5
 * This program is free software: you can redistribute it and/or modify
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     7
 * the Free Software Foundation, either version 3 of the License, or
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     8
 * (at your option) any later version.
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     9
 *
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    10
 * This program is distributed in the hope that it will be useful,
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    13
 * GNU General Public License for more details.
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    14
 *
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    16
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    17
 */
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    18
#pragma once
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    19
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    20
#include <iostream>
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    21
#include <string>
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    22
#include <sstream>
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    23
#include <vector>
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    24
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    25
#include <relpipe/writer/typedefs.h>
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    26
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    27
namespace relpipe {
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    28
namespace in {
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    29
namespace recfile {
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    30
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    31
using namespace relpipe::writer;
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    32
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    33
class RecfileCommand {
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    34
private:
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    35
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    36
	enum class RecfileLineType {
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    37
		METADATA,
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    38
		DATA
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    39
	};
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    40
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    41
	class RecfileHandler {
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    42
	private:
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    43
		RelationalWriter* writer;
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    44
	public:
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    45
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    46
		RecfileHandler(RelationalWriter* writer) : writer(writer) {
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    47
		}
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    48
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    49
		virtual ~RecfileHandler() {
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    50
		}
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    51
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    52
		void logicalLine(const string_t& name, const string_t& value, RecfileLineType type) {
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    53
			std::wcerr << L"logicalLine(" << name << L", " << value << L", " << (int) type << L");" << std::endl; // TODO: remove debug
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    54
			// TODO: writer->startRelation()
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    55
			// TODO: writer->writeAttribute()
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    56
		}
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    57
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    58
	};
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    59
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    60
	class RecfileParser {
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    61
	private:
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    62
		RecfileHandler& handler;
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    63
	public:
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    64
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    65
		RecfileParser(RecfileHandler& handler) : handler(handler) {
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    66
		}
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    67
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    68
		virtual ~RecfileParser() {
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    69
		}
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    70
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    71
		void parse(std::istream& input) {
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    72
			// TODO: parse
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    73
			handler.logicalLine(L"nnn", L"vvv", RecfileLineType::METADATA); // TODO: remove debug
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    74
			handler.logicalLine(L"nnn", L"vvv", RecfileLineType::DATA); // TODO: remove debug
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    75
		}
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    76
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    77
	};
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    78
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    79
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    80
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    81
public:
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    82
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    83
	void process(std::istream& input, std::ostream& output) {
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    84
		unique_ptr<RelationalWriter> writer(Factory::create(output));
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    85
		RecfileHandler handler(writer.get());
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    86
		RecfileParser parser(handler);
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    87
		parser.parse(input);
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    88
	}
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    89
};
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    90
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    91
}
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    92
}
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    93
}