Xmipp  v3.23.11-Nereus
Public Member Functions | Public Attributes | Friends | List of all members
MDObject Class Reference

#include <metadata_object.h>

Collaboration diagram for MDObject:
Collaboration graph
[legend]

Public Member Functions

void labelTypeCheck (MDLabelType checkingType) const
 
void copy (const MDObject &obj)
 
 MDObject (const MDObject &obj)
 
MDObjectoperator= (const MDObject &obj)
 
 MDObject (MDLabel label)
 
 MDObject (MDLabel label, const int &intValue)
 
 MDObject (MDLabel label, const double &doubleValue)
 
 MDObject (MDLabel label, const bool &boolValue)
 
 MDObject (MDLabel label, const String &stringValue)
 
 MDObject (MDLabel label, const std::vector< double > &vectorValue)
 
 MDObject (MDLabel label, const std::vector< float > &vectorValueFloat)
 
 MDObject (MDLabel label, const std::vector< size_t > &vectorValueLong)
 
 MDObject (MDLabel label, const size_t &longintValue)
 
 MDObject (MDLabel label, const float &floatValue)=delete
 
 MDObject (MDLabel label, const char *&charValue)=delete
 
 ~MDObject ()
 Destructor. More...
 
const int & getValue2 (int) const
 
const double & getValue2 (double) const
 
const bool & getValue2 (bool) const
 
const StringgetValue2 (String) const
 
const std::vector< double > & getValue2 (std::vector< double >) const
 
const std::vector< float > & getValue2 (std::vector< float >) const
 
const std::vector< size_t > & getValue2 (std::vector< size_t >) const
 
const size_t & getValue2 (size_t) const
 
float getValue2 (float) const
 
int & getValue2 (int)
 
double & getValue2 (double)
 
bool & getValue2 (bool)
 
StringgetValue2 (String)
 
std::vector< double > & getValue2 (std::vector< double >)
 
std::vector< float > & getValue2 (std::vector< float >)
 
std::vector< size_t > & getValue2 (std::vector< size_t >)
 
size_t & getValue2 (size_t)
 
float getValue2 (float)
 
void getValue2 (char *) const =delete
 
void setValue (const int &iv)
 
void setValue (const double &dv)
 
void setValue (const bool &bv)
 
void setValue (const String &sv)
 
void setValue (const std::vector< double > &vv)
 
void setValue (const std::vector< float > &vv)
 
void setValue (const std::vector< size_t > &vv)
 
void setValue (const size_t &lv)
 
void setValue (const float &floatvalue)
 
void setValue (const char *&charvalue)
 
void toStream (std::ostream &os, bool withFormat=false, bool isSql=false, bool escape=true) const
 
String toString (bool withFormat=false, bool isSql=false) const
 
bool fromStream (std::istream &is, bool fromString=false)
 
bool fromString (const String &str)
 
bool fromChar (const char *str)
 
bool eq (const MDObject &obj, double epsilon) const
 
bool operator== (const MDObject &obj) const
 
bool operator!= (const MDObject &obj) const
 
bool operator<= (const MDObject &obj) const
 
bool operator>= (const MDObject &obj) const
 
bool operator< (const MDObject &obj) const
 
bool operator> (const MDObject &obj) const
 

Public Attributes

ObjectData data = {0}
 
bool failed
 
char chr
 
MDLabel label
 
MDLabelType type = LABEL_INT
 

Friends

class MDSql
 
std::istream & operator>> (std::istream &is, MDObject &value)
 
std::ostream & operator<< (std::ostream &is, const MDObject &value)
 

Detailed Description

MDObject stores single MetaData value. Each column in each metadata row contains MDObject. It can contain multiple types of data (see ObjectData).

Definition at line 54 of file metadata_object.h.

Constructor & Destructor Documentation

◆ MDObject() [1/12]

MDObject::MDObject ( const MDObject obj)

Copy constructor

Definition at line 81 of file metadata_object.cpp.

82 {
83  copy(obj);
84 }
void copy(const MDObject &obj)

◆ MDObject() [2/12]

