Xmipp  v3.23.11-Nereus
Classes | Macros | Functions | Variables
python_filename.h File Reference
#include <Python.h>
Include dependency graph for python_filename.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  FileNameObject
 

Macros

#define FileName_Check(v)   (((v)->ob_type == &FileNameType))
 
#define FileName_Value(v)   ((*((FileNameObject*)(v))->filename))
 

Functions

void FileName_dealloc (FileNameObject *self)
 
PyObject * FileName_new (PyTypeObject *type, PyObject *args, PyObject *kwargs)
 
PyObject * FileName_repr (PyObject *obj)
 
PyObject * FileName_compose (PyObject *obj, PyObject *args, PyObject *kwargs)
 
PyObject * FileName_composeBlock (PyObject *obj, PyObject *args, PyObject *kwargs)
 
PyObject * FileName_exists (PyObject *obj, PyObject *args, PyObject *kwargs)
 
PyObject * FileName_isInStack (PyObject *obj, PyObject *args, PyObject *kwargs)
 
PyObject * FileName_isMetaData (PyObject *obj, PyObject *args, PyObject *kwargs)
 
PyObject * FileName_isImage (PyObject *obj, PyObject *args, PyObject *kwargs)
 
PyObject * FileName_isStar1 (PyObject *obj, PyObject *args, PyObject *kwargs)
 
PyObject * FileName_getExtension (PyObject *obj, PyObject *args, PyObject *kwargs)
 
PyObject * FileName_getNumber (PyObject *obj, PyObject *args, PyObject *kwargs)
 
PyObject * FileName_getBaseName (PyObject *obj, PyObject *args, PyObject *kwargs)
 
PyObject * FileName_decompose (PyObject *obj, PyObject *args, PyObject *kwargs)
 
PyObject * FileName_withoutExtension (PyObject *obj, PyObject *args, PyObject *kwargs)
 
PyObject * FileName_removeBlockName (PyObject *obj, PyObject *args, PyObject *kwargs)
 

Variables

PyObject * PyXmippError
 
PyMethodDef FileName_methods []
 
PyTypeObject FileNameType
 

Macro Definition Documentation

◆ FileName_Check

#define FileName_Check (   v)    (((v)->ob_type == &FileNameType))

Definition at line 39 of file python_filename.h.

◆ FileName_Value

#define FileName_Value (   v)    ((*((FileNameObject*)(v))->filename))

Definition at line 40 of file python_filename.h.

Function Documentation

◆ FileName_compose()

PyObject* FileName_compose ( PyObject *  obj,
PyObject *  args,
PyObject *  kwargs 
)

Definition at line 163 of file python_filename.cpp.

164 {
165  auto *self = (FileNameObject*) obj;
166  PyObject* pyStr2 = nullptr;
167 
168  if (self != nullptr)
169  {
170  PyObject *input = nullptr;
171  PyObject *pyStr = nullptr;
172  PyObject *input2 = nullptr;
173  char str[1024] = "";
174  char * ext = nullptr;
175  char str2[1024] = "";
176  int number = -1;
177  size_t n = PyTuple_Size(args);
178  //"kk000001.xmp"
179  if (n == 3 && PyArg_ParseTuple(args, "Ois", &input, &number, &ext))
180  {
181  pyStr = PyObject_Str(input);
182  if (pyStr != nullptr)
183  strcpy(str, PyUnicode_AsUTF8(pyStr));
184  self->filename->compose(str, number, ext);
185  }
186  else if (n == 2 && PyArg_ParseTuple(args, "OO", &input, &input2))
187  {
188  if( PyUnicode_Check( input ) )
189  {
190  //"jj@kk.xmp"
191  pyStr = PyObject_Str(input);
192  pyStr2 = PyObject_Str(input2);
193  if (pyStr != nullptr)
194  strcpy(str, PyUnicode_AsUTF8(pyStr));
195  if (pyStr2 != nullptr)
196  strcpy(str2, PyUnicode_AsUTF8(pyStr2));
197  self->filename->compose(str, str2);
198  }
199  else if ( PyLong_Check( input ) )
200  {
201  //"1@kk.xmp"
202  number=PyLong_AsLong(input);
203  pyStr2 = PyObject_Str(input2);
204  strcpy(str2, PyUnicode_AsUTF8(pyStr2));
205  self->filename->compose(number, str2);
206  }
207  else
208  return nullptr;
209  }
210  Py_RETURN_NONE;//Return None(similar to void in C)
211  }
212  Py_RETURN_NONE;//Return None(similar to void in C)
213 }
void(* obj)()
int * n

