src/MetadataMode.h
author František Kučera <franta-hg@frantovo.cz>
Sun, 23 May 2021 13:59:09 +0200
branchv_0
changeset 1 da114916734b
child 2 eddead33f633
permissions -rw-r--r--
multiple modes infrastructure
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
da114916734b multiple modes infrastructure
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     1
/**
da114916734b multiple modes infrastructure
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     2
 * Relational pipes
da114916734b multiple modes infrastructure
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     3
 * Copyright © 2021 František Kučera (Frantovo.cz, GlobalCode.info)
da114916734b multiple modes infrastructure
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     4
 *
da114916734b multiple modes infrastructure
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     5
 * This program is free software: you can redistribute it and/or modify
da114916734b multiple modes infrastructure
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
da114916734b multiple modes infrastructure
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     7
 * the Free Software Foundation, version 3 of the License.
da114916734b multiple modes infrastructure
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     8
 *
da114916734b multiple modes infrastructure
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
da114916734b multiple modes infrastructure
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
da114916734b multiple modes infrastructure
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
da114916734b multiple modes infrastructure
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    12
 * GNU General Public License for more details.
da114916734b multiple modes infrastructure
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    13
 *
da114916734b multiple modes infrastructure
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
da114916734b multiple modes infrastructure
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    15
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
da114916734b multiple modes infrastructure
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    16
 */
da114916734b multiple modes infrastructure
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    17
#pragma once
da114916734b multiple modes infrastructure
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    18
da114916734b multiple modes infrastructure
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    19
#include <regex>
da114916734b multiple modes infrastructure
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    20
#include <locale>
da114916734b multiple modes infrastructure
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    21
da114916734b multiple modes infrastructure
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    22
#include <relpipe/common/type/typedefs.h>
da114916734b multiple modes infrastructure
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    23
da114916734b multiple modes infrastructure
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    24
#include "Mode.h"
da114916734b multiple modes infrastructure
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    25
da114916734b multiple modes infrastructure
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    26
namespace relpipe {
da114916734b multiple modes infrastructure
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    27
namespace tr {
da114916734b multiple modes infrastructure
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    28
namespace infertypes {
da114916734b multiple modes infrastructure
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    29
da114916734b multiple modes infrastructure
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    30
class MetadataMode : public Mode {
da114916734b multiple modes infrastructure
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    31
private:
da114916734b multiple modes infrastructure
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    32
	static std::wregex pattern;
da114916734b multiple modes infrastructure
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    33
public:
da114916734b multiple modes infrastructure
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    34
da114916734b multiple modes infrastructure
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    35
	MetadataMode(shared_ptr<writer::RelationalWriter> relationalWriter) : Mode(relationalWriter) {
da114916734b multiple modes infrastructure
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    36
	}
da114916734b multiple modes infrastructure
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    37
da114916734b multiple modes infrastructure
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    38
	static bool willInfer(std::vector<relpipe::reader::handlers::AttributeMetadata> attributes) {
da114916734b multiple modes infrastructure
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    39
		for (relpipe::reader::handlers::AttributeMetadata a : attributes) if (!std::regex_match(a.getAttributeName(), pattern)) return false;
da114916734b multiple modes infrastructure
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    40
		return true;
da114916734b multiple modes infrastructure
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    41
	}
da114916734b multiple modes infrastructure
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    42
da114916734b multiple modes infrastructure
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    43
	void startRelation(relpipe::common::type::StringX name, std::vector<relpipe::reader::handlers::AttributeMetadata> attributes) override {
da114916734b multiple modes infrastructure
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    44
		// TODO: share this code through relpipe-lib-infertypes (when available)
da114916734b multiple modes infrastructure
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    45
	}
da114916734b multiple modes infrastructure
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    46
da114916734b multiple modes infrastructure
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    47
	void attribute(const relpipe::common::type::StringX& value) override {
da114916734b multiple modes infrastructure
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    48
		relationalWriter->writeAttribute(value);
da114916734b multiple modes infrastructure
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    49
	}
da114916734b multiple modes infrastructure
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    50
};
da114916734b multiple modes infrastructure
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    51
da114916734b multiple modes infrastructure
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    52
std::wregex MetadataMode::pattern = std::wregex(L"(.*)::(.*)");
da114916734b multiple modes infrastructure
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    53
da114916734b multiple modes infrastructure
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    54
}
da114916734b multiple modes infrastructure
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    55
}
da114916734b multiple modes infrastructure
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    56
}