MDObject::MDObject ( MDLabel  label)

Definition at line 105 of file metadata_object.cpp.

106 {
107  this->label = label;
108  failed = false;
109  chr = _SPACE;
110  if (label != MDL_UNDEFINED)
111  {
113  if (type == LABEL_STRING)
114  data.stringValue = new String;
115  else if (type == LABEL_VECTOR_DOUBLE)
116  data.vectorValue = new std::vector<double>;
117  else if (type == LABEL_VECTOR_SIZET)
118  data.vectorValueLong = new std::vector<size_t>;
119  }
120  else
121  type = LABEL_NOTYPE;
122 }
std::vector< size_t > * vectorValueLong
MDLabelType type
static MDLabelType labelType(const MDLabel label)
MDLabel label
std::vector< double > * vectorValue
ObjectData data
#define _SPACE
std::string String
Definition: xmipp_strings.h:34
String * stringValue

◆ MDObject() [3/12]

MDObject::MDObject ( MDLabel  label,
const int &  v 
)

Constructors for each Label supported type these constructor will do the labels type checking

Definition at line 129 of file metadata_object.cpp.

130 {
131  MDOBJECT_INIT();
132  this->setValue(v);
133 }
void setValue(const int &iv)
#define MDOBJECT_INIT()
Macro to do some basic initialization.

◆ MDObject() [4/12]

MDObject::MDObject ( MDLabel  label,
const double &  doubleValue 
)

Definition at line 134 of file metadata_object.cpp.

135 {
136  MDOBJECT_INIT();
137  this->setValue(v);
138 }
void setValue(const int &iv)
#define MDOBJECT_INIT()
Macro to do some basic initialization.

◆ MDObject() [5/12]

MDObject::MDObject ( MDLabel  label,
const bool &  boolValue 
)

Definition at line 139 of file metadata_object.cpp.

140 {
141  MDOBJECT_INIT();
142  this->setValue(v);
143 }
void setValue(const int &iv)
#define MDOBJECT_INIT()
Macro to do some basic initialization.

◆ MDObject() [6/12]

MDObject::MDObject ( MDLabel  label,
const String stringValue 
)

Definition at line 144 of file metadata_object.cpp.

145 {
146  MDOBJECT_INIT();
147  this->data.stringValue = new String();
148  this->setValue(v);
149 }
ObjectData data
std::string String
Definition: xmipp_strings.h:34
void setValue(const int &iv)
String * stringValue
#define MDOBJECT_INIT()
Macro to do some basic initialization.

◆ MDObject() [7/12]

MDObject::MDObject ( MDLabel  label,
const std::vector< double > &  vectorValue 
)

Definition at line 150 of file metadata_object.cpp.

151 {
152  MDOBJECT_INIT();
153  this->data.vectorValue = new std::vector<double>();
154  this->setValue(v);
155 }
std::vector< double > * vectorValue
ObjectData data
void setValue(const int &iv)
#define MDOBJECT_INIT()
Macro to do some basic initialization.

◆ MDObject() [8/12]

MDObject::MDObject ( MDLabel  label,
const std::vector< float > &  vectorValueFloat 
)

◆ MDObject() [9/12]

MDObject::MDObject ( MDLabel  label,
const std::vector< size_t > &  vectorValueLong 
)

Definition at line 156 of file metadata_object.cpp.

157 {
158  MDOBJECT_INIT();
159  this->data.vectorValueLong = new std::vector<size_t>();
160  this->setValue(v);
161 }
std::vector< size_t > * vectorValueLong
ObjectData data
void setValue(const int &iv)
#define MDOBJECT_INIT()
Macro to do some basic initialization.

◆ MDObject() [10/12]

MDObject::MDObject ( MDLabel  label,
const size_t &  longintValue 
)

Definition at line 162 of file metadata_object.cpp.

163 {
164  MDOBJECT_INIT();
165  this->setValue(v);
166 }
void setValue(const int &iv)
#define MDOBJECT_INIT()
Macro to do some basic initialization.

◆ MDObject() [11/12]

