Xmipp  v3.23.11-Nereus
metadata_row_vec.h
Go to the documentation of this file.
1 /***************************************************************************
2  *
3  * Authors: Jan Horacek (xhorace4@fi.muni.cz)
4  *
5  * Unidad de Bioinformatica of Centro Nacional de Biotecnologia , CSIC
6  * Institute of Computer Science MUNI
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21  * 02111-1307 USA
22  *
23  * All comments concerning this program package may be sent to the
24  * e-mail address 'xmipp@cnb.csic.es'
25  ***************************************************************************/
26 
27 #ifndef CORE_METADATA_ROW_VEC_H
28 #define CORE_METADATA_ROW_VEC_H
29 
30 #include "metadata_row_base.h"
31 
32 #include <array>
33 
46 class MDRowVec : public MDRow {
47 private:
48  std::vector<MDObject>* _row;
49  size_t _rowi;
50  std::array<int, MDL_LAST_LABEL>* _label_to_col;
51  std::vector<MDLabel>* _col_to_label;
52  size_t* _no_columns; // global number of columns in whole MetaData
53  bool _in_metadata;
54 
55  MDObject* iteratorValue(size_t i) override;
56  const MDObject* iteratorValue(size_t i) const override;
57  size_t newCol(const MDLabel);
58 
59 public:
60  static MDRowVec deepCopy(const MDRowVec&);
61 
62  MDRowVec();
63  MDRowVec(std::vector<MDObject>& row, size_t rowi, std::array<int, MDL_LAST_LABEL>& label_to_col,
64  std::vector<MDLabel>& col_to_label, size_t& no_columns);
65  MDRowVec(const std::vector<MDObject>& row, size_t rowi, const std::array<int, MDL_LAST_LABEL>& label_to_col,
66  const std::vector<MDLabel>& col_to_label, const size_t& no_columns);
67  MDRowVec(const MDRowVec&);
68  MDRowVec& operator = (const MDRowVec&);
69  MDRow& operator = (const MDRow& row);
70  virtual ~MDRowVec();
71 
72  void detach() override;
73 
74  bool empty() const override;
75  int size() const override;
76  void clear() override;
77  bool inMetadata() const;
78 
79  bool containsLabel(MDLabel label) const override;
80  std::vector<MDLabel> labels() const override;
81  void addLabel(MDLabel label) override;
82 
83  MDObject *getObject(MDLabel label) override;
84  const MDObject *getObject(MDLabel label) const override;
85 
86  void setValue(const MDObject &object) override;
87 
88  friend std::ostream& operator << (std::ostream &out, const MDRowVec &row);
89 
90  // Templated functions from based class must be retemplated
91 
92  template <typename T>
93  T& getValue(MDLabel label) { return MDRow::getValue<T>(label); }
94 
95  template <typename T>
96  const T& getValue(MDLabel label) const { return MDRow::getValue<T>(label); }
97 
98  template <typename T>
99  bool getValue(MDLabel label, T &d) const { // FIXME: deprecated
100  return MDRow::getValue<T>(label, d);
101  }
102 
103  template <typename T>
104  const T& getValueOrDefault(MDLabel label, const T& def) const { return MDRow::getValueOrDefault<T>(label, def); }
105 
106  template <typename T>
107  T& getValueOrDefault(MDLabel label, const T& def) { return MDRow::getValueOrDefault<T>(label, def); }
108 
109  template <typename T, typename T1>
110  void getValueOrDefault(MDLabel label, T &d, T1 def) const { // FIXME: deprecated
111  return MDRow::getValueOrDefault<T, T1>(label, d, def);
112  }
113 
114  template <typename T>
115  void setValue(MDLabel label, const T &d, bool addLabel = true) { return MDRow::setValue<T>(label, d, addLabel); }
116 
117  friend class MetaDataVec;
118 };
119 
120 #endif
void setValue(MDLabel label, const T &d, bool addLabel=true)
static MDRowVec deepCopy(const MDRowVec &)
int size() const override
void setValue(const MDObject &object) override
bool inMetadata() const
const T & getValueOrDefault(MDLabel label, const T &def) const
friend std::ostream & operator<<(std::ostream &out, const MDRowVec &row)
T & getValueOrDefault(MDLabel label, const T &def)
bool containsLabel(MDLabel label) const override
#define i
doublereal * d
T & getValue(MDLabel label)
MDObject * getObject(MDLabel label) override
std::vector< MDLabel > labels() const override
void addLabel(MDLabel label) override
MDRowVec & operator=(const MDRowVec &)
virtual ~MDRowVec()
bool getValue(MDLabel label, T &d) const
bool empty() const override
void detach() override
void clear() override
void getValueOrDefault(MDLabel label, T &d, T1 def) const
const T & getValue(MDLabel label) const
MDLabel