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

#include <metadata_static.h>

Static Public Member Functions

static void addLabelAlias (MDLabel label, const String &alias, bool replace=false, MDLabelType type=LABEL_NOTYPE)
 
static MDLabel getNewAlias (const String &alias, MDLabelType type=LABEL_NOTYPE)
 
static void resetBufferIndex ()
 
static MDRowSql emptyHeaderSql ()
 
static MDRowVec emptyHeaderVec ()
 
static void emptifyHeader (MDRow &)
 
String conversions
static void str2LabelVector (const String &labelsStr, std::vector< MDLabel > &labels)
 
static MDLabel str2Label (const String &labelName)
 
static String label2Str (const MDLabel &label)
 
static String label2StrSql (const MDLabel label)
 
static String label2SqlColumn (const MDLabel label)
 
static String labelType2Str (MDLabelType type)
 
Type checks

Several label type checks

static bool isInt (const MDLabel label)
 
static bool isLong (const MDLabel label)
 
static bool isBool (const MDLabel label)
 
static bool isString (const MDLabel label)
 
static bool isDouble (const MDLabel label)
 
static bool isVector (const MDLabel label)
 
static bool isVectorLong (const MDLabel label)
 
static bool isValidLabel (const MDLabel &label)
 
static bool isValidLabel (const String &labelName)
 
static MDLabelType labelType (const MDLabel label)
 
static MDLabelType labelType (const String &labelName)
 
static bool hasTag (const MDLabel label, const int tags)
 
static bool isTextFile (const MDLabel label)
 
static bool isMetadata (const MDLabel label)
 
static bool isCtfParam (const MDLabel label)
 
static bool isImage (const MDLabel label)
 
static bool isVolume (const MDLabel label)
 
static bool isStack (const MDLabel label)
 
static bool isMicrograph (const MDLabel label)
 
static bool isPSD (const MDLabel label)
 
static std::map< String, MDLabel > & getLabelDict ()
 

Friends

class MDLabelStaticInit
 

Detailed Description

Static class to group some functions with labels. This class holds several function to work with labels. Also performs the static initialization of the labels data.

Definition at line 37 of file metadata_static.h.

Member Function Documentation

◆ addLabelAlias()

void MDL::addLabelAlias ( MDLabel  label,
const String alias,
bool  replace = false,
MDLabelType  type = LABEL_NOTYPE 
)
static

Add an alias for an existing label. Params: label: The label id to create the alias to alias: The new alternative string name (alias) replace: If true, then new alias name will be used as the label string for writing back to file type: if provided, the label type will be replaced (only used with replace=True)

NOTE: Be aware that this function is not thread safe, so do not use it concurrently from different threads.

Definition at line 90 of file metadata_static.cpp.

92 {
93  names[alias] = label;
94  if (replace)
95  {
96  data[label]->str = alias;
97  if (type != LABEL_NOTYPE)
98  data[label]->type = type;
99  }
100 }
MDLabelType type
viol type

◆ emptifyHeader()

void MDL::emptifyHeader ( MDRow row)
static

Definition at line 321 of file metadata_static.cpp.

321  {
322  row.resetGeo();
323  row.setValue(MDL_ANGLE_ROT, 0.);
324  row.setValue(MDL_ANGLE_TILT,0.);
325 }
Rotation angle of an image (double,degrees)
Tilting angle of an image (double,degrees)
virtual void resetGeo(bool addLabels=true)
void setValue(MDLabel label, const T &d, bool addLabel=true)

◆ emptyHeaderSql()

MDRowSql MDL::emptyHeaderSql ( )
static

Definition at line 305 of file metadata_static.cpp.

305  {
306  MDRowSql row;
307  row.resetGeo();
308  row.setValue(MDL_ANGLE_ROT, 0.);
309  row.setValue(MDL_ANGLE_TILT,0.);
310  return row;
311 }
Rotation angle of an image (double,degrees)
Tilting angle of an image (double,degrees)
void setValue(const MDObject &object) override
virtual void resetGeo(bool addLabels=true)

◆ emptyHeaderVec()

MDRowVec MDL::emptyHeaderVec ( )
static

Definition at line 313 of file metadata_static.cpp.

313  {
314  MDRowVec row;
315  row.resetGeo();
316  row.setValue(MDL_ANGLE_ROT, 0.);
317  row.setValue(MDL_ANGLE_TILT,0.);
318  return row;
319 }
Rotation angle of an image (double,degrees)
Tilting angle of an image (double,degrees)
void setValue(const MDObject &object) override
virtual void resetGeo(bool addLabels=true)

◆ getLabelDict()

std::map< String, MDLabel > & MDL::getLabelDict ( )
static

Definition at line 260 of file metadata_static.cpp.

261 {
262  return names;
263 }

◆ getNewAlias()

MDLabel MDL::getNewAlias ( const String alias,
MDLabelType  type = LABEL_NOTYPE 
)
static

