66 } |
66 } |
67 |
67 |
68 SCM toGuileString(const string_t& value) { |
68 SCM toGuileString(const string_t& value) { |
69 return scm_from_locale_string(convertor.to_bytes(value).c_str()); |
69 return scm_from_locale_string(convertor.to_bytes(value).c_str()); |
70 } |
70 } |
71 |
71 |
72 SCM toGuileInteger(const string_t& value) { |
72 SCM toGuileInteger(const string_t& value) { |
73 return scm_from_uint64(stoul(value)); |
73 return scm_from_uint64(stoul(value)); |
74 } |
74 } |
75 |
75 |
76 SCM toGuileBoolean(const string_t& value) { |
76 SCM toGuileBoolean(const string_t& value) { |
77 return value == L"true" ? SCM_BOOL_T : SCM_BOOL_F; |
77 return value == L"true" ? SCM_BOOL_T : SCM_BOOL_F; |
78 } |
78 } |
79 |
79 |
80 void defineGuileVariable(const string_t& name, TypeId type, const string_t& value) { |
80 void defineGuileVariable(const string_t& name, TypeId type, const string_t& value) { |
127 relationalWriter->startRelation(name, writerMetadata, true); |
127 relationalWriter->startRelation(name, writerMetadata, true); |
128 } |
128 } |
129 |
129 |
130 void attribute(const string_t& value) override { |
130 void attribute(const string_t& value) override { |
131 if (filterCurrentRelation) { |
131 if (filterCurrentRelation) { |
132 // TODO: evaluate condition and updates in Guile |
|
133 currentRecord[currentAttributeIndex] = value; |
132 currentRecord[currentAttributeIndex] = value; |
134 includeCurrentRecord = false; |
133 defineGuileVariable(currentMetadata[currentAttributeIndex].getAttributeName(), currentMetadata[currentAttributeIndex].getTypeId(), value); |
135 |
|
136 // TODO: remove, just a demo code |
|
137 defineGuileVariable(L"hello", TypeId::STRING, L"world"); |
|
138 defineGuileVariable(L"a", TypeId::INTEGER, L"123"); |
|
139 defineGuileVariable(L"b", TypeId::INTEGER, L"456"); |
|
140 defineGuileVariable(L"tr", TypeId::BOOLEAN, L"true"); |
|
141 defineGuileVariable(L"fa", TypeId::BOOLEAN, L"false"); |
|
142 |
|
143 //integer_t guileResult = scm_to_uint64(scm_eval_string(toGuileString(guileCode))); |
|
144 //std::wcerr << "result from Guile: " << guileResult << std::endl; |
|
145 |
|
146 includeCurrentRecord = scm_to_bool(scm_eval_string(toGuileString(guileCode))); |
|
147 //scm_shell(0, nullptr); |
|
148 // -------- |
|
149 |
|
150 |
|
151 currentAttributeIndex++; |
134 currentAttributeIndex++; |
152 |
135 |
153 if (currentAttributeIndex > 0 && currentAttributeIndex % currentMetadata.size() == 0) { |
136 if (currentAttributeIndex > 0 && currentAttributeIndex % currentMetadata.size() == 0) { |
|
137 // TODO: support also updates in Guile |
|
138 includeCurrentRecord = scm_to_bool(scm_eval_string(toGuileString(guileCode))); |
154 if (includeCurrentRecord) for (string_t v : currentRecord) relationalWriter->writeAttribute(v); |
139 if (includeCurrentRecord) for (string_t v : currentRecord) relationalWriter->writeAttribute(v); |
155 includeCurrentRecord = false; |
140 includeCurrentRecord = false; |
156 } |
141 } |
157 |
142 |
158 currentAttributeIndex = currentAttributeIndex % currentMetadata.size(); |
143 currentAttributeIndex = currentAttributeIndex % currentMetadata.size(); |