MDObject::MDObject ( MDLabel  label,
const float &  floatValue 
)
delete

Do not use MDObject constructor with floats, use double. Floats are banned from metadata class.

◆ MDObject() [12/12]

MDObject::MDObject ( MDLabel  label,
const char *&  charValue 
)
delete

Do not use MDObject constructor with char, use string. Chars are banned from metadata class.

◆ ~MDObject()

MDObject::~MDObject ( )

Destructor.

Definition at line 168 of file metadata_object.cpp.

169 {
170  if (type == LABEL_STRING)
171  delete data.stringValue;
172  else if (type == LABEL_VECTOR_DOUBLE)
173  delete data.vectorValue;
174  else if (type == LABEL_VECTOR_SIZET)
175  delete data.vectorValueLong;
176 }
std::vector< size_t > * vectorValueLong
MDLabelType type
std::vector< double > * vectorValue
ObjectData data
String * stringValue

Member Function Documentation

◆ copy()

void MDObject::copy ( const MDObject obj)

Definition at line 48 of file metadata_object.cpp.

49 {
50  if ((type == LABEL_STRING) && (data.stringValue != nullptr))
51  {
52  delete data.stringValue;
53  data.stringValue = nullptr;
54  }
55  else if ((type == LABEL_VECTOR_DOUBLE) && (data.vectorValue != nullptr))
56  {
57  delete data.vectorValue;
58  data.vectorValue = nullptr;
59  }
60  else if ((type == LABEL_VECTOR_SIZET) && (data.vectorValueLong != nullptr))
61  {
62  delete data.vectorValueLong;
63  data.vectorValueLong = nullptr;
64  }
65 
66  label = obj.label;
67  failed = obj.failed;
68  type = obj.type;
69  chr = obj.chr;
70 
71  if (type == LABEL_STRING)
72  data.stringValue = new String(*(obj.data.stringValue));
73  else if (type == LABEL_VECTOR_DOUBLE)
74  data.vectorValue = new std::vector<double>(*(obj.data.vectorValue));
75  else if (type == LABEL_VECTOR_SIZET)
76  data.vectorValueLong = new std::vector<size_t>(*(obj.data.vectorValueLong));
77  else
78  data = obj.data;
79 }
std::vector< size_t > * vectorValueLong
MDLabelType type
MDLabel label
std::vector< double > * vectorValue
ObjectData data
std::string String
Definition: xmipp_strings.h:34
String * stringValue

◆ eq()

bool MDObject::eq ( const MDObject obj,
double  epsilon 
) const

Definition at line 539 of file metadata_object.cpp.

539  {
540  // FIXME: allow to compare e.g. int & double & longint
541  if (this->label != obj.label)
542  return false;
543 
544  if (this->type != obj.type)
545  throw std::logic_error("MDObject: cannot compare == objects of different type");
546 
547  switch (this->type) {
548  case LABEL_INT:
549  return this->data.intValue == obj.data.intValue;
550 
551  case LABEL_BOOL:
552  return this->data.boolValue == obj.data.boolValue;
553 
554  case LABEL_SIZET:
555  return this->data.longintValue == obj.data.longintValue;
556 
557  case LABEL_DOUBLE:
558  return std::abs(this->data.doubleValue - obj.data.doubleValue) <= epsilon;
559 
560  case LABEL_STRING:
561  return *(this->data.stringValue) == *(obj.data.stringValue);
562 
563  case LABEL_VECTOR_DOUBLE:
564  if (this->data.vectorValue->size() != obj.data.vectorValue->size())
565  return false;
566  for (size_t i = 0; i < this->data.vectorValue->size(); i++)
567  if (std::abs((*this->data.vectorValue)[i] - (*obj.data.vectorValue)[i]) > epsilon)
568  return false;
569  return true;
570 
571  case LABEL_VECTOR_SIZET:
572  return *(this->data.vectorValueLong) == *(obj.data.vectorValueLong);
573 
574  default:
575  throw std::logic_error("MDObject: unknown data type");
576  };
577 }
std::vector< size_t > * vectorValueLong
void abs(Image< double > &op)
MDLabelType type
#define i
MDLabel label
size_t longintValue
std::vector< double > * vectorValue
ObjectData data
double doubleValue
String * stringValue
double epsilon

