src/Configuration.h
author František Kučera <franta-hg@frantovo.cz>
Sun, 26 May 2019 19:46:47 +0200
branchv_0
changeset 23 6ee7a9e311e9
parent 16 2dcc22b7a424
child 26 421608ecc12a
permissions -rw-r--r--
add option: --debug-variable-mapping + different variables for attributes with ambiguous names
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6
4062b8436838 CLI parser: first version (only single relation is supported)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     1
/**
4062b8436838 CLI parser: first version (only single relation is supported)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     2
 * Relational pipes
4062b8436838 CLI parser: first version (only single relation is supported)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     3
 * Copyright © 2019 František Kučera (Frantovo.cz, GlobalCode.info)
4062b8436838 CLI parser: first version (only single relation is supported)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     4
 *
4062b8436838 CLI parser: first version (only single relation is supported)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     5
 * This program is free software: you can redistribute it and/or modify
4062b8436838 CLI parser: first version (only single relation is supported)
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
4062b8436838 CLI parser: first version (only single relation is supported)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     7
 * the Free Software Foundation, either version 3 of the License, or
4062b8436838 CLI parser: first version (only single relation is supported)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     8
 * (at your option) any later version.
4062b8436838 CLI parser: first version (only single relation is supported)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     9
 *
4062b8436838 CLI parser: first version (only single relation is supported)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    10
 * This program is distributed in the hope that it will be useful,
4062b8436838 CLI parser: first version (only single relation is supported)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
4062b8436838 CLI parser: first version (only single relation is supported)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4062b8436838 CLI parser: first version (only single relation is supported)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    13
 * GNU General Public License for more details.
4062b8436838 CLI parser: first version (only single relation is supported)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    14
 *
4062b8436838 CLI parser: first version (only single relation is supported)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License
4062b8436838 CLI parser: first version (only single relation is supported)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    16
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
4062b8436838 CLI parser: first version (only single relation is supported)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    17
 */
