Xmipp  v3.23.11-Nereus
metadata_object.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_OBJECT_H
29 #define CORE_METADATA_OBJECT_H
30 
31 #include "metadata_label.h"
32 
33 #define _SPACE ' '
34 #define _QUOT '\''
35 #define _DQUOT '"'
36 
38 typedef union
39 {
40  bool boolValue;
41  int intValue;
42  size_t longintValue;
43  double doubleValue;
45  std::vector<double> * vectorValue;
46  std::vector<size_t> * vectorValueLong;
47  std::vector<float> * vectorValueFloat;
48 } ObjectData;
49 
54 class MDObject
55 {
56 public:
57 
59  bool failed; // Set to True if the parsing from Star files fails
60  char chr; //literal char for string, could be SPACE, QUOT or DQUOT
61 
62  void labelTypeCheck(MDLabelType checkingType) const;
63  void copy(const MDObject &obj);
64 
68  MDObject(const MDObject & obj);
70  MDObject & operator = (const MDObject &obj);
71  //Just a simple constructor with the label
72  //don't do any type checking as have not value yet
73  MDObject(MDLabel label);
76  MDObject(MDLabel label, const int &intValue);
77  MDObject(MDLabel label, const double &doubleValue);
78  MDObject(MDLabel label, const bool &boolValue);
79  MDObject(MDLabel label, const String &stringValue);
80  MDObject(MDLabel label, const std::vector<double> &vectorValue);
81  MDObject(MDLabel label, const std::vector<float> &vectorValueFloat);
82  MDObject(MDLabel label, const std::vector<size_t> &vectorValueLong);
83  MDObject(MDLabel label, const size_t &longintValue);
84 
89  MDObject(MDLabel label, const float &floatValue) = delete;
90 
95  MDObject(MDLabel label, const char * &charValue) = delete;
96 
98  ~MDObject();
99 
100  //These getValue2 also do a compilation type checking
101  //when expanding templates functions and only
102  //will allow the supported types
103  //TODO: think if the type check if needed here
104 
105  // ******* WARNING *******
106  // Methods below were orignally marked 'getValue', however they
107  // took value via parameter and set value to parameter. This behavior has
108  // changed. To force the programmer to read value from return type (no
109  // from parameter), mehotds were temporary renamed, because compiler would
110  // not otherwise fail. When whole xmipp is compiled and all occurenced of
111  // old 'getValue' are replaced with 'getValue2', these methods could be
112  // renamed back to 'getValue'.
113 
114  const int& getValue2(int) const;
115  const double& getValue2(double) const;
116  const bool& getValue2(bool) const;
117  const String& getValue2(String) const;
118  const std::vector<double>& getValue2(std::vector<double>) const;
119  const std::vector<float>& getValue2(std::vector<float>) const;
120  const std::vector<size_t>& getValue2(std::vector<size_t>) const;
121  const size_t& getValue2(size_t) const;
122  float getValue2(float) const;
123 
124  int& getValue2(int);
125  double& getValue2(double);
126  bool& getValue2(bool);
128  std::vector<double>& getValue2(std::vector<double>);
129  std::vector<float>& getValue2(std::vector<float>);
130  std::vector<size_t>& getValue2(std::vector<size_t>);
131  size_t& getValue2(size_t);
132  float getValue2(float);
133 
138  void getValue2(char*) const = delete;
139 
140  void setValue(const int &iv);
141  void setValue(const double &dv);
142  void setValue(const bool &bv);
143  void setValue(const String &sv);
144  void setValue(const std::vector<double> &vv);
145  void setValue(const std::vector<float> &vv);
146  void setValue(const std::vector<size_t> &vv);
147  void setValue(const size_t &lv);
148  void setValue(const float &floatvalue);
149  void setValue(const char* &charvalue);
150  void toStream(std::ostream &os, bool withFormat = false, bool isSql=false, bool escape=true) const;
151  String toString(bool withFormat = false, bool isSql=false) const;
152  bool fromStream(std::istream &is, bool fromString=false);
153  friend std::istream& operator>> (std::istream& is, MDObject &value);
154  friend std::ostream& operator<< (std::ostream& is, const MDObject &value);
155  bool fromString(const String &str);
156  bool fromChar(const char * str);
157 
158  bool eq(const MDObject &obj, double epsilon) const;
159  bool operator == (const MDObject &obj) const;
160  bool operator != (const MDObject &obj) const;
161  bool operator <= (const MDObject &obj) const;
162  bool operator >= (const MDObject &obj) const;
163  bool operator < (const MDObject &obj) const;
164  bool operator > (const MDObject &obj) const;
165 
166  friend class MDSql;
167 
168 private:
169  double safeDouble(const double v) const;
170  float safeFloat(const float v) const;
171 }
172 ; //close class MDObject
173 
174 #endif
void labelTypeCheck(MDLabelType checkingType) const
std::vector< size_t > * vectorValueLong
const int & getValue2(int) const
MDLabelType
bool operator>=(const MDObject &obj) const
bool operator<(const MDObject &obj) const
MDLabelType type
bool eq(const MDObject &obj, double epsilon) const
void copy(const MDObject &obj)
bool operator>(const MDObject &obj) const
bool fromStream(std::istream &is, bool fromString=false)
double vv
MDObject(const MDObject &obj)
MDLabel label
size_t longintValue
friend std::istream & operator>>(std::istream &is, MDObject &value)
std::vector< double > * vectorValue
ObjectData data
bool fromString(const String &str)
bool operator!=(const MDObject &obj) const
bool fromChar(const char *str)
bool operator<=(const MDObject &obj) const
basic_istream< char, std::char_traits< char > > istream
Definition: utilities.cpp:815
String toString(bool withFormat=false, bool isSql=false) const
std::vector< float > * vectorValueFloat
std::string String
Definition: xmipp_strings.h:34
void setValue(const int &iv)
void toStream(std::ostream &os, bool withFormat=false, bool isSql=false, bool escape=true) const
double doubleValue
bool operator==(const MDObject &obj) const
~MDObject()
Destructor.
void(* obj)()
friend std::ostream & operator<<(std::ostream &is, const MDObject &value)
String * stringValue
double epsilon
MDLabel
MDObject & operator=(const MDObject &obj)