71 for (
const auto label : labelsVector) {
95 if ((labelIndex < 0) || (static_cast<size_t>(labelIndex) >= row.size()))
97 return row.at(labelIndex);
104 return row.at(labelIndex);
132 if (extFile ==
"xml")
134 else if (extFile ==
"sqlite")
135 throw NotImplemented(
"Reading from .sqlite file into MetaDataVec not implemented!");
137 this->
readStar(filename, desiredLabels, blockName, decomposeStack);
146 if (blockName.empty())
151 if (extFile ==
"xml") {
152 writeXML(_outFile, blockName, mode);
153 }
else if (extFile ==
"sqlite") {
154 throw NotImplemented(
"Writing to .sqlite file from MetaDataVec not implemented!");
181 if (dynamic_cast<const MDRowVec*>(&row) !=
nullptr) {
184 if ((mdRowVec._in_metadata) && (mdRowVec._rowi ==
index) && (mdRowVec._row == &this->_rows[index]))
188 size_t newRowSize = 0;
193 newRowSize = this->
size();
199 for (
size_t column = 0; (column < this->
_col_to_label.size()) && (column < newRowSize); ++column)
213 for (
size_t coli = 0; coli < this->
_no_columns; coli++)
214 editRow.push_back({this->_col_to_label[coli]});
234 _rows.emplace_back(newRow);
262 for (
const auto row : rows)
271 const auto &label = mdValueIn.
label;
273 if (labelIndex < 0) {
278 for (
auto &r :
_rows) r[labelIndex] = mdValueIn;
314 return memoryUtils::make_unique<MDRowVec>(
323 return memoryUtils::make_unique<MDRowVec>(
359 return row.at(labelIndex).getValue2(
size_t());
367 for (
const auto& vecRow : this->
_rows)
368 valuesOut.emplace_back(vecRow.at(labelIndex));
372 for (
size_t i = 0;
i <
std::min(valuesIn.size(), this->
_rows.size());
i++) {
380 this->
_rows[
i][labelIndex] = valuesIn[
i];
390 return this->
_rows.empty();
394 return this->
_rows.size();
419 for (
auto& vecRow : this->
_rows)
420 if (static_cast<int>(vecRow.size()) > column)
421 vecRow.erase(vecRow.begin()+column);
447 std::unique_ptr<const MDRow> row = md.
getRow(
id);
464 for (
size_t objId : objectsToAdd)
470 std::vector<size_t>
ids;
483 for (
size_t j = i;
j < this->
_rows.size();
j++)
490 for (
size_t id : toRemove)
495 size_t count = this->
size();
502 std::vector<size_t>
ids;
517 if (dynamic_cast<const MDMultiQuery*>(&query) !=
nullptr) {
524 assert(op == operation);
525 for (
const auto& q : mq.
queries) {
526 if ((operation ==
"AND") && (!this->
_match(row, *q)))
528 else if ((operation ==
"OR") && (this->
_match(row, *q)))
531 return (operation ==
"AND");
534 if (dynamic_cast<const MDValueRelational*>(&query) ==
nullptr)
535 throw NotImplemented(
"_match for this type of query not implemented");
541 if (rel.
value ==
nullptr)
545 if (labeli >= row.size())
548 const MDObject& mdObj = row[labeli];
551 return *(rel.
value) == mdObj;
553 return *(rel.
value) != mdObj;
555 return *(rel.
value) < mdObj;
557 return *(rel.
value) <= mdObj;
559 return *(rel.
value) > mdObj;
561 return *(rel.
value) >= mdObj;
563 throw std::logic_error(
"MetaDataVec::_match: unknown operator");
569 if (this->
_match(row, query))
578 if (this->
_match(row, query))
579 objectsOut.emplace_back(this->
getRowId(row));
584 for (
size_t i = 0; i < std::min<size_t>(limit, this->
size());
i++)
585 objectsOut.emplace_back(this->getRowId(this->_rows[
i]));
591 if (this->
_match(row, query))
602 if (this->
_match(row, query))
618 if (this->
_labelIndex(label) < static_cast<int>(row.size()))
636 String _szBlockName(
"data_");
637 _szBlockName += blockName;
641 os << _szBlockName <<
'\n';
642 os <<
"loop_" <<
'\n';
650 os << _szBlockName <<
'\n';
653 assert(this->
_rows.size() == 1);
670 const std::vector<MDLabel> *desiredLabels,
bool firstTime) {
671 for (
size_t i = 0;
i < columnValues.size();
i++) {
672 columnValues[
i]->fromStream(is);
677 columnValues[
i]->failed =
true;
678 std::cerr <<
"WARNING: " << errorMsg << std::endl;
680 }
else if (firstTime) {
684 bool reallyAdd=
false;
685 if (desiredLabels == NULL) {
689 for (
size_t j = 0;
j < desiredLabels->size(); ++
j) {
690 if ((*desiredLabels)[
j] == columnValues[
i]->label) {
706 for (
size_t i = 0;
i < columnValues.size();
i++)
707 if (columnValues[
i] !=
nullptr)
743 std::random_device rd;
744 auto g = std::mt19937(rd());
745 std::shuffle(this->
_rows.begin(), this->
_rows.end(),
g);
751 for (
size_t i = 0;
i < this->
_rows.size();
i++)
757 std::vector<MetaDataVecRow> new_rows;
758 for (
const auto& row : this->
_rows) {
760 new_rows.emplace_back(row);
762 this->_rows = new_rows;
766 for (
const auto& _row : rows)
777 int labeli = this->
_labelIndex(static_cast<MDLabel>(label));
779 if ((static_cast<size_t>(labeli) < a.size()) !=
780 (static_cast<size_t>(labeli) < b.size()))
782 if (static_cast<size_t>(labeli) >= a.size())
795 if (label_index > -1) {
799 return a[label_index] <
b[label_index];
800 return a[label_index] > b[label_index];
805 if ((limit > 0) && (limit < this->
_rows.size()))
819 if (parts > this->
size())
820 REPORT_ERROR(
ERR_MD,
"MetaDataDb::split: Couldn't split a metadata in more parts than its size");
823 sorted.
sort(*
this, sortLabel);
826 results.resize(parts);
827 for (
size_t i = 0;
i < parts;
i++) {
829 size_t firsti, lasti;
831 for (
size_t j = firsti;
j <= lasti;
j++)
843 this->
sort(mdIn, sortLabel,
true, numberOfObjects, startPosition);
852 generator.
label = label;
853 generator.
fill(*
this);
859 generator.
label = label;
860 generator.
fill(*
this);
866 generator.
label = label;
867 generator.
fill(*
this);
881 if (labeli < row.size())
884 for (
size_t i = row.size();
i <= labeli;
i++)
898 if (static_cast<size_t>(labeldesti) >= row.size())
899 this->
_expand(row, labeldesti);
901 if (static_cast<size_t>(labelsrci) < row.size()) {
902 row[labeldesti] = row[labelsrci];
903 row[labeldesti].label = labelDest;
924 for (
auto& row : this->
_rows) {
925 if (labeloldi < static_cast<int>(row.size()))
926 row[labeloldi].label = newLabel;
931 const std::vector<MDLabel> &newLabel) {
947 for (
size_t i = 0;
i < this->
_rows.size();
i++) {
954 if (thisLabelColI > -1) {
955 if ((static_cast<size_t>(thisLabelColI) < this->
_rows[
i].size()) !=
956 (static_cast<size_t>(opLabelColI) < op.
_rows[
i].size()))
958 if (static_cast<size_t>(thisLabelColI) >= this->
_rows[
i].size())
960 if (!this->
_rows[
i][thisLabelColI].
eq(op.
_rows[
i][opLabelColI], this->precision()))
970 std::vector<MDLabel> out;
973 out.emplace_back(static_cast<MDLabel>(
i));
std::vector< String > operations
void min(Image< double > &op1, const Image< double > &op2)
Case or algorithm not implemented yet.
const int & getValue2(int) const
String getBlockName() const
#define REPORT_ERROR(nerr, ErrormMsg)
void setValue(const MDObject &object) override
size_t divide_equally(size_t N, size_t size, size_t rank, size_t &first, size_t &last)
String WordWrap(const String &inputString, size_t lineLength)
String getExtension() const
T & getValue(MDLabel label)
void eq(Image< double > &op1, const Image< double > &op2)
Be careful with integer images for relational operations...due to double comparisons.
basic_istream< char, std::char_traits< char > > istream
void sort(struct DCEL_T *dcel)
String escapeForRegularExpressions(const String &str)
FileName removeBlockName() const
virtual bool containsLabel(MDLabel label) const =0
String formatString(const char *format,...)
void toStream(std::ostream &os, bool withFormat=false, bool isSql=false, bool escape=true) const
static String label2Str(const MDLabel &label)
std::vector< const MDQuery * > queries