shared_ptr<IFeature> BaseTagHDF5::createFeature(const std::string &name_or_id, LinkType link_type) { if(!block()->hasDataArray(name_or_id)) { throw std::runtime_error("DataArray not found in Block!"); } string rep_id = util::createId(); boost::optional<Group> g = feature_group(true); Group group = g->openGroup(rep_id, true); DataArray data = block()->getDataArray(name_or_id); return make_shared<FeatureHDF5>(file(), block(), group, rep_id, data, link_type); }
std::shared_ptr<IFeature> BaseTagHDF5::createFeature(const std::string &name_or_id, LinkType link_type) { if(!block()->hasEntity({name_or_id, ObjectType::DataArray})) { throw std::runtime_error("DataArray not found in Block!"); } std::string rep_id = util::createId(); boost::optional<H5Group> g = feature_group(true); H5Group group = g->openGroup(rep_id, true); DataArray data = std::dynamic_pointer_cast<IDataArray>(block()->getEntity({name_or_id, ObjectType::DataArray})); return std::make_shared<FeatureHDF5>(file(), block(), group, rep_id, data, link_type); }
shared_ptr<IFeature> BaseTagHDF5::getFeature(const std::string &name_or_id) const { shared_ptr<FeatureHDF5> feature; boost::optional<Group> g = feature_group(); if (g) { boost::optional<Group> group = g->findGroupByNameOrAttribute("entity_id", name_or_id); if (group) feature = make_shared<FeatureHDF5>(file(), block(), group.get()); } return feature; }
bool BaseTagHDF5::deleteFeature(const string &name_or_id) { boost::optional<Group> g = feature_group(); bool deleted = false; if (g && hasFeature(name_or_id)) { shared_ptr<IFeature> feature = getFeature(name_or_id); g->removeGroup(feature->id()); deleted = true; } return deleted; }
std::shared_ptr<IFeature> BaseTagHDF5::getFeature(const std::string &name_or_id) const { std::shared_ptr<FeatureHDF5> feature; boost::optional<H5Group> g = feature_group(false); if (g) { boost::optional<H5Group> group = g->findGroupByNameOrAttribute("name", name_or_id); if (group) feature = std::make_shared<FeatureHDF5>(file(), block(), group.get()); else { for (ndsize_t i = 0; i < g->objectCount(); i++) { H5Group gr = g->openGroup(g->objectName(i), false); std::shared_ptr<FeatureHDF5> feat = std::make_shared<FeatureHDF5>(file(), block(), gr); std::shared_ptr<base::IDataArray> da = feat->data(); if (da->name() == name_or_id || da->id() == name_or_id) { feature = std::make_shared<FeatureHDF5>(file(), block(), gr); break; } } } } return feature; }
shared_ptr<IFeature> BaseTagHDF5::getFeature(size_t index) const { boost::optional<Group> g = feature_group(); string id = g->objectName(index); return getFeature(id); }
ndsize_t BaseTagHDF5::featureCount() const { boost::optional<Group> g = feature_group(); return g ? g->objectCount() : size_t(0); }