equal
deleted
inserted
replaced
36 |
36 |
37 #include <relpipe/writer/Factory.h> |
37 #include <relpipe/writer/Factory.h> |
38 |
38 |
39 #include <relpipe/cli/RelpipeCLIException.h> |
39 #include <relpipe/cli/RelpipeCLIException.h> |
40 |
40 |
|
41 #include "Configuration.h" |
|
42 |
41 namespace relpipe { |
43 namespace relpipe { |
42 namespace tr { |
44 namespace tr { |
43 namespace guile { |
45 namespace guile { |
44 |
46 |
45 using namespace std; |
47 using namespace std; |
49 |
51 |
50 class GuileHandler : public RelationalReaderValueHadler { |
52 class GuileHandler : public RelationalReaderValueHadler { |
51 private: |
53 private: |
52 std::wstring_convert<codecvt_utf8<wchar_t>> convertor; // TODO: support also other encodings or use always UTF-8 between C++ and Guile |
54 std::wstring_convert<codecvt_utf8<wchar_t>> convertor; // TODO: support also other encodings or use always UTF-8 between C++ and Guile |
53 |
55 |
|
56 Configuration configuration; |
54 shared_ptr<writer::RelationalWriter> relationalWriter; |
57 shared_ptr<writer::RelationalWriter> relationalWriter; |
55 |
58 |
56 wregex relationNameRegEx; |
59 wregex relationNameRegEx; |
57 |
60 |
58 vector<AttributeMetadata> currentReaderMetadata; |
61 vector<AttributeMetadata> currentReaderMetadata; |
141 } |
144 } |
142 } |
145 } |
143 |
146 |
144 public: |
147 public: |
145 |
148 |
146 GuileHandler(ostream& output, const vector<string_t>& arguments) { |
149 GuileHandler(ostream& output, Configuration& configuration, const vector<string_t>& arguments) : configuration(configuration) { |
147 relationalWriter.reset(writer::Factory::create(output)); |
150 relationalWriter.reset(writer::Factory::create(output)); |
148 |
151 |
149 // TODO: options and parser |
152 // FIXME: remove and work directly with configuration in startRelation() and attribute() |
150 if (arguments.size() == 2) { |
153 // i.e. support multiple relationConfigurations |
151 relationNameRegEx = wregex(arguments[0]); |
154 if (configuration.relationConfigurations.size() == 1) { |
152 guileCodeWhereCondition = arguments[1]; |
155 relationNameRegEx = wregex(configuration.relationConfigurations[0].relation); |
|
156 guileCodeWhereCondition = configuration.relationConfigurations[0].guileWhere; |
153 } else { |
157 } else { |
154 throw cli::RelpipeCLIException(L"Usage: relpipe-tr-guile <relationNameRegExp> <whereConditionGuileCode>", cli::CLI::EXIT_CODE_UNKNOWN_COMMAND); |
158 throw cli::RelpipeCLIException(L"FIXME: only single relationConfiguration is currently supported", cli::CLI::EXIT_CODE_UNKNOWN_COMMAND); |
155 } |
159 } |
156 } |
160 } |
157 |
161 |
158 void startRelation(string_t name, vector<AttributeMetadata> attributes) override { |
162 void startRelation(string_t name, vector<AttributeMetadata> attributes) override { |
159 for (auto attribute : currentReaderMetadata) undefineGuileVariable(attribute.getAttributeName()); |
163 for (auto attribute : currentReaderMetadata) undefineGuileVariable(attribute.getAttributeName()); |