◆ fromChar()

bool MDObject::fromChar ( const char *  str)

Definition at line 529 of file metadata_object.cpp.

530 {
531  std::stringstream ss(szChar);
532  return fromStream(ss);
533 }
bool fromStream(std::istream &is, bool fromString=false)

◆ fromStream()

bool MDObject::fromStream ( std::istream &  is,
bool  fromString = false 
)

Definition at line 438 of file metadata_object.cpp.

439 {
440  if (label == MDL_UNDEFINED) //if undefine label, store as a literal string
441  {
442  String s;
443  is >> s;
444  }
445  else
446  {
447  //NOTE: int, bool and long(size_t) are read as double for compatibility with old doc files
448  double d;
449  size_t value;
450  switch (type)
451  {
452  case LABEL_BOOL: //bools are int in sqlite3
453  is >> d;
454  data.boolValue = (bool) ((int)d);
455  break;
456  case LABEL_INT:
457  is >> d;
458  data.intValue = (int) d;
459  break;
460  case LABEL_SIZET:
461  is >> d;
462  data.longintValue = (size_t) d;
463  break;
464  case LABEL_DOUBLE:
465  is >> data.doubleValue;
466  break;
467  case LABEL_STRING:
468  {
469  data.stringValue->clear();
470  String s;
471  is >> s;
472  char chr = s[0];
473  if (chr == _QUOT || chr == _DQUOT)
474  {
475  s = s.substr(1, s.size() - 1); //remove first char '
476  while (s.find_last_of(chr) == String::npos)
477  {
478  data.stringValue->append(s + " ");
479  is >> s;
480  }
481  s = s.substr(0, s.size() - 1); //remove last char '
482  }
483  data.stringValue->append(s);
484  }
485  break;
486  case LABEL_VECTOR_DOUBLE:
487  if (!fromString)
488  is.ignore(256, _QUOT);
489  //if (data.vectorValue == NULL)
490  // data.vectorValue = new std::vector<double>;
491  data.vectorValue->clear();
492  while (is >> d) //This will stop at ending "]"
493  data.vectorValue->emplace_back(d);
494  if (!fromString)
495  {
496  is.clear(); //this is for clear the fail state after found ']'
497  is.ignore(256, _QUOT); //ignore the ending ']'
498  }
499  break;
500  case LABEL_VECTOR_SIZET:
501  if (!fromString)
502  is.ignore(256, _QUOT);
503  //if (data.vectorValue == NULL)
504  // data.vectorValue = new std::vector<double>;
505  data.vectorValueLong->clear();
506  while (is >> value) //This will stop at ending "]"
507  data.vectorValueLong->emplace_back(value);
508  if (!fromString)
509  {
510  is.clear(); //this is for clear the fail state after found ']'
511  is.ignore(256, _QUOT); //ignore the ending ']'
512  }
513  break;
514  case LABEL_NOTYPE:
515  break;
516  }
517  }
518  return is.good();
519 }
#define _DQUOT
std::vector< size_t > * vectorValueLong
MDLabelType type
doublereal * d
MDLabel label
size_t longintValue
std::vector< double > * vectorValue
ObjectData data
bool fromString(const String &str)
#define _QUOT
std::string String
Definition: xmipp_strings.h:34
double doubleValue
String * stringValue

◆ fromString()

bool MDObject::fromString ( const String str)

Definition at line 521 of file metadata_object.cpp.

522 {
523  if (type == LABEL_STRING)
524  *data.stringValue = str;
525  std::stringstream ss(str);
526  return fromStream(ss, true);
527 }
MDLabelType type
bool fromStream(std::istream &is, bool fromString=false)
ObjectData data
String * stringValue

◆ getValue2() [1/19]

const int & MDObject::getValue2 ( int  ) const

Definition at line 188 of file metadata_object.cpp.

188  {
190  return this->data.intValue;
191 }
void labelTypeCheck(MDLabelType checkingType) const
ObjectData data