Get an alias of an available BUFFER label with the provided name. Params: alias: The name to create the alias from BUFFER label type: if provided, the label type will be replaced

Definition at line 102 of file metadata_static.cpp.

103 {
104  MDLabel newLabel = MDL::bufferIndex;
105 
106  if (newLabel == MDL_LAST_LABEL)
107  REPORT_ERROR(ERR_ARG_INCORRECT, "Not more buffer labels to use!!!");
108 
109  addLabelAlias(newLabel, alias, true, type);
110  MDL::bufferIndex = (MDLabel)((int)newLabel + 1);
111 
112  return newLabel;
113 }
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
viol type
Incorrect argument received.
Definition: xmipp_error.h:113
static void addLabelAlias(MDLabel label, const String &alias, bool replace=false, MDLabelType type=LABEL_NOTYPE)
MDLabel

◆ hasTag()

bool MDL::hasTag ( const MDLabel  label,
const int  tags 
)
static

Definition at line 265 of file metadata_static.cpp.

266 {
267  return data[label]->tags & tags;
268 }

◆ isBool()

bool MDL::isBool ( const MDLabel  label)
static

Definition at line 213 of file metadata_static.cpp.

214 {
215  return (data[label]->type == LABEL_BOOL);
216 }
viol type

◆ isCtfParam()

bool MDL::isCtfParam ( const MDLabel  label)
static

Definition at line 280 of file metadata_static.cpp.

281 {
282  return data[label]->tags & TAGLABEL_CTFPARAM;
283 }

◆ isDouble()

bool MDL::isDouble ( const MDLabel  label)
static

Definition at line 223 of file metadata_static.cpp.

224 {
225  return (data[label]->type == LABEL_DOUBLE);
226 }
viol type

◆ isImage()

bool MDL::isImage ( const MDLabel  label)
static

Definition at line 285 of file metadata_static.cpp.

286 {
287  return data[label]->tags & TAGLABEL_IMAGE;
288 }

◆ isInt()

bool MDL::isInt ( const MDLabel  label)
static

Definition at line 203 of file metadata_static.cpp.

204 {
205  return (data[label]->type == LABEL_INT);
206 }
viol type

◆ isLong()

bool MDL::isLong ( const MDLabel  label)
static

Definition at line 208 of file metadata_static.cpp.

209 {
210  return (data[label]->type == LABEL_SIZET);
211 }
viol type

◆ isMetadata()

bool MDL::isMetadata ( const MDLabel  label)
static

Definition at line 275 of file metadata_static.cpp.

276 {
277  return data[label]->tags & TAGLABEL_METADATA;
278 }

◆ isMicrograph()

bool MDL::isMicrograph ( const MDLabel  label)
static

Definition at line 295 of file metadata_static.cpp.

296 {
297  return data[label]->tags & TAGLABEL_MICROGRAPH;
298 }

◆ isPSD()

bool MDL::isPSD ( const MDLabel  label)
static

Definition at line 300 of file metadata_static.cpp.

301 {
302  return data[label]->tags & TAGLABEL_PSD;
303 }

◆ isStack()

bool MDL::isStack ( const MDLabel  label)
static

Definition at line 290 of file metadata_static.cpp.

291 {
292  return data[label]->tags & TAGLABEL_STACK;
293 }

◆ isString()

bool MDL::isString ( const MDLabel  label)
static

Definition at line 218 of file metadata_static.cpp.

219 {
220  return (data[label]->type == LABEL_STRING);
221 }
viol type

◆ isTextFile()

bool MDL::isTextFile ( const MDLabel  label)
static

Definition at line 270 of file metadata_static.cpp.

271 {
272  return data[label]->tags & TAGLABEL_TEXTFILE;
273 }

◆ isValidLabel() [1/2]

bool MDL::isValidLabel ( const MDLabel label)
static

Definition at line 238 of file metadata_static.cpp.

239 {
240  return label > MDL_UNDEFINED &&
241  label < MDL_LAST_LABEL &&
242  data[label] != NULL;
243 }

◆ isValidLabel() [2/2]

bool MDL::isValidLabel ( const String labelName)
static

Definition at line 245 of file metadata_static.cpp.

246 {
247  return isValidLabel(str2Label(labelName));
248 }
static MDLabel str2Label(const String &labelName)
static bool isValidLabel(const MDLabel &label)

◆ isVector()

bool MDL::isVector ( const MDLabel  label)
static

Definition at line 228 of file metadata_static.cpp.

229 {
230  return (data[label]->type == LABEL_VECTOR_DOUBLE);
231 }
viol type

◆ isVectorLong()

bool MDL::isVectorLong ( const MDLabel  label)
static

Definition at line 233 of file metadata_static.cpp.

234 {
235  return (data[label]->type == LABEL_VECTOR_SIZET);
236 }
viol type

◆ isVolume()

static bool MDL::isVolume ( const MDLabel  label)
static