◆ FileName_composeBlock()

PyObject* FileName_composeBlock ( PyObject *  obj,
PyObject *  args,
PyObject *  kwargs 
)

Definition at line 216 of file python_filename.cpp.

217 {
218  auto *self = (FileNameObject*) obj;
219 
220  if (self != nullptr)
221  {
222  char root[1024] = "";
223  char ext[32] = "";
224  char block[1024] ="";
225  int number = 1;
226  PyArg_ParseTuple(args, "sis|s", &block, &number, &root, &ext);
227  self->filename->composeBlock(block, number, root, ext);
228  }
229  Py_RETURN_NONE;//Return None(similar to void in C)
230 }
void(* obj)()

◆ FileName_dealloc()

void FileName_dealloc ( FileNameObject self)

Definition at line 112 of file python_filename.cpp.

113 {
114  delete self->filename;
115  Py_TYPE(self)->tp_free((PyObject*)self);
116 }
#define Py_TYPE(op)
Definition: frm_wrap.cpp:761

◆ FileName_decompose()

PyObject* FileName_decompose ( PyObject *  obj,
PyObject *  args,
PyObject *  kwargs 
)

Definition at line 326 of file python_filename.cpp.

327 {
328  auto *self = (FileNameObject*) obj;
329  size_t no;
330  String str;
331  self->filename->decompose(no, str);
332  return Py_BuildValue("is", no, str.c_str());
333 }
std::string String
Definition: xmipp_strings.h:34
void(* obj)()

◆ FileName_exists()

PyObject* FileName_exists ( PyObject *  obj,
PyObject *  args,
PyObject *  kwargs 
)

Definition at line 234 of file python_filename.cpp.

235 {
236  auto *self = (FileNameObject*) obj;
237 
238  if (self->filename->existsTrim())
239  Py_RETURN_TRUE;
240  else
241  Py_RETURN_FALSE;
242 }
void(* obj)()

◆ FileName_getBaseName()

PyObject* FileName_getBaseName ( PyObject *  obj,
PyObject *  args,
PyObject *  kwargs 
)

Definition at line 318 of file python_filename.cpp.

319 {
320  auto *self = (FileNameObject*) obj;
321 
322  return PyUnicode_FromString(self->filename->getBaseName().c_str());
323 }
void(* obj)()

◆ FileName_getExtension()

PyObject* FileName_getExtension ( PyObject *  obj,
PyObject *  args,
PyObject *  kwargs 
)

Definition at line 302 of file python_filename.cpp.

303 {
304  auto *self = (FileNameObject*) obj;
305 
306  return PyUnicode_FromString(self->filename->getExtension().c_str());
307 }
void(* obj)()

◆ FileName_getNumber()

PyObject* FileName_getNumber ( PyObject *  obj,
PyObject *  args,
PyObject *  kwargs 
)

Definition at line 310 of file python_filename.cpp.

311 {
312  auto *self = (FileNameObject*) obj;
313 
314  return PyLong_FromLong(self->filename->getNumber());
315 }
void(* obj)()

◆ FileName_isImage()

PyObject* FileName_isImage ( PyObject *  obj,
PyObject *  args,
PyObject *  kwargs 
)

Definition at line 281 of file python_filename.cpp.

282 {
283  if (isImage(FileName_Value(obj)))
284  Py_RETURN_TRUE;
285  else
286  Py_RETURN_FALSE;
287 }
#define FileName_Value(v)
void(* obj)()
bool isImage(const FileName &name)

◆ FileName_isInStack()

PyObject* FileName_isInStack ( PyObject *  obj,
PyObject *  args,
PyObject *  kwargs 
)

