src/Configuration.h
author František Kučera <franta-hg@frantovo.cz>
Sun, 16 May 2021 17:33:35 +0200
branchv_0
changeset 26 576d4965434f
parent 25 0cfbaf5c57a6
permissions -rw-r--r--
new CLI interface: --modify relation-name, --modify attribute-name
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
25
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     1
/**
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     2
 * Relational pipes
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     3
 * Copyright © 2021 František Kučera (Frantovo.cz, GlobalCode.info)
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     4
 *
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     5
 * This program is free software: you can redistribute it and/or modify
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
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
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     7
 * the Free Software Foundation, version 3 of the License.
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     8
 *
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    12
 * GNU General Public License for more details.
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    13
 *
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    15
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    16
 */
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    17
#pragma once
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    18
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    19
#include <map>
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    20
#include <regex>
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    21
#include <locale>
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    22
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    23
#include <relpipe/common/type/typedefs.h>
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    24
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    25
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    26
namespace relpipe {
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    27
namespace tr {
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    28
namespace sed {
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    29
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    30
enum class ENTITY {
26
576d4965434f new CLI interface: --modify relation-name, --modify attribute-name
František Kučera <franta-hg@frantovo.cz>
parents: 25
diff changeset
    31
	DEFAULT,
25
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    32
	RELATION,
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    33
	ATTRIBUTE,
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    34
	VALUE
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    35
};
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    36
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    37
class RewriteRule {
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    38
public:
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    39
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    40
	RewriteRule(std::map<ENTITY, relpipe::common::type::Boolean> caseSensitive, std::map<ENTITY, relpipe::common::type::Boolean> invertMatch) : caseSensitive(caseSensitive), invertMatch(invertMatch) {
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    41
	}
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    42
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    43
	virtual ~RewriteRule() {
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    44
	}
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    45
26
576d4965434f new CLI interface: --modify relation-name, --modify attribute-name
František Kučera <franta-hg@frantovo.cz>
parents: 25
diff changeset
    46
	/**
576d4965434f new CLI interface: --modify relation-name, --modify attribute-name
František Kučera <franta-hg@frantovo.cz>
parents: 25
diff changeset
    47
	 * What will be modified:
576d4965434f new CLI interface: --modify relation-name, --modify attribute-name
František Kučera <franta-hg@frantovo.cz>
parents: 25
diff changeset
    48
	 *  - relation: rename relation
576d4965434f new CLI interface: --modify relation-name, --modify attribute-name
František Kučera <franta-hg@frantovo.cz>
parents: 25
diff changeset
    49
	 *  - attribute: rename attribute
576d4965434f new CLI interface: --modify relation-name, --modify attribute-name
František Kučera <franta-hg@frantovo.cz>
parents: 25
diff changeset
    50
	 *  - value: rewrite value
576d4965434f new CLI interface: --modify relation-name, --modify attribute-name
František Kučera <franta-hg@frantovo.cz>
parents: 25
diff changeset
    51
	 *  - default: not yet set (should be set in CLIParser; means error everywhere else)
576d4965434f new CLI interface: --modify relation-name, --modify attribute-name
František Kučera <franta-hg@frantovo.cz>
parents: 25
diff changeset
    52
	 */
576d4965434f new CLI interface: --modify relation-name, --modify attribute-name
František Kučera <franta-hg@frantovo.cz>
parents: 25
diff changeset
    53
	ENTITY modify = ENTITY::DEFAULT;
25
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    54
	relpipe::common::type::StringX attribute;
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    55
	relpipe::common::type::StringX value;
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    56
	relpipe::common::type::StringX replacement;
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    57
	std::wregex attributePattern;
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    58
	std::wregex valuePattern;
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    59
	std::map<ENTITY, relpipe::common::type::Boolean> caseSensitive;
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    60
	std::map<ENTITY, relpipe::common::type::Boolean> invertMatch;
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    61
};
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    62
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    63
class RelationConfiguration {
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    64
public:
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    65
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    66
	RelationConfiguration() {
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    67
		caseSensitive[ENTITY::RELATION] = true;
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    68
		caseSensitive[ENTITY::ATTRIBUTE] = true;
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    69
		caseSensitive[ENTITY::VALUE] = true;
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    70
		invertMatch[ENTITY::RELATION] = false;
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    71
		invertMatch[ENTITY::ATTRIBUTE] = false;
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    72
		invertMatch[ENTITY::VALUE] = false;
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    73
	}
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    74
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    75
	virtual ~RelationConfiguration() {
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    76
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    77
	}
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    78
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    79
	relpipe::common::type::StringX relation;
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    80
	std::wregex relationPattern;
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    81
	std::vector<RewriteRule> rules;
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    82
	std::map<ENTITY, relpipe::common::type::Boolean> caseSensitive;
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    83
	std::map<ENTITY, relpipe::common::type::Boolean> invertMatch;
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    84
};
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    85
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    86
class Configuration {
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    87
public:
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    88
	std::vector<RelationConfiguration> relationConfigurations;
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    89
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    90
	virtual ~Configuration() {
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    91
	}
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    92
};
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    93
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    94
}
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    95
}
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    96
}