#pragma once #include "database/db_accessor.hpp" #include "import/fillings/common.hpp" #include "import/fillings/filler.hpp" template class ArrayFiller : public Filler { public: ArrayFiller( BaseImporter &db, typename PropertyFamily::PropertyType::PropertyFamilyKey key, T (*f)(const char *)) : bim(db), key(key), f(f) { } // Fills skeleton with data from str. Returns error description if // error occurs. Option fill(ElementSkeleton &data, char *str) final { sub_str.clear(); std::vector vec; bim.extract(str, bim.parts_array_mark, sub_str); for (auto s : sub_str) { if (s[0] != '\0') { vec.push_back(f(s)); } } if (vec.size() > 0) { data.add_property(key, make_shared(std::move(vec))); } return make_option(); } private: BaseImporter &bim; typename PropertyFamily::PropertyType::PropertyFamilyKey key; vector sub_str; T (*f)(const char *); }; template auto make_array_filler( BaseImporter &db, typename PropertyFamily::PropertyType::PropertyFamilyKey key, T (*f)(const char *)) { return new ArrayFiller(db, key, f); }