◆ getValue2() [2/19]

const double & MDObject::getValue2 ( double  ) const

Definition at line 198 of file metadata_object.cpp.

198  {
200  return this->data.doubleValue;
201 }
void labelTypeCheck(MDLabelType checkingType) const
ObjectData data
double doubleValue

◆ getValue2() [3/19]

const bool & MDObject::getValue2 ( bool  ) const

Definition at line 208 of file metadata_object.cpp.

208  {
210  return this->data.boolValue;
211 }
void labelTypeCheck(MDLabelType checkingType) const
ObjectData data

◆ getValue2() [4/19]

const String & MDObject::getValue2 ( String  ) const

Definition at line 218 of file metadata_object.cpp.

218  {
220  return *(this->data.stringValue);
221 }
void labelTypeCheck(MDLabelType checkingType) const
ObjectData data
String * stringValue

◆ getValue2() [5/19]

const std::vector< double > & MDObject::getValue2 ( std::vector< double >  ) const

Definition at line 228 of file metadata_object.cpp.

228  {
230  return *(this->data.vectorValue);
231 }
void labelTypeCheck(MDLabelType checkingType) const
std::vector< double > * vectorValue
ObjectData data

◆ getValue2() [6/19]

const std::vector< float > & MDObject::getValue2 ( std::vector< float >  ) const

Definition at line 238 of file metadata_object.cpp.

238  {
240  return *(this->data.vectorValueFloat);
241 }
void labelTypeCheck(MDLabelType checkingType) const
ObjectData data
std::vector< float > * vectorValueFloat

◆ getValue2() [7/19]

const std::vector< size_t > & MDObject::getValue2 ( std::vector< size_t >  ) const

Definition at line 248 of file metadata_object.cpp.

248  {
250  return *(this->data.vectorValueLong);
251 }
void labelTypeCheck(MDLabelType checkingType) const
std::vector< size_t > * vectorValueLong
ObjectData data

◆ getValue2() [8/19]

const size_t & MDObject::getValue2 ( size_t  ) const

Definition at line 258 of file metadata_object.cpp.

258  {
260  return this->data.longintValue;
261 }
void labelTypeCheck(MDLabelType checkingType) const
size_t longintValue
ObjectData data

◆ getValue2() [9/19]

float MDObject::getValue2 ( float  ) const

Definition at line 267 of file metadata_object.cpp.

267  {
268  return getValue2(0.); // double
269 }
const int & getValue2(int) const

◆ getValue2() [10/19]

int & MDObject::getValue2 ( int  )

Definition at line 183 of file metadata_object.cpp.

183  {
185  return this->data.intValue;
186 }
void labelTypeCheck(MDLabelType checkingType) const
ObjectData data

◆ getValue2() [11/19]

double & MDObject::getValue2 ( double  )

Definition at line 193 of file metadata_object.cpp.

193  {
195  return this->data.doubleValue;
196 }
void labelTypeCheck(MDLabelType checkingType) const
ObjectData data
double doubleValue

◆ getValue2() [12/19]

bool & MDObject::getValue2 ( bool  )

Definition at line 203 of file metadata_object.cpp.

203  {
205  return this->data.boolValue;
206 }
void labelTypeCheck(MDLabelType checkingType) const
ObjectData data

◆ getValue2() [13/19]

String & MDObject::getValue2 ( String  )

Definition at line 213 of file metadata_object.cpp.

213  {
215  return *(this->data.stringValue);
216 }
void labelTypeCheck(MDLabelType checkingType) const
ObjectData data
String * stringValue

◆ getValue2() [14/19]

std::vector< double > & MDObject::getValue2 ( std::vector< double >  )

Definition at line 223 of file metadata_object.cpp.

223  {
225  return *(this->data.vectorValue);
226 }
void labelTypeCheck(MDLabelType checkingType) const
std::vector< double > * vectorValue
ObjectData data

◆ getValue2() [15/19]

std::vector< float > & MDObject::getValue2 ( std::vector< float >  )

Definition at line 233 of file metadata_object.cpp.