Definition at line 246 of file python_filename.cpp.

247 {
248  auto *self = (FileNameObject*) obj;
249 
250  if (self->filename->isInStack())
251  Py_RETURN_TRUE;
252  else
253  Py_RETURN_FALSE;
254 }
void(* obj)()

◆ FileName_isMetaData()

PyObject* FileName_isMetaData ( PyObject *  obj,
PyObject *  args,
PyObject *  kwargs 
)

Definition at line 258 of file python_filename.cpp.

259 {
260  auto *self = (FileNameObject*) obj;
261  try
262  {
263  if(self->filename->isMetaData(false))
264  {
265  Py_RETURN_TRUE;
266  }
267  else
268  {
269  Py_RETURN_FALSE;
270  }
271  }
272  catch (XmippError &xe)
273  {
274  PyErr_SetString(PyXmippError, xe.what());
275  }
276  return nullptr;
277 }
PyObject * PyXmippError
Definition: xmippmodule.cpp:47
void(* obj)()

◆ FileName_isStar1()

PyObject* FileName_isStar1 ( PyObject *  obj,
PyObject *  args,
PyObject *  kwargs 
)

Definition at line 291 of file python_filename.cpp.

292 {
293  auto *self = (FileNameObject*) obj;
294 
295  if (self->filename->isStar1(false))
296  Py_RETURN_TRUE;
297  else
298  Py_RETURN_FALSE;
299 }
void(* obj)()

◆ FileName_new()

PyObject* FileName_new ( PyTypeObject *  type,
PyObject *  args,
PyObject *  kwargs 
)

Definition at line 120 of file python_filename.cpp.

121 {
122  FileNameObject *self;
123 
124  self = (FileNameObject*)type->tp_alloc(type, 0);
125  if (self != nullptr)
126  {
127 
128  PyObject *input = nullptr;
129  PyObject *pyStr = nullptr;
130  PyObject *pyStr2 = nullptr;
131  char str[1024] = "";
132  char ext[1024] = "";
133  int number = ALL_IMAGES;
134  if (PyArg_ParseTuple(args, "|Ois", &input, &number, &ext))
135  //|| PyArg_ParseTuple(args, "|Os", &input, &ext)) FIXME
136  {
137  pyStr = PyObject_Str(input);
138  if (pyStr != nullptr)
139  {
140  const char *strExcType = PyUnicode_AsUTF8(pyStr);
141  strcpy(str, strExcType);
142  }
143  }
144  if (number != ALL_IMAGES)
145  self->filename = new FileName(str, number, ext);
146  else
147  self->filename = new FileName(str);
148 
149  }
150  return (PyObject *)self;
151 }
viol type
#define ALL_IMAGES

◆ FileName_removeBlockName()

PyObject* FileName_removeBlockName ( PyObject *  obj,
PyObject *  args,
PyObject *  kwargs 
)

Definition at line 343 of file python_filename.cpp.

344 {
345  auto *self = (FileNameObject*) obj;
346  return PyUnicode_FromString(self->filename->removeBlockName().c_str());
347 }
void(* obj)()

◆ FileName_repr()

PyObject* FileName_repr ( PyObject *  obj)

Definition at line 155 of file python_filename.cpp.

156 {
157  auto *self = (FileNameObject*) obj;
158  return PyUnicode_FromString(self->filename->c_str());
159 }
void(* obj)()

◆ FileName_withoutExtension()

PyObject* FileName_withoutExtension ( PyObject *  obj,
PyObject *  args,
PyObject *  kwargs 
)

Definition at line 336 of file python_filename.cpp.

337 {
338  auto *self = (FileNameObject*) obj;
339  return PyUnicode_FromString(self->filename->withoutExtension().c_str());
340 }
void(* obj)()

Variable Documentation

◆ FileName_methods

PyMethodDef FileName_methods[]

Definition at line 37 of file python_filename.cpp.

◆ FileNameType

PyTypeObject FileNameType

Definition at line 69 of file python_filename.cpp.

◆ PyXmippError

PyObject* PyXmippError

Definition at line 47 of file xmippmodule.cpp.