◆ label2SqlColumn()

String MDL::label2SqlColumn ( const MDLabel  label)
static

Converts MDLabel to string representing SQL column

Definition at line 150 of file metadata_static.cpp.

151 {
152  std::stringstream ss;
153  ss << MDL::label2StrSql(label) << " ";
154 
155  switch (MDL::labelType(label))
156  {
157  case LABEL_BOOL: //bools are int in sqlite3
158  case LABEL_INT:
159  case LABEL_SIZET:
160  ss << "INTEGER";
161  break;
162  case LABEL_DOUBLE:
163  ss << "REAL";
164  break;
165  case LABEL_STRING:
166  ss << "TEXT";
167  break;
168  case LABEL_VECTOR_DOUBLE:
169  case LABEL_VECTOR_SIZET:
170  ss << "TEXT";
171  break;
172  case LABEL_NOTYPE:
173  ss << "NO_TYPE";
174  break;
175  }
176  return ss.str();
177 }
static String label2StrSql(const MDLabel label)
static MDLabelType labelType(const MDLabel label)

◆ label2Str()

String MDL::label2Str ( const MDLabel label)
static

Converts MDLabel to string

Definition at line 139 of file metadata_static.cpp.

140 {
141  return (isValidLabel(label)) ? data[(int)label]->str : "";
142 }
static bool isValidLabel(const MDLabel &label)

◆ label2StrSql()

String MDL::label2StrSql ( const MDLabel  label)
static

Same as label2Str but escaping with '' to use in Sqlite.

Definition at line 144 of file metadata_static.cpp.

145 {
146  String labelSqlite = "\"" + label2Str(label) + "\"";
147  return labelSqlite;
148 }
std::string String
Definition: xmipp_strings.h:34
static String label2Str(const MDLabel &label)

◆ labelType() [1/2]

MDLabelType MDL::labelType ( const MDLabel  label)
static

Definition at line 250 of file metadata_static.cpp.

251 {
252  return data[label]->type;
253 }
MDLabelType type

◆ labelType() [2/2]

MDLabelType MDL::labelType ( const String labelName)
static

Definition at line 255 of file metadata_static.cpp.

256 {
257  return data[str2Label(labelName)]->type;
258 }
MDLabelType type
static MDLabel str2Label(const String &labelName)

◆ labelType2Str()

String MDL::labelType2Str ( MDLabelType  type)
static

Return the type of the label as String

Definition at line 179 of file metadata_static.cpp.

180 {
181  switch (type)
182  {
183  case LABEL_STRING:
184  return "STRING";
185  case LABEL_DOUBLE:
186  return "DOUBLE";
187  case LABEL_INT:
188  return "INT";
189  case LABEL_BOOL:
190  return "BOOL";
191  case LABEL_VECTOR_DOUBLE:
192  return "VECTOR(DOUBLE)";
193  case LABEL_SIZET:
194  return "SIZE_T";
195  case LABEL_VECTOR_SIZET:
196  return "VECTOR(SIZE_T)";
197  case LABEL_NOTYPE:
198  return "NO_TYPE";
199  }
200  return "UNKNOWN";
201 }
viol type

◆ resetBufferIndex()

void MDL::resetBufferIndex ( )
static

Reset the counter of buffer labels. Use this function with care, since when you change the alias, the existing metadata could change and write wrong values to file.

Definition at line 115 of file metadata_static.cpp.

116 {
117  MDL::bufferIndex = BUFFER_01;
118 }

◆ str2Label()

MDLabel MDL::str2Label ( const String labelName)
static

Definition at line 132 of file metadata_static.cpp.

133 {
134  if (names.find(labelName) == names.end())
135  return MDL_UNDEFINED;
136  return names[labelName];
137 }

◆ str2LabelVector()

void MDL::str2LabelVector ( const String labelsStr,
std::vector< MDLabel > &  labels 
)
static

Converts an string to MDLabel

Definition at line 120 of file metadata_static.cpp.

121 {
122  labels.clear();
123  StringVector parts;
124  splitString(labelsStr, " ", parts);
125  for (size_t i = 0; i < parts.size(); ++i)
126  if (MDL::isValidLabel(parts[i]))
127  labels.push_back(MDL::str2Label(parts[i]));
128  else
129  REPORT_ERROR(ERR_PARAM_INCORRECT, formatString("Unknown label '%s' received.", parts[i].c_str()));
130 }
Parameter incorrect.
Definition: xmipp_error.h:181
static MDLabel str2Label(const String &labelName)
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
static bool isValidLabel(const MDLabel &label)
std::vector< String > StringVector
Definition: xmipp_strings.h:35
#define i
int splitString(const String &input, const String &delimiter, StringVector &results, bool includeEmpties)
String formatString(const char *format,...)

Friends And Related Function Documentation

◆ MDLabelStaticInit

friend class MDLabelStaticInit
friend

Definition at line 126 of file metadata_static.h.


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