233  {
235  return *(this->data.vectorValueFloat);
236 }
void labelTypeCheck(MDLabelType checkingType) const
ObjectData data
std::vector< float > * vectorValueFloat

◆ getValue2() [16/19]

std::vector< size_t > & MDObject::getValue2 ( std::vector< size_t >  )

Definition at line 243 of file metadata_object.cpp.

243  {
245  return *(this->data.vectorValueLong);
246 }
void labelTypeCheck(MDLabelType checkingType) const
std::vector< size_t > * vectorValueLong
ObjectData data

◆ getValue2() [17/19]

size_t & MDObject::getValue2 ( size_t  )

Definition at line 253 of file metadata_object.cpp.

253  {
255  return this->data.longintValue;
256 }
void labelTypeCheck(MDLabelType checkingType) const
size_t longintValue
ObjectData data

◆ getValue2() [18/19]

float MDObject::getValue2 ( float  )

Definition at line 263 of file metadata_object.cpp.

263  {
264  return getValue2(0.); // double
265 }
const int & getValue2(int) const

◆ getValue2() [19/19]

void MDObject::getValue2 ( char *  ) const
delete

Do not use getValue2 with char, use string. chars are banned from metadata class.

◆ labelTypeCheck()

void MDObject::labelTypeCheck ( MDLabelType  checkingType) const
inline

Definition at line 92 of file metadata_object.cpp.

93 {
94  if (this->type != checkingType)
95  {
96  std::stringstream ss;
97  ss << "Mismatch Label (" << MDL::label2Str(label)
98  << ") and value type(" << MDL::labelType2Str(checkingType) << ")";
99  REPORT_ERROR(ERR_MD_BADLABEL, ss.str());
100  }
101 }
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
static String labelType2Str(MDLabelType type)
Unexpected label.
Definition: xmipp_error.h:157
MDLabelType type
MDLabel label
static String label2Str(const MDLabel &label)

◆ operator!=()

bool MDObject::operator!= ( const MDObject obj) const

Definition at line 595 of file metadata_object.cpp.

595  {
596  return !(*this == obj);
597 }
void(* obj)()

◆ operator<()

bool MDObject::operator< ( const MDObject obj) const

Definition at line 603 of file metadata_object.cpp.

603  {
604  return ((*this <= obj) && (*this != obj));
605 }

◆ operator<=()

bool MDObject::operator<= ( const MDObject obj) const

Definition at line 579 of file metadata_object.cpp.

579  {
580  // FIXME: allow to compare e.g. int & double & longint
581  if (this->type == LABEL_INT)
582  return this->data.intValue <= obj.data.intValue;
583  if (this->type == LABEL_BOOL)
584  return this->data.boolValue <= obj.data.boolValue;
585  if (this->type == LABEL_SIZET)
586  return this->data.longintValue <= obj.data.longintValue;
587  if (this->type == LABEL_DOUBLE)
588  return this->data.doubleValue <= obj.data.doubleValue;
589  if (this->type == LABEL_STRING)
590  return this->data.stringValue->compare(*obj.data.stringValue) <= 0;
591 
592  throw std::logic_error("MDObject: cannot compare this type on <=");
593 }
MDLabelType type
size_t longintValue
ObjectData data
double doubleValue
String * stringValue

◆ operator=()

MDObject & MDObject::operator= ( const MDObject obj)

Assign operator

Definition at line 86 of file metadata_object.cpp.

87 {
88  copy(obj);
89  return *this;
90 }
void copy(const MDObject &obj)

◆ operator==()

bool MDObject::operator== ( const MDObject obj) const

Definition at line 535 of file metadata_object.cpp.

535  {
536  return this->eq(obj, 0);
537 }
bool eq(const MDObject &obj, double epsilon) const

◆ operator>()

bool MDObject::operator> ( const MDObject obj) const

Definition at line 607 of file metadata_object.cpp.

607  {
608  return ((*this >= obj) && (*this != obj));
609 }

◆ operator>=()

bool MDObject::operator>= ( const MDObject obj) const