4062b8436838 CLI parser: first version (only single relation is supported)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    18
#pragma once
4062b8436838 CLI parser: first version (only single relation is supported)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    19
4062b8436838 CLI parser: first version (only single relation is supported)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    20
#include <vector>
4062b8436838 CLI parser: first version (only single relation is supported)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    21
#include <tuple>
4062b8436838 CLI parser: first version (only single relation is supported)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    22
4062b8436838 CLI parser: first version (only single relation is supported)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    23
#include <relpipe/writer/AttributeMetadata.h>
4062b8436838 CLI parser: first version (only single relation is supported)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    24
#include <relpipe/writer/typedefs.h>
4062b8436838 CLI parser: first version (only single relation is supported)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    25
4062b8436838 CLI parser: first version (only single relation is supported)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    26
namespace relpipe {
4062b8436838 CLI parser: first version (only single relation is supported)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    27
namespace tr {
4062b8436838 CLI parser: first version (only single relation is supported)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    28
namespace guile {
4062b8436838 CLI parser: first version (only single relation is supported)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    29
4062b8436838 CLI parser: first version (only single relation is supported)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    30
class DefinitionRecipe {
4062b8436838 CLI parser: first version (only single relation is supported)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    31
public:
4062b8436838 CLI parser: first version (only single relation is supported)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    32
4062b8436838 CLI parser: first version (only single relation is supported)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    33
	virtual ~DefinitionRecipe() {
4062b8436838 CLI parser: first version (only single relation is supported)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    34
	}
4062b8436838 CLI parser: first version (only single relation is supported)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    35
4062b8436838 CLI parser: first version (only single relation is supported)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    36
	relpipe::writer::string_t name;
4062b8436838 CLI parser: first version (only single relation is supported)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    37
	relpipe::writer::string_t type;
4062b8436838 CLI parser: first version (only single relation is supported)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    38
	relpipe::writer::string_t value;
4062b8436838 CLI parser: first version (only single relation is supported)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    39
};
4062b8436838 CLI parser: first version (only single relation is supported)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    40
4062b8436838 CLI parser: first version (only single relation is supported)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    41
class RelationConfiguration {
4062b8436838 CLI parser: first version (only single relation is supported)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    42
public:
4062b8436838 CLI parser: first version (only single relation is supported)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    43
4062b8436838 CLI parser: first version (only single relation is supported)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    44
	virtual ~RelationConfiguration() {
4062b8436838 CLI parser: first version (only single relation is supported)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    45
	}
4062b8436838 CLI parser: first version (only single relation is supported)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    46
4062b8436838 CLI parser: first version (only single relation is supported)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    47
	relpipe::writer::string_t relation;
4062b8436838 CLI parser: first version (only single relation is supported)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    48
	relpipe::writer::string_t guileBeforeRecords;
4062b8436838 CLI parser: first version (only single relation is supported)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    49
	relpipe::writer::string_t guileAfterRecords;
4062b8436838 CLI parser: first version (only single relation is supported)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    50
	relpipe::writer::string_t guileForEach;
4062b8436838 CLI parser: first version (only single relation is supported)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    51
	relpipe::writer::string_t guileWhere;
16
2dcc22b7a424 add --has-more-records and allow adding more records dynamically in Guile
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
    52
	relpipe::writer::string_t guileHasMoreRecords;
23
6ee7a9e311e9 add option: --debug-variable-mapping + different variables for attributes with ambiguous names
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    53
	
6ee7a9e311e9 add option: --debug-variable-mapping + different variables for attributes with ambiguous names
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    54
	/**
6ee7a9e311e9 add option: --debug-variable-mapping + different variables for attributes with ambiguous names
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    55
	 * If true, additional relation will be generated: mapping between relpipe attribute names and Guile variable names
6ee7a9e311e9 add option: --debug-variable-mapping + different variables for attributes with ambiguous names
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    56
	 */
6ee7a9e311e9 add option: --debug-variable-mapping + different variables for attributes with ambiguous names
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    57
	bool debugVariableMapping = false;
15
051e58022783 add --input-attributes-append and --input-attributes-prepend for adding attributes using --output-attribute instead of replacing whole attribute list
František Kučera <franta-hg@frantovo.cz>
parents: 14
diff changeset
    58
6
4062b8436838 CLI parser: first version (only single relation is supported)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    59
	/**
4062b8436838 CLI parser: first version (only single relation is supported)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    60
	 * If true, Guile code will be executed, but no output will be generated.
4062b8436838 CLI parser: first version (only single relation is supported)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    61
	 */
4062b8436838 CLI parser: first version (only single relation is supported)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    62
	bool drop = false;
15
051e58022783 add --input-attributes-append and --input-attributes-prepend for adding attributes using --output-attribute instead of replacing whole attribute list
František Kučera <franta-hg@frantovo.cz>
parents: 14
diff changeset
    63
6
4062b8436838 CLI parser: first version (only single relation is supported)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    64
	/**
11
9603e64324bc add --define for passing parameters from the outside environment
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    65
	 * Variable definitions for this relation.
9603e64324bc add --define for passing parameters from the outside environment
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    66
	 * Can be used as a safe way for passing parameters from the outside environment.
13
c9fece435aa2 add --define for global variables (can be overridden by relation's ones)
František Kučera <franta-hg@frantovo.cz>
parents: 12
diff changeset
    67
	 * See also Configuration::definitions (can be overridden by relation's definitions)
6
4062b8436838 CLI parser: first version (only single relation is supported)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    68
	 */
4062b8436838 CLI parser: first version (only single relation is supported)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    69
	std::vector<DefinitionRecipe> definitions;
15
051e58022783 add --input-attributes-append and --input-attributes-prepend for adding attributes using --output-attribute instead of replacing whole attribute list
František Kučera <franta-hg@frantovo.cz>
parents: 14
diff changeset
    70
6
4062b8436838 CLI parser: first version (only single relation is supported)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    71
	/**
4062b8436838 CLI parser: first version (only single relation is supported)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    72
	 * If empty, output relation will have same metadata as the input relation.
4062b8436838 CLI parser: first version (only single relation is supported)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    73
	 */
4062b8436838 CLI parser: first version (only single relation is supported)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    74
	std::vector<relpipe::writer::AttributeMetadata> writerMetadata;
15
051e58022783 add --input-attributes-append and --input-attributes-prepend for adding attributes using --output-attribute instead of replacing whole attribute list
František Kučera <franta-hg@frantovo.cz>
parents: 14
diff changeset
    75
051e58022783 add --input-attributes-append and --input-attributes-prepend for adding attributes using --output-attribute instead of replacing whole attribute list
František Kučera <franta-hg@frantovo.cz>
parents: 14
diff changeset
    76
	/**
051e58022783 add --input-attributes-append and --input-attributes-prepend for adding attributes using --output-attribute instead of replacing whole attribute list
František Kučera <franta-hg@frantovo.cz>
parents: 14
diff changeset
    77
	 * Whether original attributes should be appended to those specified using --output-attribute
051e58022783 add --input-attributes-append and --input-attributes-prepend for adding attributes using --output-attribute instead of replacing whole attribute list
František Kučera <franta-hg@frantovo.cz>
parents: 14
diff changeset
    78
	 */
051e58022783 add --input-attributes-append and --input-attributes-prepend for adding attributes using --output-attribute instead of replacing whole attribute list
František Kučera <franta-hg@frantovo.cz>
parents: 14
diff changeset
    79
	bool inputAttributesAppend = false;
051e58022783 add --input-attributes-append and --input-attributes-prepend for adding attributes using --output-attribute instead of replacing whole attribute list
František Kučera <franta-hg@frantovo.cz>
parents: 14
diff changeset
    80
051e58022783 add --input-attributes-append and --input-attributes-prepend for adding attributes using --output-attribute instead of replacing whole attribute list
František Kučera <franta-hg@frantovo.cz>
parents: 14
diff changeset
    81
	/**
051e58022783 add --input-attributes-append and --input-attributes-prepend for adding attributes using --output-attribute instead of replacing whole attribute list
František Kučera <franta-hg@frantovo.cz>
parents: 14
diff changeset
    82
	 * Whether original attributes should be prepended to those specified using --output-attribute
051e58022783 add --input-attributes-append and --input-attributes-prepend for adding attributes using --output-attribute instead of replacing whole attribute list
František Kučera <franta-hg@frantovo.cz>
parents: 14
diff changeset
    83
	 */
051e58022783 add --input-attributes-append and --input-attributes-prepend for adding attributes using --output-attribute instead of replacing whole attribute list
František Kučera <franta-hg@frantovo.cz>
parents: 14
diff changeset
    84
	bool inputAttributesPrepend = false;
6
4062b8436838 CLI parser: first version (only single relation is supported)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    85
};
4062b8436838 CLI parser: first version (only single relation is supported)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    86
4062b8436838 CLI parser: first version (only single relation is supported)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    87
class Configuration {
4062b8436838 CLI parser: first version (only single relation is supported)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    88
public:
15
051e58022783 add --input-attributes-append and --input-attributes-prepend for adding attributes using --output-attribute instead of replacing whole attribute list
František Kučera <franta-hg@frantovo.cz>
parents: 14
diff changeset
    89
6
4062b8436838 CLI parser: first version (only single relation is supported)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    90
	vector<RelationConfiguration> relationConfigurations;
13
c9fece435aa2 add --define for global variables (can be overridden by relation's ones)
František Kučera <franta-hg@frantovo.cz>
parents: 12
diff changeset
    91
	/**
c9fece435aa2 add --define for global variables (can be overridden by relation's ones)
František Kučera <franta-hg@frantovo.cz>
parents: 12
diff changeset
    92
	 * Global definitions for all relations.
c9fece435aa2 add --define for global variables (can be overridden by relation's ones)
František Kučera <franta-hg@frantovo.cz>
parents: 12
diff changeset
    93
	 * Can be used as a safe way for passing parameters from the outside environment.
c9fece435aa2 add --define for global variables (can be overridden by relation's ones)
František Kučera <franta-hg@frantovo.cz>
parents: 12
diff changeset
    94
	 * See also RelationConfiguration::definitions
c9fece435aa2 add --define for global variables (can be overridden by relation's ones)
František Kučera <franta-hg@frantovo.cz>
parents: 12
diff changeset
    95
	 */
c9fece435aa2 add --define for global variables (can be overridden by relation's ones)
František Kučera <franta-hg@frantovo.cz>
parents: 12
diff changeset
    96
	std::vector<DefinitionRecipe> definitions;
6
4062b8436838 CLI parser: first version (only single relation is supported)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    97
11
9603e64324bc add --define for passing parameters from the outside environment
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    98
	// TODO: --create t2 3 a integer b boolean '…guile…' – allow creating new relations? Or allow calling startRelation() and attribute() from Guile?
16
2dcc22b7a424 add --has-more-records and allow adding more records dynamically in Guile
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
    99
	// TODO: --has-more-relations '…guile…' – called after all relations … ?
2dcc22b7a424 add --has-more-records and allow adding more records dynamically in Guile
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
   100
	// TODO: --dynamic-output-attributes '…guile…' – used instead or together with --output-attribute
11
9603e64324bc add --define for passing parameters from the outside environment
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
   101
6
4062b8436838 CLI parser: first version (only single relation is supported)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   102
	virtual ~Configuration() {
4062b8436838 CLI parser: first version (only single relation is supported)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   103
	}
4062b8436838 CLI parser: first version (only single relation is supported)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   104
};
4062b8436838 CLI parser: first version (only single relation is supported)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   105
4062b8436838 CLI parser: first version (only single relation is supported)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   106
}
4062b8436838 CLI parser: first version (only single relation is supported)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   107
}
4062b8436838 CLI parser: first version (only single relation is supported)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   108
}