Xmipp  v3.23.11-Nereus
metadata_row_sql.h
Go to the documentation of this file.
1 /***************************************************************************
2  *
3  * Authors: J.M. De la Rosa Trevin (jmdelarosa@cnb.csic.es)
4  * Jan Horacek (xhorace4@fi.muni.cz)
5  *
6  * Unidad de Bioinformatica of Centro Nacional de Biotecnologia , CSIC
7  * Institute of Computer Science MUNI
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
22  * 02111-1307 USA
23  *
24  * All comments concerning this program package may be sent to the
25  * e-mail address 'xmipp@cnb.csic.es'
26  ***************************************************************************/
27 
28 #ifndef CORE_METADATA_ROW_SQL_H
29 #define CORE_METADATA_ROW_SQL_H
30 
31 #include "metadata_row_base.h"
32 
33 #include <array>
34 
36 class MDRowSql : public MDRow {
37 private:
38  // Reserve space for the maximum different labels
39  // this will allow constant access to each object indexing by labels
40  std::array<MDObject*, MDL_LAST_LABEL> _objects; // label to object; nullptr if none
41  std::array<MDLabel, MDL_LAST_LABEL> _order; // index to label (_order[0] = label for column 0)
42  size_t _size; // Number of active labels
43  size_t _id;
44 
45  void copy(const MDRowSql &row);
46  MDObject* iteratorValue(size_t i) override;
47  const MDObject* iteratorValue(size_t i) const override;
48 
49 public:
50  MDRowSql();
51  ~MDRowSql();
52  MDRowSql(const MDRowSql &row);
53  MDRowSql(const std::vector<MDObject> &values);
54  MDRow& operator = (const MDRow&) override;
55  MDRowSql& operator = (const MDRowSql &row);
56 
57  size_t id() const override { return this->_id; }
58  void set_id(size_t id) { this->_id = id; }
59 
60  bool empty() const override;
61  int size() const override;
62  void clear() override;
63 
64  bool containsLabel(MDLabel label) const override;
65  std::vector<MDLabel> labels() const override;
66  void addLabel(MDLabel label) override;
67 
68  MDObject *getObject(MDLabel label) override;
69  const MDObject *getObject(MDLabel label) const override;
70 
71  void setValue(const MDObject &object) override;
72 
73  friend std::ostream& operator << (std::ostream &out, const MDRowSql &row);
74 
75  // Templated functions from base class must be retemplated
76 
77  template <typename T>
78  T& getValue(MDLabel label) { return MDRow::getValue<T>(label); }
79 
80  template <typename T>
81  const T& getValue(MDLabel label) const { return MDRow::getValue<T>(label); }
82 
83  template <typename T>
84  bool getValue(MDLabel label, T &d) const { // FIXME: deprecated
85  return MDRow::getValue<T>(label, d);
86  }
87 
88  template <typename T>
89  const T& getValueOrDefault(MDLabel label, const T& def) const { return MDRow::getValueOrDefault<T>(label, def); }
90 
91  template <typename T>
92  T& getValueOrDefault(MDLabel label, const T& def) { return MDRow::getValueOrDefault<T>(label, def); }
93 
94  template <typename T, typename T1>
95  void getValueOrDefault(MDLabel label, T &d, T1 def) const { // FIXME: deprecated
96  return MDRow::getValueOrDefault<T, T1>(label, d, def);
97  }
98 
99  template <typename T>
100  void setValue(MDLabel label, const T &d, bool addLabel = true) { return MDRow::setValue<T>(label, d, addLabel); }
101 };
102 
103 #endif
friend std::ostream & operator<<(std::ostream &out, const MDRowSql &row)
const T & getValue(MDLabel label) const
int size() const override
void clear() override
#define i
doublereal * d
T & getValueOrDefault(MDLabel label, const T &def)
size_t id() const override
void set_id(size_t id)
std::vector< MDLabel > labels() const override
void setValue(const MDObject &object) override
const T & getValueOrDefault(MDLabel label, const T &def) const
void setValue(MDLabel label, const T &d, bool addLabel=true)
T & getValue(MDLabel label)
bool empty() const override
void addLabel(MDLabel label) override
bool containsLabel(MDLabel label) const override
void getValueOrDefault(MDLabel label, T &d, T1 def) const
MDRow & operator=(const MDRow &) override
bool getValue(MDLabel label, T &d) const
MDObject * getObject(MDLabel label) override
MDLabel