Definition at line 599 of file metadata_object.cpp.

599  {
600  return (!(*this <= obj) || (*this == obj));
601 }

◆ setValue() [1/10]

void MDObject::setValue ( const int &  iv)

Definition at line 271 of file metadata_object.cpp.

272 {
274  this->data.intValue = iv;
275 }
void labelTypeCheck(MDLabelType checkingType) const
ObjectData data

◆ setValue() [2/10]

void MDObject::setValue ( const double &  dv)

Definition at line 277 of file metadata_object.cpp.

278 {
280  this->data.doubleValue = safeDouble(dv);
281 }
void labelTypeCheck(MDLabelType checkingType) const
ObjectData data
double doubleValue

◆ setValue() [3/10]

void MDObject::setValue ( const bool &  bv)

Definition at line 283 of file metadata_object.cpp.

284 {
286  this->data.boolValue = bv;
287 }
void labelTypeCheck(MDLabelType checkingType) const
ObjectData data

◆ setValue() [4/10]

void MDObject::setValue ( const String sv)

Definition at line 289 of file metadata_object.cpp.

290 {
292  *(this->data.stringValue) = sv;
293 }
void labelTypeCheck(MDLabelType checkingType) const
ObjectData data
String * stringValue

◆ setValue() [5/10]

void MDObject::setValue ( const std::vector< double > &  vv)

Definition at line 295 of file metadata_object.cpp.

296 {
298  const auto size = vv.size();
299  this->data.vectorValue->resize(size);
300  for (size_t i = 0; i < size; ++i) {
301  this->data.vectorValue->operator[](i) = safeDouble(vv[i]);
302  }
303 }
void labelTypeCheck(MDLabelType checkingType) const
#define i
double vv
std::vector< double > * vectorValue
ObjectData data

◆ setValue() [6/10]

void MDObject::setValue ( const std::vector< float > &  vv)

Definition at line 305 of file metadata_object.cpp.

306 {
308  const auto size = vv.size();
309  this->data.vectorValueFloat->resize(size);
310  for (size_t i = 0; i < size; ++i) {
311  this->data.vectorValueFloat->operator[](i) = safeFloat(vv[i]);
312  }
313 }
void labelTypeCheck(MDLabelType checkingType) const
#define i
double vv
ObjectData data
std::vector< float > * vectorValueFloat

◆ setValue() [7/10]

void MDObject::setValue ( const std::vector< size_t > &  vv)

Definition at line 315 of file metadata_object.cpp.

316 {
318  *(this->data.vectorValueLong) = vv;
319 }
void labelTypeCheck(MDLabelType checkingType) const
std::vector< size_t > * vectorValueLong
double vv
ObjectData data

◆ setValue() [8/10]

void MDObject::setValue ( const size_t &  lv)

Definition at line 321 of file metadata_object.cpp.

322 {
324  this->data.longintValue = lv;
325 }
void labelTypeCheck(MDLabelType checkingType) const
size_t longintValue
ObjectData data

◆ setValue() [9/10]

void MDObject::setValue ( const float &  floatvalue)

Definition at line 327 of file metadata_object.cpp.

328 {
329  setValue((double) floatvalue);
330 }
void setValue(const int &iv)

◆ setValue() [10/10]

void MDObject::setValue ( const char *&  charvalue)

Definition at line 332 of file metadata_object.cpp.

333 {
334  setValue(String(charvalue));
335 }
std::string String
Definition: xmipp_strings.h:34
void setValue(const int &iv)

◆ toStream()

void MDObject::toStream ( std::ostream &  os,
bool  withFormat = false,
bool  isSql = false,
bool  escape = true 
) const

Definition at line 337 of file metadata_object.cpp.

338 {
339  if (label == MDL_UNDEFINED) //if undefine label, store as a literal string
340  os << data.stringValue;
341  else
342  switch (MDL::labelType(label))
343  {
344  case LABEL_BOOL: //bools are int in sqlite3
345  os << data.boolValue;
346  break;
347  case LABEL_INT:
349  break;
350  case LABEL_SIZET:
352  break;
353  case LABEL_DOUBLE:
355  break;
356  case LABEL_STRING:
357  {
358  char c = _SPACE;
359  if (escape)
360  {
361  if (isSql || data.stringValue->find_first_of(_DQUOT) != String::npos)
362  c = _QUOT;
363  else if (data.stringValue->find_first_of(_QUOT) != String::npos)
364  c = _DQUOT;
365  else if (data.stringValue->find_first_of(_SPACE) != String::npos)
366  c = _QUOT;
367  else if (data.stringValue->empty())
368  c = _QUOT;
369  }
370  if (c == _SPACE)
371  os << *(data.stringValue);
372  else
373  os << c << *(data.stringValue) << c;
374  }
375  break;
376  case LABEL_VECTOR_DOUBLE:
377  {
378  std::vector<double> &vectorDouble = *(data.vectorValue);
379  if (escape)
380  os << _QUOT << " ";
381  size_t size = vectorDouble.size();
382  for (size_t i = 0; i < size; i++)
383  {
384  double v = vectorDouble[i];
385  DOUBLE2STREAM(v);
386  os << " ";
387  }
388  if (escape)
389  os << _QUOT;
390  }
391  break;
392  case LABEL_VECTOR_SIZET:
393  {
394  std::vector<size_t> &vector = *(data.vectorValueLong);
395  if (escape)
396  os << _QUOT << " ";
397  size_t size = vector.size();
398  for (size_t i = 0; i < size; i++)
399  os << vector[i] << " ";
400  if (escape)
401  os << _QUOT;
402  }
403  break;
404  case LABEL_NOTYPE:
405  if (escape) os << _QUOT;
406  os << "No type";
407  if (escape) os << _QUOT;
408  break;
409  }//close switch
410 }//close function toStream
#define _DQUOT
std::vector< size_t > * vectorValueLong
doublereal * c
#define i
static MDLabelType labelType(const MDLabel label)
MDLabel label
size_t longintValue
std::vector< double > * vectorValue
ObjectData data
#define DOUBLE2STREAM(d)
#define _QUOT
#define _SPACE
double doubleValue
String * stringValue
#define INT2STREAM(i)

◆ toString()

String MDObject::toString ( bool  withFormat = false,
bool  isSql = false 
) const

Definition at line 412 of file metadata_object.cpp.

413 {
414  if (type == LABEL_STRING)
415  {
416  return isSql ? formatString("'%s'", data.stringValue->c_str()) : *data.stringValue;
417  }
418  std::stringstream ss;
419  toStream(ss, withFormat, isSql, isSql);
420 
421  return ss.str();
422 }
MDLabelType type
ObjectData data
String formatString(const char *format,...)
void toStream(std::ostream &os, bool withFormat=false, bool isSql=false, bool escape=true) const
String * stringValue

Friends And Related Function Documentation

◆ MDSql

friend class MDSql
friend

Definition at line 166 of file metadata_object.h.

◆ operator<<

std::ostream& operator<< ( std::ostream &  is,
const MDObject value 
)
friend

Definition at line 425 of file metadata_object.cpp.

426 {
427  value.toStream(os);
428  return os;
429 }
void toStream(std::ostream &os, bool withFormat=false, bool isSql=false, bool escape=true) const

◆ operator>>

std::istream& operator>> ( std::istream &  is,
MDObject value 
)
friend

Definition at line 432 of file metadata_object.cpp.

433 {
434  value.fromStream(is);
435  return is;
436 }
bool fromStream(std::istream &is, bool fromString=false)

Member Data Documentation

◆ chr

char MDObject::chr

Definition at line 60 of file metadata_object.h.

◆ data

ObjectData MDObject::data = {0}

Definition at line 58 of file metadata_object.h.

◆ failed

bool MDObject::failed

Definition at line 59 of file metadata_object.h.

◆ label

MDLabel MDObject::label

Definition at line 65 of file metadata_object.h.

◆ type

MDLabelType MDObject::type = LABEL_INT

Definition at line 66 of file metadata_object.h.


The documentation for this class was generated from the following files: