MOOSE - Multiscale Object Oriented Simulation Environment
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
moosemodule.h File Reference
#include <string>
+ Include dependency graph for moosemodule.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _Field
 
struct  _Id
 
struct  _ObjId
 
struct  module_state
 

Macros

#define ElementField_Check(v)   (Py_TYPE(v) == &moose_ElementField)
 
#define ElementField_SubtypeCheck(v)   (PyType_IsSubtype(Py_TYPE(v), &moose_ElementField))
 
#define GETSTATE(m)   (&_state)
 
#define Id_Check(v)   (Py_TYPE(v) == &IdType)
 
#define Id_SubtypeCheck(v)   (PyType_IsSubtype(Py_TYPE(v),&IdType))
 
#define LookupField_Check(v)   (Py_TYPE(v) == &moose_LookupField)
 
#define maxArgs   10
 
#define minArgs   1
 
#define O32_HOST_ORDER   (o32_host_order.value)
 
#define ObjId_Check(v)   (Py_TYPE(v) == &ObjIdType)
 
#define ObjId_SubtypeCheck(v)   (PyType_IsSubtype(Py_TYPE(v), &ObjIdType))
 
#define RAISE_INVALID_ID(ret, msg)
 
#define RAISE_TYPE_ERROR(ret, type)
 
#define SET_LOOKUP_VALUE(TYPE)
 
#define SHELLPTR   (reinterpret_cast<Shell*>(getShell(0, NULL).eref().data()))
 

Enumerations

enum  { O32_LITTLE_ENDIAN = 0x03020100ul, O32_BIG_ENDIAN = 0x00010203ul, O32_PDP_ENDIAN = 0x01000302ul }
 

Functions

template<class A >
PyObject * _set_vector_destFinfo (ObjId obj, string fieldName, PyObject *value, char vtypecode)
 
PyObject * convert_and_set_tuple_entry (PyObject *tuple, unsigned int index, void *vptr, char typecode)
 
Id create_Id_from_path (string path, unsigned int numData, unsigned int isGlobal, string type)
 
int defineAllClasses (PyObject *module_dict)
 
int defineClass (PyObject *module_dict, const Cinfo *cinfo)
 
int defineDestFinfos (const Cinfo *cinfo)
 
int defineElementFinfos (const Cinfo *cinfo)
 
int defineLookupFinfos (const Cinfo *cinfo)
 
PyObject * deleteObjId (ObjId obj)
 
const map< string, string > & get_field_alias ()
 
map< string, vector
< PyGetSetDef > > & 
get_getsetdefs ()
 
map< string, PyTypeObject * > & get_moose_classes ()
 
int get_npy_typenum (const type_info &ctype)
 
template<typename KeyType , typename ValueType >
PyObject * get_simple_lookupfield (ObjId oid, string fieldname, KeyType key, char vtypecode)
 
template<typename KeyType , typename ValueType >
PyObject * get_vec_lookupfield (ObjId oid, string fieldname, KeyType key, char vtypecode)
 
PyTypeObject * getBaseClass (PyObject *self)
 
vector< string > getFieldNames (string className, string finfoType)
 
string getFieldType (string className, string fieldName)
 
const char ** getFinfoTypes ()
 finalize() More...
 
PyObject * getLookupField (ObjId oid, char *fieldName, PyObject *key)
 
PyObject * getObjIdAttr (_ObjId *oid, string attribute)
 
Id getShell (int argc, char **argv)
 setup_runtime_env() More...
 
PyMODINIT_FUNC init_moose ()
 
char innerType (char)
 
template<class KeyType >
PyObject * lookup_value (const ObjId &oid, string fname, char value_type_code, char key_type_code, PyObject *key)
 
PyObject * moose_connect (PyObject *dummy, PyObject *args)
 
PyObject * moose_copy (PyObject *dummy, PyObject *args, PyObject *kwargs)
 
PyObject * moose_delete (PyObject *dummy, PyObject *args)
 
PyObject * moose_element (PyObject *dummy, PyObject *args)
 
PyObject * moose_ElementField_getattro (_Field *self, PyObject *attr)
 
PyObject * moose_ElementField_getDataId (_Field *self, void *closure)
 
PyObject * moose_ElementField_getId (_Field *self, void *closure)
 
PyObject * moose_ElementField_getItem (_Field *self, Py_ssize_t index)
 
Py_ssize_t moose_ElementField_getLen (_Field *self, void *closure)
 
PyObject * moose_ElementField_getName (_Field *self, void *closure)
 
PyObject * moose_ElementField_getNum (_Field *self, void *closure)
 
PyObject * moose_ElementField_getOwner (_Field *self, void *closure)
 
PyObject * moose_ElementField_getPath (_Field *self, void *closure)
 
PyObject * moose_ElementField_getSlice (_Field *self, Py_ssize_t start, Py_ssize_t end)
 
int moose_ElementField_init (_Field *self, PyObject *args, PyObject *kwargs)
 
int moose_ElementField_setattro (_Field *self, PyObject *attr, PyObject *value)
 
int moose_ElementField_setNum (_Field *self, PyObject *num, void *closure)
 
PyObject * moose_exists (PyObject *dummy, PyObject *args)
 
void moose_Field_dealloc (_Field *self)
 
long moose_Field_hash (_Field *self)
 Return the hash of the string {objectpath}.{fieldName} More...
 
int moose_Field_init (_Field *self, PyObject *args, PyObject *kwds)
 
PyObject * moose_Field_repr (_Field *self)
 String representation of fields is {objectpath}.{fieldName} More...
 
PyObject * moose_getCwe (PyObject *dummy, PyObject *args)
 
PyObject * moose_getField (PyObject *dummy, PyObject *args)
 
PyObject * moose_getFieldDict (PyObject *dummy, PyObject *args)
 
int moose_Id_contains (_Id *self, PyObject *args)
 
PyObject * moose_Id_delete (_Id *self)
 
PyObject * moose_Id_getattro (_Id *self, PyObject *attr)
 
PyObject * moose_Id_getItem (_Id *self, Py_ssize_t index)
 
Py_ssize_t moose_Id_getLength (_Id *self)
 
PyObject * moose_Id_getPath (_Id *self)
 
PyObject * moose_Id_getShape (_Id *self)
 
PyObject * moose_Id_getSlice (_Id *self, Py_ssize_t start, Py_ssize_t end)
 
PyObject * moose_Id_getValue (_Id *self)
 
long moose_Id_hash (_Id *self)
 
int moose_Id_init (_Id *self, PyObject *args, PyObject *kwargs)
 
PyObject * moose_Id_repr (_Id *self)
 
PyObject * moose_Id_richCompare (_Id *self, PyObject *args, int op)
 
int moose_Id_setattro (_Id *self, PyObject *attr, PyObject *value)
 
PyObject * moose_Id_setField (_Id *self, PyObject *args)
 
PyObject * moose_Id_str (_Id *self)
 
PyObject * moose_Id_subscript (_Id *self, PyObject *op)
 
PyObject * moose_isRunning (PyObject *dummy, PyObject *args)
 
PyObject * moose_loadModel (PyObject *dummy, PyObject *args)
 
PyObject * moose_LookupField_getItem (_Field *self, PyObject *key)
 
int moose_LookupField_setItem (_Field *self, PyObject *key, PyObject *value)
 
PyObject * moose_move (PyObject *dummy, PyObject *args)
 
PyObject * moose_ObjId_connect (_ObjId *self, PyObject *args)
 
PyObject * moose_ObjId_get_destField_attr (PyObject *self, void *closure)
 
PyObject * moose_ObjId_get_elementField_attr (PyObject *self, void *closure)
 
PyObject * moose_ObjId_get_lookupField_attr (PyObject *self, void *closure)
 
PyObject * moose_ObjId_getattro (_ObjId *self, PyObject *attr)
 
PyObject * moose_ObjId_getDataIndex (_ObjId *self)
 
PyObject * moose_ObjId_getField (_ObjId *self, PyObject *args)
 
PyObject * moose_ObjId_getFieldIndex (_ObjId *self)
 
PyObject * moose_ObjId_getFieldNames (_ObjId *self, PyObject *args)
 
PyObject * moose_ObjId_getFieldType (_ObjId *self, PyObject *args)
 
PyObject * moose_ObjId_getId (_ObjId *self)
 
PyObject * moose_ObjId_getItem (_ObjId *self, Py_ssize_t index)
 
Py_ssize_t moose_ObjId_getLength (_ObjId *self)
 
PyObject * moose_ObjId_getLookupField (_ObjId *self, PyObject *args)
 
PyObject * moose_ObjId_getNeighbors (_ObjId *self, PyObject *args)
 
PyObject * moose_ObjId_getSlice (_ObjId *self, Py_ssize_t start, Py_ssize_t end)
 
long moose_ObjId_hash (_ObjId *self)
 
int moose_ObjId_init (_ObjId *self, PyObject *args, PyObject *kwargs)
 
PyObject * moose_ObjId_repr (_ObjId *self)
 
PyObject * moose_ObjId_richcompare (_ObjId *self, PyObject *args, int op)
 
int moose_ObjId_setattro (_ObjId *self, PyObject *attr, PyObject *value)
 
PyObject * moose_ObjId_setDestField (_ObjId *self, PyObject *args)
 
PyObject * moose_ObjId_setField (_ObjId *self, PyObject *args)
 
PyObject * moose_ObjId_setLookupField (_ObjId *self, PyObject *args)
 
PyObject * moose_quit (PyObject *dummy)
 
PyObject * moose_reinit (PyObject *dummy, PyObject *args)
 
PyObject * moose_seed (PyObject *dummy, PyObject *args)
 
PyObject * moose_setClock (PyObject *dummy, PyObject *args)
 
PyObject * moose_setCwe (PyObject *dummy, PyObject *args)
 
PyObject * moose_start (PyObject *dummy, PyObject *args)
 
PyObject * moose_stop (PyObject *dummy, PyObject *args)
 
PyObject * moose_syncDataHandler (PyObject *dummy, PyObject *target)
 
PyObject * moose_useClock (PyObject *dummy, PyObject *args)
 
PyObject * moose_wildcardFind (PyObject *dummy, PyObject *args)
 
PyObject * oid_to_element (ObjId oid)
 
int parseFinfoType (string className, string finfoType, string fieldName, vector< string > &typeVec)
 
vector< int > pysequence_to_dimvec (PyObject *dims)
 
template<typename T >
vector< T > * PySequenceToVector (PyObject *seq, char typecode)
 
template<typename T >
vector< vector< T > > * PySequenceToVectorOfVectors (PyObject *seq, char typecode)
 
template<class KeyType >
int set_lookup_value (const ObjId &oid, string fname, char value_type_code, char key_type_code, PyObject *key, PyObject *value_obj)
 
PyObject * setDestFinfo (ObjId obj, string fieldName, PyObject *arg, string argType)
 
template<class A >
PyObject * setDestFinfo1 (ObjId obj, string fieldName, PyObject *arg1, char type1, A arg2)
 
PyObject * setDestFinfo2 (ObjId obj, string fieldName, PyObject *arg1, char type1, PyObject *arg2, char type2)
 
int setLookupField (ObjId oid, char *fieldName, PyObject *key, PyObject *value)
 
char shortType (string)
 
void * to_cpp (PyObject *object, char typecode)
 
PyObject * to_py (void *obj, char typecode)
 
PyObject * to_pytuple (void *obj, char typecode)
 

Variables

static struct module_state _state
 
union {
   unsigned char   bytes [4]
 
   uint32_t   value
 
o32_host_order = { { 0, 1, 2, 3 } }
 

Macro Definition Documentation

#define ElementField_Check (   v)    (Py_TYPE(v) == &moose_ElementField)

Definition at line 100 of file moosemodule.h.

#define ElementField_SubtypeCheck (   v)    (PyType_IsSubtype(Py_TYPE(v), &moose_ElementField))

Definition at line 101 of file moosemodule.h.

Referenced by moose_element().

#define GETSTATE (   m)    (&_state)

Definition at line 67 of file moosemodule.h.

Referenced by MODINIT().

#define Id_Check (   v)    (Py_TYPE(v) == &IdType)

Definition at line 95 of file moosemodule.h.

Referenced by moose_ObjId_init_from_id().

#define Id_SubtypeCheck (   v)    (PyType_IsSubtype(Py_TYPE(v),&IdType))

Definition at line 96 of file moosemodule.h.

Referenced by moose_connect(), and moose_Id_init().

#define LookupField_Check (   v)    (Py_TYPE(v) == &moose_LookupField)

Definition at line 99 of file moosemodule.h.

#define maxArgs   10

Definition at line 88 of file moosemodule.h.

Referenced by moose_ObjId_setDestField(), and parseFinfoType().

#define minArgs   1

Definition at line 84 of file moosemodule.h.

Referenced by moose_ObjId_setDestField().

#define O32_HOST_ORDER   (o32_host_order.value)

Definition at line 45 of file moosemodule.h.

#define ObjId_Check (   v)    (Py_TYPE(v) == &ObjIdType)

Definition at line 97 of file moosemodule.h.

#define ObjId_SubtypeCheck (   v)    (PyType_IsSubtype(Py_TYPE(v), &ObjIdType))

Definition at line 98 of file moosemodule.h.

Referenced by moose_connect(), moose_Id_contains(), and moose_Id_init().

#define RAISE_TYPE_ERROR (   ret,
  type 
)
Value:
{ \
PyErr_SetString(PyExc_TypeError, "require " #type); \
return ret; \
}

Definition at line 76 of file moosemodule.h.

#define SET_LOOKUP_VALUE (   TYPE)
Value:
{ \
TYPE * value = (TYPE*)to_cpp(value_obj, value_type_code); \
if (value){ \
success = LookupField < KeyType, TYPE > ::set(oid, fname, *cpp_key, *value); \
delete value; \
delete cpp_key; \
} \
break; \
}
uint32_t value
Definition: moosemodule.h:42
void * to_cpp(PyObject *object, char typecode)

Referenced by set_lookup_value().

Enumeration Type Documentation

anonymous enum
Enumerator
O32_LITTLE_ENDIAN 
O32_BIG_ENDIAN 
O32_PDP_ENDIAN 

Definition at line 32 of file moosemodule.h.

33 {
34  O32_LITTLE_ENDIAN = 0x03020100ul,
35  O32_BIG_ENDIAN = 0x00010203ul,
36  O32_PDP_ENDIAN = 0x01000302ul
37 };

Function Documentation

template<class A >
PyObject* _set_vector_destFinfo ( ObjId  obj,
string  fieldName,
PyObject *  value,
char  vtypecode 
)

Definition at line 578 of file moosemodule.h.

References moose::error, and to_cpp().

579 {
580  ostringstream error;
581  if (!PySequence_Check(value))
582  {
583  PyErr_SetString(PyExc_TypeError, "For setting vector field, specified value must be a sequence." );
584  return NULL;
585  }
586  vector<A> * _value = (vector < A > *)to_cpp(value, vtypecode);
587  if (_value == NULL)
588  {
589  return NULL;
590  }
591  bool ret = SetGet1< vector < A > >::set(obj, fieldName, *_value);
592  delete _value;
593  if (ret)
594  {
595  Py_RETURN_TRUE;
596  }
597  else
598  {
599  Py_RETURN_FALSE;
600  }
601 }
uint32_t value
Definition: moosemodule.h:42
void * to_cpp(PyObject *object, char typecode)

+ Here is the call graph for this function:

PyObject* convert_and_set_tuple_entry ( PyObject *  tuple,
unsigned int  index,
void *  vptr,
char  typecode 
)

Inner function to convert C++ object at vptr and set tuple entry ii to the created PyObject. typecode is passed to to_cpp for conversion. If error occurs while setting tuple antry, it decrements the refcount of the tuple and returns NULL. Returns the tuple on success.

Definition at line 491 of file moosemodule.cpp.

References to_py(), and verbosity.

Referenced by to_pytuple().

492 {
493  PyObject * item = to_py(vptr, typecode);
494  if (item == NULL)
495  {
496  return NULL; // the error message would have been populated by to_cpp
497  }
498  if (PyTuple_SetItem(tuple, (Py_ssize_t)index, item) != 0)
499  {
500  PyErr_SetString(PyExc_RuntimeError, "convert_and_set_tuple_entry: could not set tuple entry.");
501  return NULL;
502  }
503 #ifndef NDEBUG
504  if (verbosity > 2)
505  {
506  cout << "Set tuple " << tuple << " entry " << index << " with " << item << endl;
507  }
508 #endif
509  return tuple;
510 }
int verbosity
PyObject * to_py(void *obj, char typecode)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Id create_Id_from_path ( string  path,
unsigned int  numData,
unsigned int  isGlobal,
string  type 
)

Referenced by moose_ObjId_init_from_path().

+ Here is the caller graph for this function:

int defineAllClasses ( PyObject *  module_dict)

Go through all elements under /classes and ask for defining a Python class for it.

Definition at line 2461 of file moosemodule.cpp.

References defineClass(), Cinfo::find(), and verbosity.

Referenced by MODINIT().

2462 {
2463  static vector <Id> classes(Field< vector<Id> >::get(ObjId("/classes"),
2464  "children"));
2465  for (unsigned ii = 0; ii < classes.size(); ++ii)
2466  {
2467  const string& className = classes[ii].element()->getName();
2468  if (verbosity > 0)
2469  {
2470  cout << "\nCreating " << className << endl;
2471  }
2472  const Cinfo * cinfo = Cinfo::find(className);
2473  if (!cinfo)
2474  {
2475  cerr << "Error: no cinfo found with name " << className << endl;
2476  return 0;
2477  }
2478  if (!defineClass(module_dict, cinfo))
2479  {
2480  return 0;
2481  }
2482  }
2483  return 1;
2484 }
Definition: SetGet.h:236
static const Cinfo * find(const std::string &name)
Definition: Cinfo.cpp:200
Definition: ObjId.h:20
int defineClass(PyObject *module_dict, const Cinfo *cinfo)
int verbosity
Definition: Cinfo.h:18

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int defineClass ( PyObject *  module_dict,
const Cinfo cinfo 
)

Definition at line 2540 of file moosemodule.cpp.

References Cinfo::baseCinfo(), defineClass(), defineDestFinfos(), defineElementFinfos(), defineLookupFinfos(), get_getsetdefs(), get_moose_classes(), Cinfo::getBaseClass(), Cinfo::name(), ObjIdType, and verbosity.

Referenced by defineAllClasses(), and defineClass().

2541 {
2542  const string& className = cinfo->name();
2543  map <string, PyTypeObject * >::iterator existing =
2544  get_moose_classes().find(className);
2545  if (existing != get_moose_classes().end())
2546  {
2547  return 1;
2548  }
2549  const Cinfo* base = cinfo->baseCinfo();
2550 #ifndef NDEBUG
2551  if (verbosity > 1)
2552  {
2553  cout << "Defining class " << className << endl; //" with base=" << base->name() << endl;
2554  }
2555 #endif
2556  if (base && !defineClass(module_dict, base))
2557  {
2558  return 0;
2559  }
2560 
2561  string str = "moose." + className;
2562 
2563  PyTypeObject * new_class =
2564  (PyTypeObject*)PyType_Type.tp_alloc(&PyType_Type, 0);
2565 // Python3 does not like it without heaptype: aborts on import
2566 // Fatal Python error:
2567 // type_traverse() called for non-heap type 'moose.Neutral'
2568 #ifdef PY3K
2569  new_class->tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HEAPTYPE;
2570  PyHeapTypeObject* et = (PyHeapTypeObject*)new_class;
2571  et->ht_name = PyUnicode_FromString(className.c_str());
2572 #if PY_MINOR_VERSION >= 3
2573  et->ht_qualname = PyUnicode_FromString(str.c_str());
2574 #endif
2575 #else
2576  new_class->tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
2577 #endif
2578  /*
2579  Thu Jul 9 09:58:09 IST 2015 - commenting out
2580  Py_TPFLAGS_HEAPTYPE because it causes segfault on accessing
2581  __class__ attribute of instances. Bug # 168. Another
2582  possible solution would be to catch __class__ request in
2583  tp_getattro and INCREF the class object when returning the
2584  same.
2585 
2586  ------
2587  should we avoid Py_TPFLAGS_HEAPTYPE as it imposes certain
2588  limitations:
2589  http://mail.python.org/pipermail/python-dev/2009-July/090921.html
2590  But otherwise somehow GC tries tp_traverse on these classes
2591  (even when I unset Py_TPFLAGS_HAVE_GC) and fails the
2592  assertion in debug build of Python:
2593 
2594  python: Objects/typeobject.c:2683: type_traverse: Assertion `type->tp_flags & Py_TPFLAGS_HEAPTYPE' failed.
2595 
2596  In released versions of Python there is a crash at
2597  Py_Finalize().
2598 
2599  Also if HEAPTYPE is true, then help(classname) causes a
2600  segmentation fault as it tries to convert the class object
2601  to a heaptype object (resulting in an invalid pointer). If
2602  heaptype is not set it uses tp_name to print the help.
2603  Py_SIZE(new_class) = sizeof(_ObjId);
2604  */
2605  new_class->tp_name = strdup(str.c_str());
2606  new_class->tp_doc = moose_Class_documentation;
2607 
2608  //strncpy(new_class->tp_doc, moose_Class_documentation, strlen(moose_Class_documentation));
2609  map<string, PyTypeObject *>::iterator base_iter =
2610  get_moose_classes().find(cinfo->getBaseClass());
2611  if (base_iter == get_moose_classes().end())
2612  {
2613  new_class->tp_base = &ObjIdType;
2614  }
2615  else
2616  {
2617  new_class->tp_base = base_iter->second;
2618  }
2619  Py_INCREF(new_class->tp_base);
2620  // Define all the lookupFields
2621  if (!defineLookupFinfos(cinfo))
2622  {
2623  return 0;
2624  }
2625  // Define the destFields
2626  if (!defineDestFinfos(cinfo))
2627  {
2628  return 0;
2629  }
2630 
2631  // Define the element fields
2632  if (!defineElementFinfos(cinfo))
2633  {
2634  return 0;
2635  }
2636  // #ifndef NDEBUG
2637  // cout << "Get set defs:" << className << endl;
2638  // for (unsigned int ii = 0; ii < get_getsetdefs()[className].size(); ++ii){
2639  // cout << ii;
2640  // if (get_getsetdefs()[className][ii].name != NULL){
2641  // cout << ": " << get_getsetdefs()[className][ii].name;
2642  // } else {
2643  // cout << "Empty";
2644  // }
2645  // cout << endl;
2646  // }
2647  // cout << "End getsetdefs: " << className << endl;
2648  // #endif
2649  // The getsetdef array must be terminated with empty objects.
2650  PyGetSetDef empty;
2651  empty.name = NULL;
2652  get_getsetdefs()[className].push_back(empty);
2653  get_getsetdefs()[className].back().name = NULL;
2654  new_class->tp_getset = &(get_getsetdefs()[className][0]);
2655  /*
2656  Cannot do this for HEAPTYPE ?? but pygobject.c does this in
2657  pygobject_register_class
2658  */
2659  if (PyType_Ready(new_class) < 0)
2660  {
2661  cerr << "Fatal error: Could not initialize class '" << className
2662  << "'" << endl;
2663  return 0;
2664  }
2665  get_moose_classes().insert(pair<string, PyTypeObject*> (className, new_class));
2666  Py_INCREF(new_class);
2667 
2668 #ifdef PY3K
2669  PyDict_SetItemString(new_class->tp_dict, "__module__", PyUnicode_InternFromString("moose"));
2670 #endif
2671  // string doc = const_cast<Cinfo*>(cinfo)->getDocs();
2672  // PyDict_SetItemString(new_class->tp_dict, "__doc__", PyString_FromString(" \0"));
2673  // PyDict_SetItemString(module_dict, className.c_str(), (PyObject *)new_class);
2674  return 1;
2675 }
const Cinfo * baseCinfo() const
Definition: Cinfo.cpp:216
int defineElementFinfos(const Cinfo *cinfo)
map< string, PyTypeObject * > & get_moose_classes()
int defineClass(PyObject *module_dict, const Cinfo *cinfo)
map< string, vector< PyGetSetDef > > & get_getsetdefs()
int defineDestFinfos(const Cinfo *cinfo)
const std::string & name() const
Definition: Cinfo.cpp:260
int defineLookupFinfos(const Cinfo *cinfo)
PyTypeObject ObjIdType
int verbosity
string getBaseClass() const
Definition: Cinfo.cpp:391
Definition: Cinfo.h:18

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int defineDestFinfos ( const Cinfo cinfo)

Definition at line 2714 of file moosemodule.cpp.

References get_getsetdefs(), Cinfo::getNumDestFinfo(), moose_ObjId_get_destField_attr(), Finfo::name(), Cinfo::name(), name, and verbosity.

Referenced by defineClass().

2715 {
2716  const string& className = cinfo->name();
2717 #ifndef NDEBUG
2718  if (verbosity > 1)
2719  {
2720  cout << "\tCreating destField attributes for " << className << endl;
2721  }
2722 #endif
2723  vector <PyGetSetDef>& vec = get_getsetdefs()[className];
2724  /*
2725  We do not know the final number of user-accessible
2726  destFinfos as we have to ignore the destFinfos starting
2727  with get/set. So use a vector instead of C array.
2728  */
2729  size_t currIndex = vec.size();
2730  for (unsigned int ii = 0; ii < cinfo->getNumDestFinfo(); ++ii)
2731  {
2732  Finfo * destFinfo = const_cast<Cinfo*>(cinfo)->getDestFinfo(ii);
2733  const string& name = destFinfo->name();
2734  /*
2735  get_{xyz} and set_{xyz} are internal destFinfos for
2736  accessing valueFinfos. Ignore them.
2737 
2738  With the '_' removed from internal get/set for value
2739  fields, we cannot separate them out. - Subha Fri Jan 31
2740  16:43:51 IST 2014
2741 
2742  The policy changed in the past and hence the following were commented out.
2743  - Subha Tue May 26 00:25:28 EDT 2015
2744  */
2745  // if (name.find("get") == 0 || name.find("set") == 0){
2746  // continue;
2747  // }
2748  PyGetSetDef destFieldGetSet;
2749  vec.push_back(destFieldGetSet);
2750 
2751  vec[currIndex].name = strdup(name.c_str());
2752  vec[currIndex].doc = (char*) "Destination field";
2753  vec[currIndex].get = (getter)moose_ObjId_get_destField_attr;
2754  PyObject *args = PyTuple_New(1);
2755  if (!args || !vec[currIndex].name) {
2756  cerr << "moosemodule.cpp: defineDestFinfos: allocation failed\n";
2757  return 0;
2758  }
2759  PyTuple_SetItem(args, 0, PyString_FromString(name.c_str()));
2760  vec[currIndex].closure = (void*)args;
2761 
2762  //LOG( debug, "\tCreated destField " << vec[currIndex].name );
2763 
2764  ++currIndex;
2765  } // ! for
2766 
2767  return 1;
2768 }
unsigned int getNumDestFinfo() const
Definition: Cinfo.cpp:444
PyObject * moose_ObjId_get_destField_attr(PyObject *self, void *closure)
const string & name() const
Definition: Finfo.cpp:80
map< string, vector< PyGetSetDef > > & get_getsetdefs()
const std::string & name() const
Definition: Cinfo.cpp:260
int verbosity
static char name[]
Definition: mfield.cpp:401
Definition: Cinfo.h:18
Definition: Finfo.h:12

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int defineElementFinfos ( const Cinfo cinfo)

Definition at line 2863 of file moosemodule.cpp.

References get_getsetdefs(), Cinfo::getNumFieldElementFinfo(), moose_ObjId_get_elementField_attr(), Cinfo::name(), name, and verbosity.

Referenced by defineClass().

2864 {
2865  const string & className = cinfo->name();
2866 #ifndef NDEBUG
2867  if (verbosity > 1)
2868  {
2869  cout << "\tDefining elementFields for " << className << endl;
2870  }
2871 #endif
2872  unsigned int num = cinfo->getNumFieldElementFinfo();
2873  unsigned int currIndex = get_getsetdefs()[className].size();
2874  for (unsigned int ii = 0; ii < num; ++ii)
2875  {
2876  const string& name = const_cast<Cinfo*>(cinfo)->getFieldElementFinfo(ii)->name();
2877  PyGetSetDef getset;
2878  get_getsetdefs()[className].push_back(getset);
2879  get_getsetdefs()[className][currIndex].name = (char*)calloc(name.size() + 1, sizeof(char));
2880  strncpy(const_cast<char*>(get_getsetdefs()[className][currIndex].name)
2881  , const_cast<char*>(name.c_str()), name.size());
2882  get_getsetdefs()[className][currIndex].doc = (char*) "Element field";
2883  get_getsetdefs()[className][currIndex].get = (getter)moose_ObjId_get_elementField_attr;
2884  PyObject * args = PyTuple_New(1);
2885  PyTuple_SetItem(args, 0, PyString_FromString(name.c_str()));
2886  get_getsetdefs()[className][currIndex].closure = (void*)args;
2887 #ifndef NDEBUG
2888  if (verbosity > 1)
2889  {
2890  cout << "\tDefined elementField " << get_getsetdefs()[className][currIndex].name << endl;
2891  }
2892 #endif
2893 
2894  ++currIndex;
2895  }
2896  return 1;
2897 }
PyObject * moose_ObjId_get_elementField_attr(PyObject *self, void *closure)
map< string, vector< PyGetSetDef > > & get_getsetdefs()
const std::string & name() const
Definition: Cinfo.cpp:260
unsigned int getNumFieldElementFinfo() const
Definition: Cinfo.cpp:537
int verbosity
static char name[]
Definition: mfield.cpp:401
Definition: Cinfo.h:18

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int defineLookupFinfos ( const Cinfo cinfo)

Definition at line 2503 of file moosemodule.cpp.

References get_getsetdefs(), Cinfo::getNumLookupFinfo(), moose_ObjId_get_lookupField_attr(), Cinfo::name(), name, and verbosity.

Referenced by defineClass().

2504 {
2505  const string & className = cinfo->name();
2506 #ifndef NDEBUG
2507  if (verbosity > 1)
2508  {
2509  cout << "\tDefining lookupFields for " << className << endl;
2510  }
2511 #endif
2512  unsigned int num = cinfo->getNumLookupFinfo();
2513  unsigned int currIndex = get_getsetdefs()[className].size();
2514  for (unsigned int ii = 0; ii < num; ++ii)
2515  {
2516  const string& name = const_cast<Cinfo*>(cinfo)->getLookupFinfo(ii)->name();
2517  PyGetSetDef getset;
2518  get_getsetdefs()[className].push_back(getset);
2519  get_getsetdefs()[className][currIndex].name = (char*)calloc(name.size() + 1, sizeof(char));
2520  strncpy(const_cast<char*>(get_getsetdefs()[className][currIndex].name)
2521  , const_cast<char*>(name.c_str()), name.size());
2522  get_getsetdefs()[className][currIndex].doc = (char*) "Lookup field";
2523  get_getsetdefs()[className][currIndex].get = (getter)moose_ObjId_get_lookupField_attr;
2524  PyObject * args = PyTuple_New(1);
2525  PyTuple_SetItem(args, 0, PyString_FromString(name.c_str()));
2526  get_getsetdefs()[className][currIndex].closure = (void*)args;
2527 #ifndef NDEBUG
2528  if (verbosity > 1)
2529  {
2530  cout << "\tDefined lookupField " << get_getsetdefs()[className][currIndex].name << endl;
2531  }
2532 #endif
2533 
2534  ++currIndex;
2535  }
2536  return 1;
2537 }
PyObject * moose_ObjId_get_lookupField_attr(PyObject *self, void *closure)
map< string, vector< PyGetSetDef > > & get_getsetdefs()
const std::string & name() const
Definition: Cinfo.cpp:260
int verbosity
static char name[]
Definition: mfield.cpp:401
unsigned int getNumLookupFinfo() const
Definition: Cinfo.cpp:491
Definition: Cinfo.h:18

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

PyObject* deleteObjId ( ObjId  obj)

Definition at line 522 of file vec.cpp.

References SHELLPTR, and verbosity.

Referenced by moose_delete(), and moose_Id_delete().

523 {
524 #ifndef NDEBUG
525  if (verbosity > 1)
526  {
527  cout << "Deleting ObjId " << oid << endl;
528  }
529 #endif
530  SHELLPTR->doDelete(oid);
531  Py_RETURN_NONE;
532 }
#define SHELLPTR
Definition: moosemodule.h:105
int verbosity

+ Here is the caller graph for this function:

const map<string, string>& get_field_alias ( )

map of fields which are aliased in Python to avoid collision with Python keywords.

Definition at line 850 of file moosemodule.cpp.

Referenced by moose_ElementField_getattro(), moose_Id_getattro(), and moose_ObjId_getattro().

851 {
852  static map<string, string> alias;
853  if (alias.empty())
854  {
855  // alias["class_"] = "class";
856  alias["lambda_"] = "lambda";
857  }
858  return alias;
859 }

+ Here is the caller graph for this function:

map<string, vector <PyGetSetDef> >& get_getsetdefs ( )

Definition at line 840 of file moosemodule.cpp.

Referenced by defineClass(), defineDestFinfos(), defineElementFinfos(), defineLookupFinfos(), and finalize().

841 {
842  static map<string, vector <PyGetSetDef> > getset_defs;
843  return getset_defs;
844 }

+ Here is the caller graph for this function:

map<string, PyTypeObject *>& get_moose_classes ( )

Definition at line 833 of file moosemodule.cpp.

Referenced by defineClass(), getBaseClass(), MODINIT(), moose_ObjId_init_from_path(), moose_ObjId_setattro(), and oid_to_element().

834 {
835  static map<string, PyTypeObject *> defined_classes;
836  return defined_classes;
837 }

+ Here is the caller graph for this function:

int get_npy_typenum ( const type_info &  ctype)
template<typename KeyType , typename ValueType >
PyObject* get_simple_lookupfield ( ObjId  oid,
string  fieldname,
KeyType  key,
char  vtypecode 
)

Definition at line 378 of file moosemodule.h.

References LookupField< L, A >::get(), to_py(), and value.

379 {
380  ValueType value = LookupField<KeyType, ValueType>::get(oid, fieldname, key);
381  PyObject * v = to_py(&value, vtypecode);
382  return v;
383 }
uint32_t value
Definition: moosemodule.h:42
static A get(const ObjId &dest, const string &field, L index)
Definition: SetGet.h:532
PyObject * to_py(void *obj, char typecode)

+ Here is the call graph for this function:

template<typename KeyType , typename ValueType >
PyObject* get_vec_lookupfield ( ObjId  oid,
string  fieldname,
KeyType  key,
char  vtypecode 
)

Definition at line 371 of file moosemodule.h.

References innerType(), to_pytuple(), and value.

372 {
373  vector<ValueType> value = LookupField<KeyType, vector<ValueType> >::get(oid, fieldname, key);
374  return to_pytuple((void*)&value, innerType(vtypecode));
375 }
uint32_t value
Definition: moosemodule.h:42
char innerType(char)
Definition: types.cpp:104
PyObject * to_pytuple(void *obj, char typecode)

+ Here is the call graph for this function:

PyTypeObject* getBaseClass ( PyObject *  self)

Utility function to traverse python class hierarchy to reach closest base class. Ideally we should go via mro

Definition at line 1294 of file moosemodule.cpp.

References get_moose_classes(), and ObjIdType.

Referenced by moose_ObjId_init_from_path(), and testCinfoFields().

1295 {
1296  extern PyTypeObject ObjIdType;
1297  string basetype_str = "";
1298  PyTypeObject * base = NULL;
1299  for (base = Py_TYPE(self);
1300  base != &ObjIdType; base = base->tp_base)
1301  {
1302  basetype_str = base->tp_name;
1303  size_t dot = basetype_str.find('.');
1304  basetype_str = basetype_str.substr(dot+1);
1305  if (get_moose_classes().find(basetype_str) !=
1306  get_moose_classes().end())
1307  {
1308  return base;
1309  }
1310  }
1311  return NULL;
1312 }
map< string, PyTypeObject * > & get_moose_classes()
PyTypeObject ObjIdType

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

vector<string> getFieldNames ( string  className,
string  finfoType 
)
string getFieldType ( string  className,
string  fieldName 
)
const char** getFinfoTypes ( )

finalize()

Return list of available Finfo types. Place holder for static const to avoid static initialization issues.

Definition at line 1064 of file moosemodule.cpp.

Referenced by moose_ObjId_getFieldNames().

1065 {
1066  static const char * finfoTypes[] = {"valueFinfo",
1067  "srcFinfo",
1068  "destFinfo",
1069  "lookupFinfo",
1070  "sharedFinfo",
1071  "fieldElementFinfo",
1072  0
1073  };
1074  return finfoTypes;
1075 }

+ Here is the caller graph for this function:

PyObject* getLookupField ( ObjId  target,
char *  fieldName,
PyObject *  key 
)

Inner function for looking up value from LookupField on object with ObjId target.

args should be a tuple (lookupFieldName, key)

Definition at line 1295 of file melement.cpp.

References moose::error, Field< A >::get(), parseFinfoType(), and shortType().

Referenced by moose_LookupField_getItem(), and moose_ObjId_getLookupField().

1296 {
1297  vector<string> type_vec;
1298  if (parseFinfoType(Field<string>::get(target, "className"), "lookupFinfo", string(fieldName), type_vec) < 0)
1299  {
1300  ostringstream error;
1301  error << "Cannot handle key type for LookupField `" << Field<string>::get(target, "className") << "." << fieldName << "`.";
1302  PyErr_SetString(PyExc_TypeError, error.str().c_str());
1303  return NULL;
1304  }
1305  if (type_vec.size() != 2)
1306  {
1307  ostringstream error;
1308  error << "LookupField type signature should be <keytype>, <valuetype>. But for `"
1309  << Field<string>::get(target, "className") << "." << fieldName << "` got " << type_vec.size() << " components." ;
1310  PyErr_SetString(PyExc_AssertionError, error.str().c_str());
1311  return NULL;
1312  }
1313  PyObject * ret = NULL;
1314  char key_type_code = shortType(type_vec[0]);
1315  char value_type_code = shortType(type_vec[1]);
1316  switch(key_type_code)
1317  {
1318  case 'b':
1319  {
1320  ret = lookup_value <bool> (target, string(fieldName), value_type_code, key_type_code, key);
1321  break;
1322  }
1323  case 'c':
1324  {
1325  ret = lookup_value <char> (target, string(fieldName), value_type_code, key_type_code, key);
1326  break;
1327  }
1328  case 'h':
1329  {
1330  ret = lookup_value <short> (target, string(fieldName), value_type_code, key_type_code, key);
1331  break;
1332  }
1333  case 'H':
1334  {
1335  ret = lookup_value <unsigned short> (target, string(fieldName), value_type_code, key_type_code, key);
1336  break;
1337  }
1338  case 'i':
1339  {
1340  ret = lookup_value <int> (target, string(fieldName), value_type_code, key_type_code, key);
1341  break;
1342  }
1343  case 'I':
1344  {
1345  ret = lookup_value <unsigned int> (target, string(fieldName), value_type_code, key_type_code, key);
1346  break;
1347  }
1348  case 'l':
1349  {
1350  ret = lookup_value <long> (target, string(fieldName), value_type_code, key_type_code, key);
1351  break;
1352  }
1353  case 'k':
1354  {
1355  ret = lookup_value <unsigned long> (target, string(fieldName), value_type_code, key_type_code, key);
1356  break;
1357  }
1358  case 'L':
1359  {
1360  ret = lookup_value <long long> (target, string(fieldName), value_type_code, key_type_code, key);
1361  break;
1362  }
1363  case 'K':
1364  {
1365  ret = lookup_value <unsigned long long> (target, string(fieldName), value_type_code, key_type_code, key);
1366  break;
1367  }
1368  case 'd':
1369  {
1370  ret = lookup_value <double> (target, string(fieldName), value_type_code, key_type_code, key);
1371  break;
1372  }
1373  case 'f':
1374  {
1375  ret = lookup_value <float> (target, string(fieldName), value_type_code, key_type_code, key);
1376  break;
1377  }
1378  case 's':
1379  {
1380  ret = lookup_value <string> (target, string(fieldName), value_type_code, key_type_code, key);
1381  break;
1382  }
1383  case 'x':
1384  {
1385  ret = lookup_value <Id> (target, string(fieldName), value_type_code, key_type_code, key);
1386  break;
1387  }
1388  case 'y':
1389  {
1390  ret = lookup_value <ObjId> (target, string(fieldName), value_type_code, key_type_code, key);
1391  break;
1392  }
1393  case 'D':
1394  {
1395  ret = lookup_value < vector <double> >(target, string(fieldName), value_type_code, key_type_code, key);
1396  break;
1397  }
1398  case 'S':
1399  {
1400  ret = lookup_value < vector <string> >(target, string(fieldName), value_type_code, key_type_code, key);
1401  break;
1402  }
1403  case 'X':
1404  {
1405  ret = lookup_value < vector <Id> >(target, string(fieldName), value_type_code, key_type_code, key);
1406  break;
1407  }
1408  case 'Y':
1409  {
1410  ret = lookup_value < vector <ObjId> >(target, string(fieldName), value_type_code, key_type_code, key);
1411  break;
1412  }
1413  case 'v':
1414  {
1415  ret = lookup_value < vector <int> >(target, string(fieldName), value_type_code, key_type_code, key);
1416  break;
1417  }
1418  case 'N':
1419  {
1420  ret = lookup_value < vector <unsigned int> >(target, string(fieldName), value_type_code, key_type_code, key);
1421  break;
1422  }
1423  case 'P':
1424  {
1425  ret = lookup_value < vector <unsigned long> >(target, string(fieldName), value_type_code, key_type_code, key);
1426  break;
1427  }
1428  case 'F':
1429  {
1430  ret = lookup_value < vector <float> >(target, string(fieldName), value_type_code, key_type_code, key);
1431  break;
1432  }
1433  case 'w':
1434  {
1435  ret = lookup_value < vector <short> >(target, string(fieldName), value_type_code, key_type_code, key);
1436  break;
1437  }
1438  case 'C':
1439  {
1440  ret = lookup_value < vector <char> >(target, string(fieldName), value_type_code, key_type_code, key);
1441  break;
1442  }
1443  default:
1444  ostringstream error;
1445  error << "Unhandled key type `" << type_vec[0] << "` for " << Field<string>::get(target, "className") << "." << fieldName;
1446  PyErr_SetString(PyExc_TypeError, error.str().c_str());
1447  }
1448  return ret;
1449 }
char shortType(string)
Definition: SetGet.h:236
int parseFinfoType(string className, string finfoType, string fieldName, vector< string > &typeVec)
static A get(const ObjId &dest, const string &field)
Definition: SetGet.h:284

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

PyObject* getObjIdAttr ( _ObjId oid,
string  attribute 
)
Id getShell ( int  argc,
char **  argv 
)

setup_runtime_env()

Create the shell instance unless already created. This calls basecode/main.cpp:init(argc, argv) to do the initialization.

Return the Id of the Shell object.

Definition at line 967 of file moosemodule.cpp.

References Eref::data(), doRegressionTests, Shell::doSetClock(), doUnitTests, Shell::doUseClock(), Id::eref(), init(), mooseBenchmarks(), mpiTests(), Shell::myNode(), nonMpiTests(), Shell::numNodes(), and processTests().

Referenced by finalize(), handle_keyboard_interrupts(), and MODINIT().

968 {
969  static int inited = 0;
970  if (inited)
971  {
972  return Id(0);
973  }
974  bool dounit = doUnitTests != 0;
975  bool doregress = doRegressionTests != 0;
976  unsigned int doBenchmark = 0;
977  // Utilize the main::init function which has friend access to Id
978  Id shellId = init(argc, argv, dounit, doregress, doBenchmark );
979  inited = 1;
980  Shell * shellPtr = reinterpret_cast<Shell*>(shellId.eref().data());
981  if (dounit)
982  {
983  nonMpiTests( shellPtr ); // These tests do not need the process loop.
984  }
985  if ( shellPtr->myNode() == 0 )
986  {
987  if ( Shell::numNodes() > 1 )
988  {
989  // Use the last clock for the postmaster, so that it is called
990  // after everything else has been processed and all messages
991  // are ready to send out.
992  shellPtr->doUseClock( "/postmaster", "process", 9 );
993  shellPtr->doSetClock( 9, 1.0 ); // Use a sensible default.
994  }
995 #ifdef DO_UNIT_TESTS
996  if ( dounit )
997  {
998  mpiTests();
999  processTests( shellPtr );
1000  }
1001  // if ( doRegressionTests ) regressionTests();
1002 #endif
1003  // These are outside unit tests because they happen in optimized
1004  // mode, using a command-line argument. As soon as they are done
1005  // the system quits, in order to estimate timing.
1006  if ( doBenchmark != 0 )
1007  {
1008  mooseBenchmarks( doBenchmark );
1009  }
1010  }
1011  return shellId;
1012 }
char * data() const
Definition: Eref.cpp:41
void mpiTests()
Definition: main.cpp:350
void doSetClock(unsigned int tickNum, double dt)
Definition: Shell.cpp:377
Eref eref() const
Definition: Id.cpp:125
void mooseBenchmarks(unsigned int option)
static int doRegressionTests
void processTests(Shell *)
Definition: main.cpp:333
void nonMpiTests(Shell *)
Definition: main.cpp:297
Id init(int argc, char **argv, bool &doUnitTests, bool &doRegressionTests, unsigned int &benchmark)
Definition: main.cpp:150
Definition: Id.h:17
static unsigned int myNode()
void doUseClock(string path, string field, unsigned int tick)
Definition: Shell.cpp:382
static int doUnitTests
static unsigned int numNodes()
Definition: Shell.h:43

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

PyMODINIT_FUNC init_moose ( )
char innerType ( char  )

Definition at line 104 of file types.cpp.

Referenced by get_vec_lookupfield(), and to_py().

104  {
105  static map<char, char> innerTypeMap;
106  if (innerTypeMap.empty()){
107  innerTypeMap.insert(pair<char, char>('D', 'd')); // vector<double>
108  innerTypeMap.insert(pair<char, char>('v', 'i')); // vector<int>
109  innerTypeMap.insert(pair<char, char>('M', 'l')); // vector<long>
110  innerTypeMap.insert(pair<char, char>('X', 'x')); // vector<Id>
111  innerTypeMap.insert(pair<char, char>('Y', 'y')); // vector<ObjId>
112  innerTypeMap.insert(pair<char, char>('C', 'c')); // vector<char>
113  innerTypeMap.insert(pair<char, char>('w', 'h')); // vector<short>
114  innerTypeMap.insert(pair<char, char>('N', 'I')); // vector<unsigned int>
115  innerTypeMap.insert(pair<char, char>('P', 'k')); // vector<unsigned long>
116  innerTypeMap.insert(pair<char, char>('A', 'L')); // vector<long long>
117  innerTypeMap.insert(pair<char, char>('B', 'K')); // vector<unsigned long long>
118  innerTypeMap.insert(pair<char, char>('F', 'f')); // vector<float>
119  innerTypeMap.insert(pair<char, char>('S', 's')); // vector<string>
120  innerTypeMap.insert(pair<char, char>('T', 'N')); // vector<vector<unsigned>>
121  innerTypeMap.insert(pair<char, char>('Q', 'v')); // vector<vector<int>>
122  innerTypeMap.insert(pair<char, char>('R', 'D')); // vector<vector<double>>
123  }
124  map<char, char>::iterator iter = innerTypeMap.find(typecode);
125  if (iter == innerTypeMap.end()){
126  return 0;
127  }
128  return iter->second;
129 }

+ Here is the caller graph for this function:

template<class KeyType >
PyObject* lookup_value ( const ObjId oid,
string  fname,
char  value_type_code,
char  key_type_code,
PyObject *  key 
)

Definition at line 386 of file moosemodule.h.

References to_cpp().

391 {
392  PyObject * ret = NULL;
393  KeyType * cpp_key = (KeyType *)to_cpp(key, key_type_code);
394  if (cpp_key == NULL)
395  {
396  return NULL;
397  }
398  // The case statements are arranged roughly in order of frequency
399  // of that data type. This is an attempt to optimize. We cannot
400  // use a map of function pointers because part of the template
401  // will be unspecialized (or we need N^2 templated fn instances).
402  switch (value_type_code)
403  {
404  case 'd':
405  ret = get_simple_lookupfield< KeyType, double>(oid, fname, *cpp_key, value_type_code);
406  break;
407  case 'D':
408  ret = get_vec_lookupfield<KeyType, double>(oid, fname, *cpp_key, value_type_code);
409  break;
410  case 'S':
411  ret = get_vec_lookupfield<KeyType, string>(oid, fname, *cpp_key, value_type_code);
412  break;
413  case 'i':
414  ret = get_simple_lookupfield < KeyType, int >(oid, fname, *cpp_key, value_type_code);
415  break;
416  case 'I':
417  ret = get_simple_lookupfield < KeyType, unsigned int >(oid, fname, *cpp_key, value_type_code);
418  break;
419  case 'y':
420  ret = get_simple_lookupfield< KeyType, ObjId >(oid, fname, *cpp_key, value_type_code);
421  break;
422  case 'x':
423  ret = get_simple_lookupfield<KeyType, Id>(oid, fname, *cpp_key, value_type_code);
424  break;
425  case 'l':
426  ret = get_simple_lookupfield< KeyType, long >(oid, fname, *cpp_key, value_type_code);
427  break;
428  case 'k':
429  ret = get_simple_lookupfield< KeyType, unsigned long >(oid, fname, *cpp_key, value_type_code);
430  break;
431  case 'f':
432  ret = get_simple_lookupfield< KeyType, float >(oid, fname, *cpp_key, value_type_code);
433  break;
434  case 'b': // boolean is a special case that PyBuildValue does not handle
435  ret = get_simple_lookupfield < KeyType, bool >(oid, fname, *cpp_key, value_type_code);
436  break;
437  case 'c':
438  ret = get_simple_lookupfield < KeyType, char >(oid, fname, *cpp_key, value_type_code);
439  break;
440  case 'h':
441  ret = get_simple_lookupfield < KeyType, short >(oid, fname, *cpp_key, value_type_code);
442  break;
443  case 'H':
444  ret = get_simple_lookupfield< KeyType, unsigned short >(oid, fname, *cpp_key, value_type_code);
445  break;
446 #ifdef HAVE_LONG_LONG
447  case 'L':
448  ret = get_simple_lookupfield< KeyType, long long>(oid, fname, *cpp_key, value_type_code);
449  break;
450  case 'K':
451  ret = get_simple_lookupfield< KeyType, unsigned long long>(oid, fname, *cpp_key, value_type_code);
452  break;
453 #endif
454  case 'X':
455  ret = get_vec_lookupfield<KeyType, Id>(oid, fname, *cpp_key, value_type_code);
456  break;
457  case 'Y':
458  ret = get_vec_lookupfield<KeyType, ObjId>(oid, fname, *cpp_key, value_type_code);
459  break;
460  case 'v':
461  ret = get_vec_lookupfield<KeyType, int>(oid, fname, *cpp_key, value_type_code);
462  break;
463  case 'w':
464  ret = get_vec_lookupfield<KeyType, short>(oid, fname, *cpp_key, value_type_code);
465  break;
466  case 'M':
467  ret = get_vec_lookupfield<KeyType, long>(oid, fname, *cpp_key, value_type_code);
468  break;
469  case 'N':
470  ret = get_vec_lookupfield<KeyType, unsigned int>(oid, fname, *cpp_key, value_type_code);
471  break;
472  case 'P':
473  ret = get_vec_lookupfield<KeyType, unsigned long>(oid, fname, *cpp_key, value_type_code);
474  break;
475  case 'F':
476  ret = get_vec_lookupfield<KeyType, float>(oid, fname, *cpp_key, value_type_code);
477  break;
478  default:
479  PyErr_SetString(PyExc_TypeError, "invalid value type");
480  }
481  delete cpp_key;
482  return ret;
483 }
void * to_cpp(PyObject *object, char typecode)

+ Here is the call graph for this function:

PyObject* moose_connect ( PyObject *  dummy,
PyObject *  args 
)

Definition at line 1982 of file moosemodule.cpp.

References ObjId::bad(), ObjId::id, _Id::id_, Id_SubtypeCheck, Id::isValid(), ObjId_SubtypeCheck, _ObjId::oid_, oid_to_element(), RAISE_INVALID_ID, and SHELLPTR.

1983 {
1984  PyObject * srcPtr = NULL, * destPtr = NULL;
1985  char * srcField = NULL, * destField = NULL, * msgType = NULL;
1986  static char default_msg_type[] = "Single";
1987  if(!PyArg_ParseTuple(args, "OsOs|s:moose_connect", &srcPtr, &srcField, &destPtr, &destField, &msgType))
1988  {
1989  return NULL;
1990  }
1991  if (msgType == NULL)
1992  {
1993  msgType = default_msg_type;
1994  }
1995  ObjId dest, src;
1996  if (ObjId_SubtypeCheck(srcPtr))
1997  {
1998  _ObjId * _src = reinterpret_cast<_ObjId*>(srcPtr);
1999  src = _src->oid_;
2000  }
2001  else if (Id_SubtypeCheck(srcPtr))
2002  {
2003  _Id * _src = reinterpret_cast<_Id*>(srcPtr);
2004  src = ObjId(_src->id_);
2005  }
2006  else if (PyString_Check(srcPtr))
2007  {
2008  char * _src = PyString_AsString(srcPtr);
2009  src = ObjId(string(_src));
2010  }
2011  else
2012  {
2013  PyErr_SetString(PyExc_TypeError, "source does not resolve to an element.");
2014  return NULL;
2015  }
2016  if (ObjId_SubtypeCheck(destPtr))
2017  {
2018  _ObjId * _dest = reinterpret_cast<_ObjId*>(destPtr);
2019  dest = _dest->oid_;
2020  }
2021  else if (Id_SubtypeCheck(destPtr))
2022  {
2023  _Id * _dest = reinterpret_cast<_Id*>(destPtr);
2024  dest = ObjId(_dest->id_);
2025  }
2026  else if (PyString_Check(destPtr))
2027  {
2028  char * _dest = PyString_AsString(destPtr);
2029  dest = ObjId(string(_dest));
2030  }
2031  else
2032  {
2033  PyErr_SetString(PyExc_TypeError, "target does not resolve to an element.");
2034  return NULL;
2035  }
2036  if (!Id::isValid(dest.id) || !Id::isValid(src.id))
2037  {
2038  RAISE_INVALID_ID(NULL, "moose_connect");
2039  }
2040  ObjId mid = SHELLPTR->doAddMsg(msgType, src, string(srcField), dest, string(destField));
2041  if ( mid.bad() )
2042  {
2043  PyErr_SetString(PyExc_NameError, "check field names and type compatibility.");
2044  return NULL;
2045  }
2046  return oid_to_element(mid);
2047 }
PyObject_HEAD Id id_
Definition: moosemodule.h:114
#define ObjId_SubtypeCheck(v)
Definition: moosemodule.h:98
#define SHELLPTR
Definition: moosemodule.h:105
bool bad() const
Definition: ObjId.cpp:18
Id id
Definition: ObjId.h:98
Definition: ObjId.h:20
#define RAISE_INVALID_ID(ret, msg)
Definition: moosemodule.h:71
PyObject_HEAD ObjId oid_
Definition: moosemodule.h:133
#define Id_SubtypeCheck(v)
Definition: moosemodule.h:96
static bool isValid(Id id)
Definition: Id.h:145
PyObject * oid_to_element(ObjId oid)

+ Here is the call graph for this function:

PyObject* moose_copy ( PyObject *  dummy,
PyObject *  args,
PyObject *  kwargs 
)

Definition at line 1391 of file moosemodule.cpp.

References ObjId::bad(), Field< A >::get(), _Id::id_, Id::id_, IdType, Id::isValid(), name, ObjIdType, RAISE_INVALID_ID, and SHELLPTR.

1392 {
1393  PyObject * src = NULL, * dest = NULL;
1394  char * newName = NULL;
1395  static const char * kwlist[] = {"src", "dest", "name", "n", "toGlobal", "copyExtMsg", NULL};
1396  unsigned int num=1, toGlobal=0, copyExtMsgs=0;
1397  if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OO|sIII", const_cast<char**>(kwlist), &src, &dest, &newName, &num, &toGlobal, &copyExtMsgs))
1398  {
1399  return NULL;
1400  }
1401  Id _src;
1402  ObjId _dest;
1403  if (PyObject_IsInstance(src, (PyObject*)&IdType))
1404  {
1405  _src = ((_Id*)src)->id_;
1406  }
1407  else if (PyObject_IsInstance(src, (PyObject*)&ObjIdType))
1408  {
1409  _src = ((_ObjId*)src)->oid_.id;
1410  }
1411  else if (PyString_Check(src))
1412  {
1413  _src = Id(PyString_AsString(src));
1414  }
1415  else
1416  {
1417  PyErr_SetString(PyExc_TypeError, "Source must be instance of vec, element or string.");
1418  return NULL;
1419  }
1420  if (_src == Id())
1421  {
1422  PyErr_SetString(PyExc_ValueError, "Cannot make copy of moose shell.");
1423  return NULL;
1424  }
1425  if (PyObject_IsInstance(dest, (PyObject*)&IdType))
1426  {
1427  _dest = ObjId(((_Id*)dest)->id_);
1428  }
1429  else if (PyObject_IsInstance(dest, (PyObject*)&ObjIdType))
1430  {
1431  _dest = ((_ObjId*)dest)->oid_;
1432  }
1433  else if (PyString_Check(dest))
1434  {
1435  _dest = ObjId(PyString_AsString(dest));
1436  }
1437  else
1438  {
1439  PyErr_SetString(PyExc_TypeError, "destination must be instance of vec, element or string.");
1440  return NULL;
1441  }
1442  if (!Id::isValid(_src))
1443  {
1444  RAISE_INVALID_ID(NULL, "moose_copy: invalid source Id.");
1445  }
1446  else if (_dest.bad())
1447  {
1448  RAISE_INVALID_ID(NULL, "moose_copy: invalid destination.");
1449  }
1450  string name;
1451  if (newName == NULL)
1452  {
1453  // Use the original name if name is not specified.
1454  name = Field<string>::get(ObjId(_src, 0), "name");
1455  }
1456  else
1457  {
1458  name = string(newName);
1459  }
1460  _Id * tgt = PyObject_New(_Id, &IdType);
1461  tgt->id_ = SHELLPTR->doCopy(_src, _dest, name, num, toGlobal, copyExtMsgs);
1462  PyObject * ret = (PyObject*)tgt;
1463  return ret;
1464 }
PyObject_HEAD Id id_
Definition: moosemodule.h:114
#define SHELLPTR
Definition: moosemodule.h:105
bool bad() const
Definition: ObjId.cpp:18
Definition: ObjId.h:20
#define RAISE_INVALID_ID(ret, msg)
Definition: moosemodule.h:71
PyTypeObject ObjIdType
static bool isValid(Id id)
Definition: Id.h:145
static char name[]
Definition: mfield.cpp:401
Definition: Id.h:17
static A get(const ObjId &dest, const string &field)
Definition: SetGet.h:284
PyTypeObject IdType
Definition: vec.cpp:262
unsigned int id_
Definition: Id.h:172

+ Here is the call graph for this function:

PyObject* moose_delete ( PyObject *  dummy,
PyObject *  args 
)

Definition at line 1544 of file moosemodule.cpp.

References ObjId::bad(), BADINDEX, deleteObjId(), IdType, ObjIdType, and RAISE_INVALID_ID.

1545 {
1546  PyObject * obj;
1547  bool isId_ = false;
1548  bool isObjId_ = false;
1549  if (!PyArg_ParseTuple(args, "O:moose.delete", &obj))
1550  {
1551  return NULL;
1552  }
1553  // if (!PyObject_IsInstance(obj, (PyObject*)&IdType)){
1554  // PyErr_SetString(PyExc_TypeError, "vec instance expected");
1555  // return NULL;
1556  // }
1557  ObjId oid_;
1558  if (PyObject_IsInstance(obj, (PyObject*)&IdType))
1559  {
1560  oid_ = ((_Id*)obj)->id_;
1561  isId_ = true;
1562  }
1563  else if (PyObject_IsInstance(obj, (PyObject*)&ObjIdType))
1564  {
1565  oid_ = ((_ObjId*)obj)->oid_;
1566  isObjId_ = true;
1567  }
1568  else if (PyString_Check(obj))
1569  {
1570  oid_ = ObjId(PyString_AsString(obj));
1571  }
1572  else
1573  {
1574  PyErr_SetString(PyExc_ValueError, "cannot delete moose shell.");
1575  return NULL;
1576  }
1577  if (oid_ == ObjId())
1578  {
1579  PyErr_SetString(PyExc_ValueError, "cannot delete moose shell.");
1580  return NULL;
1581  }
1582  if ( oid_.bad() )
1583  {
1584  RAISE_INVALID_ID(NULL, "moose_delete");
1585  }
1586  deleteObjId(oid_);
1587  if (isId_)
1588  {
1589  ((_Id*)obj)->id_ = Id();
1590  }
1591  if (isObjId_)
1592  {
1593  ((_ObjId*)obj)->oid_ = ObjId(0, BADINDEX, BADINDEX);
1594  }
1595  // SHELLPTR->doDelete(((_Id*)obj)->id_);
1596  Py_RETURN_NONE;
1597 }
PyObject * deleteObjId(ObjId obj)
Definition: vec.cpp:522
bool bad() const
Definition: ObjId.cpp:18
Definition: ObjId.h:20
#define RAISE_INVALID_ID(ret, msg)
Definition: moosemodule.h:71
PyTypeObject ObjIdType
Definition: Id.h:17
PyTypeObject IdType
Definition: vec.cpp:262
const unsigned int BADINDEX
Used by ObjId and Eref.
Definition: consts.cpp:25

+ Here is the call graph for this function:

PyObject* moose_element ( PyObject *  dummy,
PyObject *  args 
)

Definition at line 2931 of file moosemodule.cpp.

References ObjId::bad(), ElementField_SubtypeCheck, id, IdType, moose_ElementField_getId(), ObjIdType, oid_to_element(), and path.

2932 {
2933  char * path = NULL;
2934  PyObject * obj = NULL;
2935  ObjId oid;
2936  unsigned nid = 0, did = 0, fidx = 0;
2937  Id id;
2938  unsigned int numData = 0;
2939  if (PyArg_ParseTuple(args, "s", &path))
2940  {
2941  oid = ObjId(path);
2942  // cout << "Original Path " << path << ", Element Path: " << oid.path() << endl;
2943  if ( oid.bad() )
2944  {
2945  PyErr_SetString(PyExc_ValueError, ( std::string("moose_element: '")
2946  + std::string(path)
2947  + std::string("' does not exist!")
2948  ).c_str()
2949  );
2950  return NULL;
2951  }
2952  PyObject * new_obj = oid_to_element(oid);
2953  if (new_obj)
2954  {
2955  return new_obj;
2956  }
2957  PyErr_SetString(PyExc_TypeError, "moose_element: unknown class");
2958  return NULL;
2959  }
2960  PyErr_Clear();
2961  if (PyArg_ParseTuple(args, "I|II", &nid, &did, &fidx))
2962  {
2963  oid = ObjId(id, did, fidx);
2964  // Todo: test for validity
2965  PyObject * new_obj = oid_to_element(oid);
2966  if (!new_obj)
2967  {
2968  PyErr_SetString(PyExc_RuntimeError, "moose_element: not a moose class.");
2969  }
2970  return new_obj;
2971  }
2972  PyErr_Clear();
2973  if (!PyArg_ParseTuple(args, "O|II", &obj, &did, &fidx))
2974  {
2975  PyErr_SetString(PyExc_TypeError, "moose_element: argument must be a path or an existing element or an vec");
2976  return NULL;
2977  }
2978  // PyErr_Clear();
2979  if (PyObject_IsInstance(obj, (PyObject*)&ObjIdType))
2980  {
2981  oid = ((_ObjId*)obj)->oid_;
2982  }
2983  else if (PyObject_IsInstance(obj, (PyObject*)&IdType))
2984  {
2985  oid = ObjId(((_Id*)obj)->id_, did, fidx); // TODO: check for validity
2986  }
2987  else if (ElementField_SubtypeCheck(obj))
2988  {
2989  oid = ObjId(((_Id*)moose_ElementField_getId((_Field*)obj, NULL))->id_);
2990  }
2991  if (oid.bad())
2992  {
2993  PyErr_SetString(PyExc_TypeError, "moose_element: cannot convert to moose element.");
2994  return NULL;
2995  }
2996  PyObject * new_obj = oid_to_element(oid);
2997  if (!new_obj)
2998  {
2999  PyErr_SetString(PyExc_RuntimeError, "moose_element: not a moose class.");
3000  }
3001  return new_obj;
3002 }
bool bad() const
Definition: ObjId.cpp:18
Definition: ObjId.h:20
#define ElementField_SubtypeCheck(v)
Definition: moosemodule.h:101
PyTypeObject ObjIdType
Definition: Id.h:17
PyObject * moose_ElementField_getId(_Field *self, void *closure)
Definition: mfield.cpp:581
PyTypeObject IdType
Definition: vec.cpp:262
PyObject * oid_to_element(ObjId oid)
static char id[]
Definition: mfield.cpp:404
static char path[]
Definition: mfield.cpp:403

+ Here is the call graph for this function:

PyObject* moose_ElementField_getattro ( _Field self,
PyObject *  attr 
)

Definition at line 685 of file mfield.cpp.

References Field< A >::get(), get_field_alias(), getFieldType(), Field< A >::getVec(), RAISE_INVALID_ID, shortType(), and to_pytuple().

686 {
687  int new_attr = 0;
688  PyObject * ret = NULL;
689  if (self->owner->oid_.bad())
690  {
691  RAISE_INVALID_ID(NULL, "moose_ElementField_getSlice");
692  }
693  char * field = PyString_AsString(attr);
694  string className = Field<string>::get(self->myoid, "className");
695  string type = getFieldType(className, field);
696  if (type.empty())
697  {
698  // Check if this field name is aliased and update fieldname and type if so.
699  map<string, string>::const_iterator it = get_field_alias().find(string(field));
700  if (it != get_field_alias().end())
701  {
702  field = const_cast<char*>((it->second).c_str());
703  type = getFieldType(Field<string>::get(self->myoid, "className"), it->second);
704  // Update attr for next level (PyObject_GenericGetAttr) in case.
705  new_attr = 1;
706  attr = PyString_FromString(field);
707  }
708  }
709  if (type.empty())
710  {
711  ret = PyObject_GenericGetAttr((PyObject*)self, attr);
712  if (new_attr)
713  {
714  Py_DECREF(attr);
715  return ret;
716  }
717  }
718  char ftype = shortType(type);
719  switch (ftype)
720  {
721  case 'd':
722  {
723  vector < double > val;
724  Field< double >::getVec(self->myoid, string(field), val);
725  ret = to_pytuple(&val, ftype);
726  break;
727  }
728  case 's':
729  {
730  vector < string > val;
731  Field< string >::getVec(self->myoid, string(field), val);
732  ret = to_pytuple(&val, ftype);
733  break;
734  }
735  case 'l':
736  {
737  vector < long > val;
738  Field< long >::getVec(self->myoid, string(field), val);
739  ret = to_pytuple(&val, ftype);
740  break;
741  }
742  case 'x':
743  {
744  vector < Id > val;
745  Field< Id >::getVec(self->myoid, string(field), val);
746  ret = to_pytuple(&val, ftype);
747  break;
748  }
749  case 'y':
750  {
751  vector < ObjId > val;
752  Field< ObjId >::getVec(self->myoid, string(field), val);
753  ret = to_pytuple(&val, ftype);
754  break;
755  }
756  case 'i':
757  {
758  vector < int > val;
759  Field< int >::getVec(self->myoid, string(field), val);
760  ret = to_pytuple(&val, ftype);
761  break;
762  }
763  case 'I':
764  {
765  vector < unsigned int > val;
766  Field< unsigned int >::getVec(self->myoid, string(field), val);
767  ret = to_pytuple(&val, ftype);
768  break;
769  }
770  case 'k':
771  {
772  vector < unsigned long > val;
773  Field< unsigned long >::getVec(self->myoid, string(field), val);
774  ret = to_pytuple(&val, ftype);
775  break;
776  }
777  case 'f':
778  {
779  vector < float > val;
780  Field< float >::getVec(self->myoid, string(field), val);
781  ret = to_pytuple(&val, ftype);
782  break;
783  }
784  case 'b':
785  {
786  vector<bool> val;
787  Field< bool >::getVec(self->myoid, string(field), val);
788  ret = to_pytuple(&val, ftype);
789  break;
790  }
791  case 'c':
792  {
793  vector < char > val;
794  Field< char >::getVec(self->myoid, string(field), val);
795  ret = to_pytuple(&val, ftype);
796  break;
797  }
798  case 'h':
799  {
800  vector < short > val;
801  Field< short >::getVec(self->myoid, string(field), val);
802  ret = to_pytuple(&val, ftype);
803  break;
804  }
805  case 'z':
806  {
807  PyErr_SetString(PyExc_NotImplementedError, "DataId handling not implemented yet.");
808  break;
809  }
810  case 0:
811  {
812  ret = PyObject_GenericGetAttr((PyObject*)self, attr);
813  break;
814  }
815  default:
816  PyErr_SetString(PyExc_ValueError, "unhandled field type.");
817  break;
818  }
819  if (new_attr)
820  {
821  Py_DECREF(attr);
822  }
823  return ret;
824 }
char shortType(string)
bool bad() const
Definition: ObjId.cpp:18
Definition: SetGet.h:236
const map< string, string > & get_field_alias()
#define RAISE_INVALID_ID(ret, msg)
Definition: moosemodule.h:71
PyObject_HEAD ObjId oid_
Definition: moosemodule.h:133
ObjId myoid
Definition: moosemodule.h:141
_ObjId * owner
Definition: moosemodule.h:140
PyObject * to_pytuple(void *obj, char typecode)
string getFieldType(string className, string fieldName)
static A get(const ObjId &dest, const string &field)
Definition: SetGet.h:284
static void getVec(ObjId dest, const string &field, vector< A > &vec)
Definition: SetGet.h:317

+ Here is the call graph for this function:

PyObject* moose_ElementField_getDataId ( _Field self,
void *  closure 
)

Definition at line 602 of file mfield.cpp.

References RAISE_INVALID_ID.

603 {
604  if (self->owner->oid_.bad())
605  {
606  RAISE_INVALID_ID(NULL, "moose_ElementField_getItem");
607  }
608  return Py_BuildValue("I", self->owner->oid_.dataIndex);
609 }
bool bad() const
Definition: ObjId.cpp:18
#define RAISE_INVALID_ID(ret, msg)
Definition: moosemodule.h:71
PyObject_HEAD ObjId oid_
Definition: moosemodule.h:133
_ObjId * owner
Definition: moosemodule.h:140
unsigned int dataIndex
Definition: ObjId.h:99
PyObject* moose_ElementField_getId ( _Field self,
void *  closure 
)

Definition at line 581 of file mfield.cpp.

References IdType, and RAISE_INVALID_ID.

Referenced by moose_element().

582 {
583  if (self->owner->oid_.bad())
584  {
585  RAISE_INVALID_ID(NULL, "moose_ElementField_setNum");
586  }
587  Id myId(self->owner->oid_.path() + "/" + string(self->name));
588  _Id * new_id = PyObject_New(_Id, &IdType);
589  new_id->id_ = myId;
590  return (PyObject*)new_id;
591 }
bool bad() const
Definition: ObjId.cpp:18
PyTypeObject IdType
Definition: vec.cpp:262
#define RAISE_INVALID_ID(ret, msg)
Definition: moosemodule.h:71
PyObject_HEAD ObjId oid_
Definition: moosemodule.h:133
string path() const
Definition: ObjId.cpp:119
_ObjId * owner
Definition: moosemodule.h:140
PyObject_HEAD char * name
Definition: moosemodule.h:139
Definition: Id.h:17

+ Here is the caller graph for this function:

PyObject* moose_ElementField_getItem ( _Field self,
Py_ssize_t  index 
)

Definition at line 611 of file mfield.cpp.

References Field< A >::get(), oid_to_element(), and RAISE_INVALID_ID.

612 {
613  if (self->owner->oid_.bad())
614  {
615  RAISE_INVALID_ID(NULL, "moose_ElementField_getItem");
616  }
617  int len = Field<unsigned int>::get(self->myoid, "numField");
618  assert(len >= 0);
619  if (index >= len)
620  {
621  PyErr_SetString(PyExc_IndexError, "moose.ElementField.getItem: index out of bounds.");
622  return NULL;
623  }
624  if (index < 0)
625  {
626  index += len;
627  }
628  if (index < 0)
629  {
630  PyErr_SetString(PyExc_IndexError, "moose.ElementField.getItem: invalid index.");
631  return NULL;
632  }
633  // _ObjId * oid = PyObject_New(_ObjId, &ObjIdType);
634  // cout << "Element field: " << self->name << ", owner: " << self->owner->oid_.path() << endl;
635  // stringstream path;
636  // path << self->owner->oid_.path() << "/" << self->name << "[" << index << "]";
637  // cout << "moose_ElementField_getItem:: path=" << path.str();
638  // oid->oid_ = ObjId(self->myoid.id, self->myoid.dataIndex, index);
639  // return (PyObject*)oid;
640  ObjId oid(self->myoid.id, self->myoid.dataIndex, index);
641  return oid_to_element(oid);
642 }
bool bad() const
Definition: ObjId.cpp:18
Id id
Definition: ObjId.h:98
Definition: ObjId.h:20
#define RAISE_INVALID_ID(ret, msg)
Definition: moosemodule.h:71
PyObject_HEAD ObjId oid_
Definition: moosemodule.h:133
ObjId myoid
Definition: moosemodule.h:141
_ObjId * owner
Definition: moosemodule.h:140
static A get(const ObjId &dest, const string &field)
Definition: SetGet.h:284
PyObject * oid_to_element(ObjId oid)
unsigned int dataIndex
Definition: ObjId.h:99

+ Here is the call graph for this function:

Py_ssize_t moose_ElementField_getLen ( _Field self,
void *  closure 
)

Definition at line 561 of file mfield.cpp.

References Field< A >::get(), and RAISE_INVALID_ID.

Referenced by moose_ElementField_setattro().

562 {
563  if (self->owner->oid_.bad())
564  {
565  RAISE_INVALID_ID(-1, "moose_ElementField_getLen");
566  }
567  unsigned int num = Field<unsigned int>::get(self->myoid, "numField");
568  return Py_ssize_t(num);
569 }
bool bad() const
Definition: ObjId.cpp:18
#define RAISE_INVALID_ID(ret, msg)
Definition: moosemodule.h:71
PyObject_HEAD ObjId oid_
Definition: moosemodule.h:133
ObjId myoid
Definition: moosemodule.h:141
_ObjId * owner
Definition: moosemodule.h:140
static A get(const ObjId &dest, const string &field)
Definition: SetGet.h:284

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

PyObject* moose_ElementField_getName ( _Field self,
void *  closure 
)

Definition at line 593 of file mfield.cpp.

594 {
595  return Py_BuildValue("s", self->name);
596 }
PyObject_HEAD char * name
Definition: moosemodule.h:139
PyObject* moose_ElementField_getNum ( _Field self,
void *  closure 
)

Definition at line 528 of file mfield.cpp.

References Field< A >::get(), and RAISE_INVALID_ID.

529 {
530  if (self->owner->oid_.bad())
531  {
532  RAISE_INVALID_ID(NULL, "moose_ElementField_getNum");
533  }
534  string name = self->name;
535  name[0] = std::toupper( name[0] );
536  unsigned int num = Field<unsigned int>::get(self->myoid, "numField");
537  return Py_BuildValue("I", num);
538 }
bool bad() const
Definition: ObjId.cpp:18
#define RAISE_INVALID_ID(ret, msg)
Definition: moosemodule.h:71
PyObject_HEAD ObjId oid_
Definition: moosemodule.h:133
ObjId myoid
Definition: moosemodule.h:141
_ObjId * owner
Definition: moosemodule.h:140
static char name[]
Definition: mfield.cpp:401
static A get(const ObjId &dest, const string &field)
Definition: SetGet.h:284

+ Here is the call graph for this function:

PyObject* moose_ElementField_getOwner ( _Field self,
void *  closure 
)

Definition at line 597 of file mfield.cpp.

598 {
599  Py_INCREF(self->owner);
600  return (PyObject*)self->owner;
601 }
_ObjId * owner
Definition: moosemodule.h:140
PyObject* moose_ElementField_getPath ( _Field self,
void *  closure 
)

Definition at line 571 of file mfield.cpp.

References Id::isValid(), path, and RAISE_INVALID_ID.

572 {
573  if (!Id::isValid(self->owner->oid_.id))
574  {
575  RAISE_INVALID_ID(NULL, "moose_ElementField_setNum");
576  }
577  string path = Id(self->owner->oid_.path() + "/" + string(self->name)).path();
578  return Py_BuildValue("s", path.c_str());
579 }
Id id
Definition: ObjId.h:98
#define RAISE_INVALID_ID(ret, msg)
Definition: moosemodule.h:71
PyObject_HEAD ObjId oid_
Definition: moosemodule.h:133
string path() const
Definition: ObjId.cpp:119
_ObjId * owner
Definition: moosemodule.h:140
PyObject_HEAD char * name
Definition: moosemodule.h:139
static bool isValid(Id id)
Definition: Id.h:145
Definition: Id.h:17
static char path[]
Definition: mfield.cpp:403

+ Here is the call graph for this function:

PyObject* moose_ElementField_getSlice ( _Field self,
Py_ssize_t  start,
Py_ssize_t  end 
)

Definition at line 644 of file mfield.cpp.

References Field< A >::get(), oid_to_element(), RAISE_INVALID_ID, and value.

645 {
646  assert(start >= 0);
647  assert(end >= 0);
648 
649  if (self->owner->oid_.bad())
650  {
651  RAISE_INVALID_ID(NULL, "moose_ElementField_getSlice");
652  }
653  Py_ssize_t len = Field<unsigned int>::get(self->myoid, "numField");
654  while (start < 0)
655  {
656  start += len;
657  }
658  while (end < 0)
659  {
660  end += len;
661  }
662  if (start > end)
663  {
664  // PyErr_SetString(PyExc_IndexError, "Start index must be less than end.");
665  // return NULL;
666  // Python itself returns empty tuple in such cases, follow that
667  return PyTuple_New(0);
668  }
669  PyObject * ret = PyTuple_New((Py_ssize_t)(end - start));
670  for ( int ii = start; ii < end; ++ii)
671  {
672  ObjId oid(self->myoid.id, self->myoid.dataIndex, ii);
673  PyObject * value = oid_to_element(oid);
674  if (PyTuple_SetItem(ret, (Py_ssize_t)(ii-start), value))
675  {
676  Py_XDECREF(ret);
677  // Py_XDECREF(value);
678  PyErr_SetString(PyExc_RuntimeError, "Could not assign tuple entry.");
679  return NULL;
680  }
681  }
682  return ret;
683 }
uint32_t value
Definition: moosemodule.h:42
bool bad() const
Definition: ObjId.cpp:18
Id id
Definition: ObjId.h:98
Definition: ObjId.h:20
#define RAISE_INVALID_ID(ret, msg)
Definition: moosemodule.h:71
PyObject_HEAD ObjId oid_
Definition: moosemodule.h:133
ObjId myoid
Definition: moosemodule.h:141
_ObjId * owner
Definition: moosemodule.h:140
static A get(const ObjId &dest, const string &field)
Definition: SetGet.h:284
PyObject * oid_to_element(ObjId oid)
unsigned int dataIndex
Definition: ObjId.h:99

+ Here is the call graph for this function:

int moose_ElementField_init ( _Field self,
PyObject *  args,
PyObject *  kwargs 
)

Initialize field with ObjId and fieldName.

Definition at line 519 of file mfield.cpp.

References moose_Field_init().

520 {
521  moose_Field_init(self, args, kwargs);
522  string path = self->owner->oid_.path()+"/";
523  path += string(self->name);
524  self->myoid = ObjId(path);
525  return 0;
526 }
int moose_Field_init(_Field *self, PyObject *args, PyObject *kwargs)
Definition: mfield.cpp:89
Definition: ObjId.h:20
PyObject_HEAD char * name
Definition: moosemodule.h:139
static char path[]
Definition: mfield.cpp:403

+ Here is the call graph for this function:

int moose_ElementField_setattro ( _Field self,
PyObject *  attr,
PyObject *  value 
)

Definition at line 826 of file mfield.cpp.

References Field< A >::get(), getFieldType(), Id::isValid(), moose_ElementField_getLen(), RAISE_INVALID_ID, Field< A >::setVec(), shortType(), and value.

827 {
828  if (!Id::isValid(self->myoid))
829  {
830  RAISE_INVALID_ID(-1, "moose_ElementField_setattro");
831  }
832  int ret = -1;
833  string field;
834  if (PyString_Check(attr))
835  {
836  field = string(PyString_AsString(attr));
837  }
838  else
839  {
840  PyErr_SetString(PyExc_TypeError, "Attribute name must be a string");
841  return -1;
842  }
843  string moose_class = Field<string>::get(self->myoid, "className");
844  string fieldtype = getFieldType(moose_class, field);
845  if (fieldtype.length() == 0)
846  {
847  if (field == "num")
848  {
849  return PyObject_GenericSetAttr((PyObject*)self, attr, value);
850  }
851  PyErr_SetString(PyExc_AttributeError, "cannot add new field to ElementField objects");
852  return -1;
853  }
854  char ftype = shortType(fieldtype);
855  Py_ssize_t length = moose_ElementField_getLen(self, NULL);
856  bool is_seq = true;
857  if (!PySequence_Check(value))
858  {
859  is_seq = false;
860  }
861  else if (length != PySequence_Length(value))
862  {
863  PyErr_SetString(PyExc_IndexError, "Length of the sequence on the right hand side does not match Id size.");
864  return -1;
865  }
866 
867  assert(length >= 0);
868  switch(ftype)
869  {
870  case 'd': //SET_VECFIELD(double, d)
871  {
872  vector<double> _value;
873  if (is_seq)
874  {
875  for ( int ii = 0; ii < length; ++ii)
876  {
877  double v = PyFloat_AsDouble(PySequence_GetItem(value, ii));
878  _value.push_back(v);
879  }
880  }
881  else
882  {
883  double v = PyFloat_AsDouble(value);
884  _value.assign(length, v);
885  }
886  ret = Field<double>::setVec(self->myoid, field, _value);
887  break;
888  }
889  case 's':
890  {
891  vector<string> _value;
892  if (is_seq)
893  {
894  for ( int ii = 0; ii < length; ++ii)
895  {
896  char * v = PyString_AsString(PySequence_GetItem(value, ii));
897  _value.push_back(string(v));
898  }
899  }
900  else
901  {
902  char * v = PyString_AsString(value);
903  _value.assign(length, string(v));
904  }
905  ret = Field<string>::setVec(self->myoid, field, _value);
906  break;
907  }
908  case 'i':
909  {
910  vector<int> _value;
911  if (is_seq)
912  {
913  for ( int ii = 0; ii < length; ++ii)
914  {
915  int v = PyInt_AsLong(PySequence_GetItem(value, ii));
916  _value.push_back(v);
917  }
918  }
919  else
920  {
921  int v = PyInt_AsLong(value);
922  _value.assign(length, v);
923  }
924  ret = Field< int >::setVec(self->myoid, field, _value);
925  break;
926  }
927  case 'I': //SET_VECFIELD(unsigned int, I)
928  {
929  vector<unsigned int> _value;
930  if (is_seq)
931  {
932  for ( int ii = 0; ii < length; ++ii)
933  {
934  unsigned int v = PyInt_AsUnsignedLongMask(PySequence_GetItem(value, ii));
935  _value.push_back(v);
936  }
937  }
938  else
939  {
940  unsigned int v = PyInt_AsUnsignedLongMask(value);
941  _value.assign(length, v);
942  }
943  ret = Field< unsigned int >::setVec(self->myoid, field, _value);
944  break;
945  }
946  case 'l': //SET_VECFIELD(long, l)
947  {
948  vector<long> _value;
949  if (is_seq)
950  {
951  for ( int ii = 0; ii < length; ++ii)
952  {
953  long v = PyInt_AsLong(PySequence_GetItem(value, ii));
954  _value.push_back(v);
955  }
956  }
957  else
958  {
959  long v = PyInt_AsLong(value);
960  _value.assign(length, v);
961  }
962  ret = Field<long>::setVec(self->myoid, field, _value);
963  break;
964  }
965  case 'k': //SET_VECFIELD(unsigned long, k)
966  {
967  vector<unsigned long> _value;
968  if (is_seq)
969  {
970  for ( int ii = 0; ii < length; ++ii)
971  {
972  unsigned long v = PyInt_AsUnsignedLongMask(PySequence_GetItem(value, ii));
973  _value.push_back(v);
974  }
975  }
976  else
977  {
978  unsigned long v = PyInt_AsUnsignedLongMask(value);
979  _value.assign(length, v);
980  }
981  ret = Field< unsigned long >::setVec(self->myoid, field, _value);
982  break;
983  }
984  case 'b':
985  {
986  vector<bool> _value;
987  if (is_seq)
988  {
989  for ( int ii = 0; ii < length; ++ii)
990  {
991  PyObject * _v = PySequence_GetItem(value, ii);
992  bool v = (Py_True ==_v) || (PyInt_AsLong(_v) != 0);
993  _value.push_back(v);
994  }
995  }
996  else
997  {
998  bool v = (Py_True ==value) || (PyInt_AsLong(value) != 0);
999  _value.assign(length, v);
1000  }
1001  ret = Field< bool >::setVec(self->myoid, field, _value);
1002  break;
1003  }
1004  case 'c':
1005  {
1006  vector<char> _value;
1007  if (is_seq)
1008  {
1009  for ( int ii = 0; ii < length; ++ii)
1010  {
1011  PyObject * _v = PySequence_GetItem(value, ii);
1012  char * v = PyString_AsString(_v);
1013  if (v && v[0])
1014  {
1015  _value.push_back(v[0]);
1016  }
1017  else
1018  {
1019  ostringstream err;
1020  err << ii << "-th element is NUL";
1021  PyErr_SetString(PyExc_ValueError, err.str().c_str());
1022  return -1;
1023  }
1024  }
1025  }
1026  else
1027  {
1028  char * v = PyString_AsString(value);
1029  if (v && v[0])
1030  {
1031  _value.assign(length, v[0]);
1032  }
1033  else
1034  {
1035  PyErr_SetString(PyExc_ValueError, "value is an empty string");
1036  return -1;
1037  }
1038  }
1039  ret = Field< char >::setVec(self->myoid, field, _value);
1040  break;
1041  }
1042  case 'h':
1043  {
1044  vector<short> _value;
1045  if (is_seq)
1046  {
1047  for ( int ii = 0; ii < length; ++ii)
1048  {
1049  short v = PyInt_AsLong(PySequence_GetItem(value, ii));
1050  _value.push_back(v);
1051  }
1052  }
1053  else
1054  {
1055  short v = PyInt_AsLong(value);
1056  _value.assign(length, v);
1057  }
1058  ret = Field< short >::setVec(self->myoid, field, _value);
1059  break;
1060  }
1061  case 'f': //SET_VECFIELD(float, f)
1062  {
1063  vector<float> _value;
1064  if (is_seq)
1065  {
1066  for ( int ii = 0; ii < length; ++ii)
1067  {
1068  float v = PyFloat_AsDouble(PySequence_GetItem(value, ii));
1069  _value.push_back(v);
1070  }
1071  }
1072  else
1073  {
1074  float v = PyFloat_AsDouble(value);
1075  _value.assign(length, v);
1076  }
1077  ret = Field<float>::setVec(self->myoid, field, _value);
1078  break;
1079  }
1080  default:
1081  break;
1082  }
1083  // MOOSE Field::set returns 1 for success 0 for
1084  // failure. Python treats return value 0 from setters as
1085  // success, anything else failure.
1086  if (ret && (PyErr_Occurred() == NULL))
1087  {
1088  return 0;
1089  }
1090  else
1091  {
1092  return -1;
1093  }
1094 
1095 }
char shortType(string)
uint32_t value
Definition: moosemodule.h:42
Py_ssize_t moose_ElementField_getLen(_Field *self, void *closure)
Definition: mfield.cpp:561
#define RAISE_INVALID_ID(ret, msg)
Definition: moosemodule.h:71
ObjId myoid
Definition: moosemodule.h:141
string getFieldType(string className, string fieldName)
static bool setVec(ObjId destId, const string &field, const vector< A > &arg)
Definition: SetGet.h:252
static bool isValid(Id id)
Definition: Id.h:145
static A get(const ObjId &dest, const string &field)
Definition: SetGet.h:284

+ Here is the call graph for this function:

int moose_ElementField_setNum ( _Field self,
PyObject *  num,
void *  closure 
)

Definition at line 540 of file mfield.cpp.

References RAISE_INVALID_ID.

541 {
542  if (self->owner->oid_.bad())
543  {
544  RAISE_INVALID_ID(-1, "moose_ElementField_setNum");
545  }
546  unsigned int num;
547  if (!PyInt_Check(args))
548  {
549  PyErr_SetString(PyExc_TypeError, "moose.ElementField.setNum - needes an integer.");
550  return -1;
551  }
552  num = PyInt_AsUnsignedLongMask(args);
553  if (!Field<unsigned int>::set(self->myoid, "numField", num))
554  {
555  PyErr_SetString(PyExc_RuntimeError, "moose.ElementField.setNum : Field::set returned False.");
556  return -1;
557  }
558  return 0;
559 }
bool bad() const
Definition: ObjId.cpp:18
Definition: SetGet.h:236
#define RAISE_INVALID_ID(ret, msg)
Definition: moosemodule.h:71
PyObject_HEAD ObjId oid_
Definition: moosemodule.h:133
ObjId myoid
Definition: moosemodule.h:141
_ObjId * owner
Definition: moosemodule.h:140
PyObject* moose_exists ( PyObject *  dummy,
PyObject *  args 
)

Definition at line 1764 of file moosemodule.cpp.

References path.

1765 {
1766  char * path;
1767  if (!PyArg_ParseTuple(args, "s", &path))
1768  {
1769  return NULL;
1770  }
1771  return Py_BuildValue("i", Id(path) != Id() || string(path) == "/" || string(path) == "/root");
1772 }
Definition: Id.h:17
static char path[]
Definition: mfield.cpp:403
void moose_Field_dealloc ( _Field self)

Definition at line 134 of file mfield.cpp.

135 {
136  Py_DECREF(self->owner);
137  Py_TYPE(self)->tp_free((PyObject*)self);
138 }
_ObjId * owner
Definition: moosemodule.h:140
long moose_Field_hash ( _Field self)

Return the hash of the string {objectpath}.{fieldName}

Definition at line 142 of file mfield.cpp.

References Id::isValid(), path, and RAISE_INVALID_ID.

143 {
144  if (!Id::isValid(self->owner->oid_.id))
145  {
146  RAISE_INVALID_ID(-1, "moose_Field_hash");
147  }
148  string fieldPath = self->owner->oid_.path() + "." + self->name;
149  PyObject * path = PyString_FromString(fieldPath.c_str());
150  long hash = PyObject_Hash(path);
151  Py_XDECREF(path);
152  return hash;
153 }
Id id
Definition: ObjId.h:98
#define RAISE_INVALID_ID(ret, msg)
Definition: moosemodule.h:71
PyObject_HEAD ObjId oid_
Definition: moosemodule.h:133
_ObjId * owner
Definition: moosemodule.h:140
static bool isValid(Id id)
Definition: Id.h:145
static char path[]
Definition: mfield.cpp:403

+ Here is the call graph for this function:

int moose_Field_init ( _Field self,
PyObject *  args,
PyObject *  kwargs 
)

Initialize field with ObjId and fieldName.

Definition at line 89 of file mfield.cpp.

References Id::isValid(), ObjIdType, owner, and RAISE_INVALID_ID.

Referenced by moose_ElementField_init().

90 {
91  PyObject * owner;
92  char * fieldName;
93  if (!PyArg_ParseTuple(args, "Os:moose_Field_init", &owner, &fieldName))
94  {
95  return -1;
96  }
97  if (fieldName == NULL)
98  {
99  PyErr_SetString(PyExc_ValueError, "fieldName cannot be NULL");
100  return -1;
101  }
102  if (owner == NULL)
103  {
104  PyErr_SetString(PyExc_ValueError, "owner cannot be NULL");
105  return -1;
106  }
107  if (!PyObject_IsInstance(owner, (PyObject*)&ObjIdType))
108  {
109  PyErr_SetString(PyExc_TypeError, "Owner must be subtype of ObjId");
110  return -1;
111  }
112  if (!Id::isValid(((_ObjId*)owner)->oid_.id))
113  {
114  Py_DECREF(self);
115  RAISE_INVALID_ID(-1, "moose_Field_init");
116  }
117  self->owner = ((_ObjId*)owner);
118  Py_INCREF(self->owner);
119  self->name = strdup(fieldName);
120  if (!self->name) {
121  PyErr_NoMemory();
122  return -1;
123  }
124 
125  // In earlier version I tried to deallocate the existing
126  // self->name if it is not NULL. But it turns out that it
127  // causes a SIGABRT. In any case it should not be an issue as
128  // we can safely assume __init__ will be called only once in
129  // this case. The Fields are created only internally at
130  // initialization of the MOOSE module.
131  return 0;
132 }
static char owner[]
Definition: mfield.cpp:405
PyTypeObject ObjIdType
#define RAISE_INVALID_ID(ret, msg)
Definition: moosemodule.h:71
_ObjId * owner
Definition: moosemodule.h:140
PyObject_HEAD char * name
Definition: moosemodule.h:139
static bool isValid(Id id)
Definition: Id.h:145

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

PyObject* moose_Field_repr ( _Field self)

String representation of fields is {objectpath}.{fieldName}

Definition at line 156 of file mfield.cpp.

References Id::isValid(), and RAISE_INVALID_ID.

157 {
158  if (!Id::isValid(self->owner->oid_.id))
159  {
160  RAISE_INVALID_ID(NULL, "moose_Field_repr");
161  }
162  ostringstream fieldPath;
163  fieldPath << self->owner->oid_.path() << "." << self->name;
164  return PyString_FromString(fieldPath.str().c_str());
165 }
Id id
Definition: ObjId.h:98
#define RAISE_INVALID_ID(ret, msg)
Definition: moosemodule.h:71
PyObject_HEAD ObjId oid_
Definition: moosemodule.h:133
_ObjId * owner
Definition: moosemodule.h:140
static bool isValid(Id id)
Definition: Id.h:145

+ Here is the call graph for this function:

PyObject* moose_getCwe ( PyObject *  dummy,
PyObject *  args 
)

Definition at line 1921 of file moosemodule.cpp.

References oid_to_element(), and SHELLPTR.

1922 {
1923  if (!PyArg_ParseTuple(args, ":moose_getCwe"))
1924  {
1925  return NULL;
1926  }
1927  // _Id * cwe = (_Id*)PyObject_New(_Id, &IdType);
1928  // cwe->id_ = SHELLPTR->getCwe();
1929  // PyObject * ret = (PyObject*)cwe;
1930  // return ret;
1931  return oid_to_element(SHELLPTR->getCwe());
1932 }
#define SHELLPTR
Definition: moosemodule.h:105
PyObject * oid_to_element(ObjId oid)

+ Here is the call graph for this function:

PyObject* moose_getField ( PyObject *  dummy,
PyObject *  args 
)

Definition at line 2145 of file moosemodule.cpp.

References Field< A >::get(), ObjId::id, _Id::id_, IdType, Id::isValid(), ObjIdType, _ObjId::oid_, RAISE_INVALID_ID, and value.

2146 {
2147  PyObject * pyobj;
2148  const char * field;
2149  const char * type;
2150  if (!PyArg_ParseTuple(args, "Oss:moose_getfield", &pyobj, &field, &type))
2151  {
2152  return NULL;
2153  }
2154  if (!PyObject_IsInstance(pyobj, (PyObject*)&ObjIdType))
2155  {
2156  PyErr_SetString(PyExc_TypeError, "moose.getField(element, fieldname, fieldtype): First argument must be an instance of element or its subclass");
2157  return NULL;
2158  }
2159  string fname(field), ftype(type);
2160  ObjId oid = ((_ObjId*)pyobj)->oid_;
2161  if (!Id::isValid(oid.id))
2162  {
2163  RAISE_INVALID_ID(NULL, "moose_getField");
2164  }
2165  // Let us do this version using brute force. Might be simpler than getattro.
2166  if (ftype == "char")
2167  {
2168  char value =Field<char>::get(oid, fname);
2169  return PyInt_FromLong(value);
2170  }
2171  else if (ftype == "double")
2172  {
2173  double value = Field<double>::get(oid, fname);
2174  return PyFloat_FromDouble(value);
2175  }
2176  else if (ftype == "float")
2177  {
2178  float value = Field<float>::get(oid, fname);
2179  return PyFloat_FromDouble(value);
2180  }
2181  else if (ftype == "int")
2182  {
2183  int value = Field<int>::get(oid, fname);
2184  return PyInt_FromLong(value);
2185  }
2186  else if (ftype == "string")
2187  {
2188  string value = Field<string>::get(oid, fname);
2189  return PyString_FromString(value.c_str());
2190  }
2191  else if (ftype == "unsigned int" || ftype == "unsigned" || ftype == "uint")
2192  {
2193  unsigned int value = Field<unsigned int>::get(oid, fname);
2194  return PyInt_FromLong(value);
2195  }
2196  else if (ftype == "Id")
2197  {
2198  _Id * value = (_Id*)PyObject_New(_Id, &IdType);
2199  value->id_ = Field<Id>::get(oid, fname);
2200  return (PyObject*) value;
2201  }
2202  else if (ftype == "ObjId")
2203  {
2204  _ObjId * value = (_ObjId*)PyObject_New(_ObjId, &ObjIdType);
2205  value->oid_ = Field<ObjId>::get(oid, fname);
2206  return (PyObject*)value;
2207  }
2208  else if (ftype == "vector<int>")
2209  {
2210  vector<int> value = Field< vector < int > >::get(oid, fname);
2211  PyObject * ret = PyTuple_New((Py_ssize_t)value.size());
2212 
2213  for (unsigned int ii = 0; ii < value.size(); ++ ii )
2214  {
2215  PyObject * entry = Py_BuildValue("i", value[ii]);
2216  if (!entry || PyTuple_SetItem(ret, (Py_ssize_t)ii, entry))
2217  {
2218  Py_XDECREF(ret);
2219  ret = NULL;
2220  break;
2221  }
2222  }
2223  return ret;
2224  }
2225  else if (ftype == "vector<double>")
2226  {
2227  vector<double> value = Field< vector < double > >::get(oid, fname);
2228  PyObject * ret = PyTuple_New((Py_ssize_t)value.size());
2229 
2230  for (unsigned int ii = 0; ii < value.size(); ++ ii )
2231  {
2232  PyObject * entry = Py_BuildValue("f", value[ii]);
2233  if (!entry || PyTuple_SetItem(ret, (Py_ssize_t)ii, entry))
2234  {
2235  Py_XDECREF(ret);
2236  ret = NULL;
2237  break;
2238  }
2239  }
2240  return ret;
2241  }
2242  else if (ftype == "vector<float>")
2243  {
2244  vector<float> value = Field< vector < float > >::get(oid, fname);
2245  PyObject * ret = PyTuple_New((Py_ssize_t)value.size());
2246 
2247  for (unsigned int ii = 0; ii < value.size(); ++ ii )
2248  {
2249  PyObject * entry = Py_BuildValue("f", value[ii]);
2250  if (!entry || PyTuple_SetItem(ret, (Py_ssize_t)ii, entry))
2251  {
2252  Py_XDECREF(ret);
2253  ret = NULL;
2254  break;
2255  }
2256  }
2257  return ret;
2258  }
2259  else if (ftype == "vector<string>")
2260  {
2261  vector<string> value = Field< vector < string > >::get(oid, fname);
2262  PyObject * ret = PyTuple_New((Py_ssize_t)value.size());
2263 
2264  for (unsigned int ii = 0; ii < value.size(); ++ ii )
2265  {
2266  PyObject * entry = Py_BuildValue("s", value[ii].c_str());
2267  if (!entry || PyTuple_SetItem(ret, (Py_ssize_t)ii, entry))
2268  {
2269  Py_XDECREF(ret);
2270  return NULL;
2271  }
2272  }
2273  return ret;
2274  }
2275  else if (ftype == "vector<Id>")
2276  {
2277  vector<Id> value = Field< vector < Id > >::get(oid, fname);
2278  PyObject * ret = PyTuple_New((Py_ssize_t)value.size());
2279 
2280  for (unsigned int ii = 0; ii < value.size(); ++ ii )
2281  {
2282  _Id * entry = PyObject_New(_Id, &IdType);
2283  entry->id_ = value[ii];
2284  if (PyTuple_SetItem(ret, (Py_ssize_t)ii, (PyObject*)entry))
2285  {
2286  Py_XDECREF(ret);
2287  return NULL;
2288  }
2289  }
2290  return ret;
2291  }
2292  else if (ftype == "vector<ObjId>")
2293  {
2294  vector<ObjId> value = Field< vector < ObjId > >::get(oid, fname);
2295  PyObject * ret = PyTuple_New((Py_ssize_t)value.size());
2296 
2297  for (unsigned int ii = 0; ii < value.size(); ++ ii )
2298  {
2299  _ObjId * entry = PyObject_New(_ObjId, &ObjIdType);
2300  entry->oid_ = value[ii];
2301  if (PyTuple_SetItem(ret, (Py_ssize_t)ii, (PyObject*)entry))
2302  {
2303  Py_XDECREF(ret);
2304  return NULL;
2305  }
2306  }
2307  return ret;
2308  }
2309  PyErr_SetString(PyExc_TypeError, "Field type not handled.");
2310  return NULL;
2311 }
PyObject_HEAD Id id_
Definition: moosemodule.h:114
uint32_t value
Definition: moosemodule.h:42
Definition: SetGet.h:236
Id id
Definition: ObjId.h:98
Definition: ObjId.h:20
#define RAISE_INVALID_ID(ret, msg)
Definition: moosemodule.h:71
PyObject_HEAD ObjId oid_
Definition: moosemodule.h:133
PyTypeObject ObjIdType
static bool isValid(Id id)
Definition: Id.h:145
static A get(const ObjId &dest, const string &field)
Definition: SetGet.h:284
PyTypeObject IdType
Definition: vec.cpp:262

+ Here is the call graph for this function:

PyObject* moose_getFieldDict ( PyObject *  dummy,
PyObject *  args 
)

Definition at line 2081 of file moosemodule.cpp.

References getFieldDict(), and value.

2082 {
2083  char * className = NULL;
2084  char * fieldType = NULL;
2085  if (!PyArg_ParseTuple(args, "s|s:moose_getFieldDict", &className, &fieldType))
2086  {
2087  return NULL;
2088  }
2089  if (!className || (strlen(className) <= 0))
2090  {
2091  PyErr_SetString(PyExc_ValueError, "Expected non-empty class name.");
2092  return NULL;
2093  }
2094 
2095  Id classId = Id("/classes/" + string(className));
2096  if (classId == Id())
2097  {
2098  string msg = string(className);
2099  msg += " not a valid MOOSE class.";
2100  PyErr_SetString(PyExc_NameError, msg.c_str());
2101  return NULL;
2102  }
2103  static const char * finfoTypes [] = {"valueFinfo", "lookupFinfo", "srcFinfo", "destFinfo", "sharedFinfo", NULL};
2104  vector <string> fields, types;
2105  if (fieldType && strlen(fieldType) > 0)
2106  {
2107  if (getFieldDict(className, string(fieldType), fields, types) == 0)
2108  {
2109  PyErr_SetString(PyExc_ValueError, "Invalid finfo type.");
2110  return NULL;
2111  }
2112  }
2113  else
2114  {
2115  for (const char ** ptr = finfoTypes; *ptr != NULL; ++ptr)
2116  {
2117  if (getFieldDict(className, string(*ptr), fields, types) == 0)
2118  {
2119  string message = "No such finfo type: ";
2120  message += string(*ptr);
2121  PyErr_SetString(PyExc_ValueError, message.c_str());
2122  return NULL;
2123  }
2124  }
2125  }
2126  PyObject * ret = PyDict_New();
2127  if (!ret)
2128  {
2129  PyErr_SetString(PyExc_SystemError, "Could not allocate dictionary object.");
2130  return NULL;
2131  }
2132  for (unsigned int ii = 0; ii < fields.size(); ++ ii)
2133  {
2134  PyObject * value = Py_BuildValue("s", types[ii].c_str());
2135  if (value == NULL || PyDict_SetItemString(ret, fields[ii].c_str(), value) == -1)
2136  {
2137  Py_XDECREF(ret);
2138  Py_XDECREF(value);
2139  return NULL;
2140  }
2141  }
2142  return ret;
2143 }
uint32_t value
Definition: moosemodule.h:42
Definition: Id.h:17
int getFieldDict(string className, string finfoType, vector< string > &fieldNames, vector< string > &fieldTypes)

+ Here is the call graph for this function:

int moose_Id_contains ( _Id self,
PyObject *  args 
)

Definition at line 799 of file vec.cpp.

References ObjId_SubtypeCheck, and ObjIdType.

800 {
801  extern PyTypeObject ObjIdType;
802  int ret = 0;
803  if (ObjId_SubtypeCheck(obj))
804  {
805  ret = (((_ObjId*)obj)->oid_.id == self->id_);
806  }
807  return ret;
808 }
#define ObjId_SubtypeCheck(v)
Definition: moosemodule.h:98
PyTypeObject ObjIdType
PyObject* moose_Id_delete ( _Id self)

Definition at line 534 of file vec.cpp.

References deleteObjId(), Id::isValid(), and RAISE_INVALID_ID.

535 {
536  if (self->id_ == Id())
537  {
538  PyErr_SetString(PyExc_ValueError, "moose_Id_delete: cannot delete moose shell.");
539  return NULL;
540  }
541  if (!Id::isValid(self->id_))
542  {
543  RAISE_INVALID_ID(NULL, "moose_Id_delete");
544  }
545  deleteObjId(self->id_);
546  self->id_ = Id();
547  Py_CLEAR(self);
548  Py_RETURN_NONE;
549 }
PyObject_HEAD Id id_
Definition: moosemodule.h:114
#define RAISE_INVALID_ID(ret, msg)
Definition: moosemodule.h:71
static bool isValid(Id id)
Definition: Id.h:145
PyObject * deleteObjId(ObjId oid)
Definition: vec.cpp:522
Definition: Id.h:17

+ Here is the call graph for this function:

PyObject* moose_Id_getattro ( _Id self,
PyObject *  attr 
)

Definition at line 810 of file vec.cpp.

References Field< A >::get(), get_field_alias(), get_Id_attr(), getFieldType(), Field< A >::getVec(), Id::isValid(), RAISE_INVALID_ID, shortType(), and to_pytuple().

811 {
812  int new_attr = 0;
813  if (!Id::isValid(self->id_))
814  {
815  RAISE_INVALID_ID(NULL, "moose_Id_getattro");
816  }
817  char * field = PyString_AsString(attr);
818  PyObject * _ret = get_Id_attr(self, field);
819  if (_ret != NULL)
820  {
821  return _ret;
822  }
823  string className = Field<string>::get(self->id_, "className");
824  string type = getFieldType(className, string(field));
825  if (type.empty())
826  {
827  // Check if this field name is aliased and update fieldname and type if so.
828  map<string, string>::const_iterator it = get_field_alias().find(string(field));
829  if (it != get_field_alias().end())
830  {
831  field = const_cast<char*>((it->second).c_str());
832  type = getFieldType(Field<string>::get(self->id_, "className"), it->second);
833  // Update attr for next level (PyObject_GenericGetAttr) in case.
834  // Py_XDECREF(attr);
835  attr = PyString_FromString(field);
836  new_attr = 1;
837  }
838  }
839  if (type.empty())
840  {
841  return PyObject_GenericGetAttr((PyObject*)self, attr);
842  }
843  char ftype = shortType(type);
844  if (!ftype)
845  {
846  return PyObject_GenericGetAttr((PyObject*)self, attr);
847  }
848 
849  switch (ftype)
850  {
851  case 'd':
852  {
853  vector < double > val;
854  Field< double >::getVec(self->id_, string(field), val);
855  _ret = to_pytuple(&val, ftype);
856  break;
857  }
858  case 's':
859  {
860  vector < string > val;
861  Field< string >::getVec(self->id_, string(field), val);
862  _ret = to_pytuple(&val, ftype);
863  break;
864  }
865  case 'l':
866  {
867  vector < long > val;
868  Field< long >::getVec(self->id_, string(field), val);
869  _ret = to_pytuple(&val, ftype);
870  break;
871  }
872  case 'x':
873  {
874  vector < Id > val;
875  Field< Id >::getVec(self->id_, string(field), val);
876  _ret = to_pytuple(&val, ftype);
877  break;
878  }
879  case 'y':
880  {
881  vector < ObjId > val;
882  Field< ObjId >::getVec(self->id_, string(field), val);
883  _ret = to_pytuple(&val, ftype);
884  break;
885  }
886  case 'i':
887  {
888  vector < int > val;
889  Field< int >::getVec(self->id_, string(field), val);
890  _ret = to_pytuple(&val, ftype);
891  break;
892  }
893  case 'I':
894  {
895  vector < unsigned int > val;
896  Field< unsigned int >::getVec(self->id_, string(field), val);
897  _ret = to_pytuple(&val, ftype);
898  break;
899  }
900  case 'k':
901  {
902  vector < unsigned long > val;
903  Field< unsigned long >::getVec(self->id_, string(field), val);
904  _ret = to_pytuple(&val, ftype);
905  break;
906  }
907  case 'f':
908  {
909  vector < float > val;
910  Field< float >::getVec(self->id_, string(field), val);
911  _ret = to_pytuple(&val, ftype);
912  break;
913  }
914  case 'b':
915  {
916  vector<bool> val;
917  Field< bool >::getVec(self->id_, string(field), val);
918  _ret = to_pytuple(&val, ftype);
919  break;
920  }
921  case 'c':
922  {
923  vector < char > val;
924  Field< char >::getVec(self->id_, string(field), val);
925  _ret = to_pytuple(&val, ftype);
926  break;
927  }
928  case 'h':
929  {
930  vector < short > val;
931  Field< short >::getVec(self->id_, string(field), val);
932  _ret = to_pytuple(&val, ftype);
933  break;
934  }
935  case 'z':
936  {
937  PyErr_SetString(PyExc_NotImplementedError,
938  "moose_Id_getattro: DataId handling not implemented yet.");
939  _ret = NULL;
940  break;
941  }
942  default:
943  ostringstream msg;
944  msg << "moose_Id_getattro: unhandled field type '" << type << "'\n"
945  << "This is a vec object. Perhaps you are trying to access the field in an"
946  << " element in this. Then use indexing to get the element first.";
947  PyErr_SetString(PyExc_ValueError, msg.str().c_str());
948  _ret = NULL;
949  break;
950  }
951  if (new_attr)
952  {
953  Py_DECREF(attr);
954  }
955  return _ret;
956 }
PyObject_HEAD Id id_
Definition: moosemodule.h:114
char shortType(string)
Definition: SetGet.h:236
const map< string, string > & get_field_alias()
#define RAISE_INVALID_ID(ret, msg)
Definition: moosemodule.h:71
PyObject * to_pytuple(void *obj, char typecode)
PyObject * get_Id_attr(_Id *id, string attribute)
Definition: vec.cpp:312
string getFieldType(string className, string fieldName)
static bool isValid(Id id)
Definition: Id.h:145
static A get(const ObjId &dest, const string &field)
Definition: SetGet.h:284
static void getVec(ObjId dest, const string &field, vector< A > &vec)
Definition: SetGet.h:317

+ Here is the call graph for this function:

PyObject* moose_Id_getItem ( _Id self,
Py_ssize_t  index 
)

Definition at line 649 of file vec.cpp.

References Id::isValid(), moose_Id_getLength(), oid_to_element(), and RAISE_INVALID_ID.

Referenced by moose_Id_subscript().

650 {
651  if (!Id::isValid(self->id_))
652  {
653  RAISE_INVALID_ID(NULL, "moose_Id_getItem");
654  }
655  if (index < 0)
656  {
657  index += moose_Id_getLength(self);
658  }
659  if ((index < 0) || (index >= moose_Id_getLength(self)))
660  {
661  PyErr_SetString(PyExc_IndexError, "index out of bounds.");
662  return NULL;
663  }
664  ObjId oid(self->id_.path()); // This is just to get the dataIndex of parent
665  if (self->id_.element()->hasFields())
666  {
667  // How to efficiently get the dataIndex of parent element
668  // without creating ObjId from path?
669  oid = ObjId(self->id_, oid.dataIndex, index);
670  }
671  else
672  {
673  oid = ObjId(self->id_, index, 0);
674  }
675  return oid_to_element(oid);
676 }
PyObject_HEAD Id id_
Definition: moosemodule.h:114
Py_ssize_t moose_Id_getLength(_Id *self)
Definition: vec.cpp:607
Element * element() const
Synonym for Id::operator()()
Definition: Id.cpp:113
std::string path(const std::string &separator="/") const
Definition: Id.cpp:76
Definition: ObjId.h:20
#define RAISE_INVALID_ID(ret, msg)
Definition: moosemodule.h:71
virtual bool hasFields() const =0
static bool isValid(Id id)
Definition: Id.h:145
PyObject * oid_to_element(ObjId oid)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Py_ssize_t moose_Id_getLength ( _Id self)

Definition at line 607 of file vec.cpp.

References Id::isValid(), and RAISE_INVALID_ID.

Referenced by moose_Id_getItem(), moose_Id_getSlice(), moose_Id_setattro(), and moose_Id_subscript().

608 {
609  if (!Id::isValid(self->id_))
610  {
611  RAISE_INVALID_ID(-1, "moose_Id_getLength");
612  }
613  if (self->id_.element()->hasFields())
614  {
615  return (Py_ssize_t)(Field < unsigned int >::get(self->id_, "numField"));
616  }
617  else
618  {
619  return (Py_ssize_t)(self->id_.element()->numData());
620  }
621 }
PyObject_HEAD Id id_
Definition: moosemodule.h:114
Element * element() const
Synonym for Id::operator()()
Definition: Id.cpp:113
Definition: SetGet.h:236
#define RAISE_INVALID_ID(ret, msg)
Definition: moosemodule.h:71
virtual bool hasFields() const =0
static bool isValid(Id id)
Definition: Id.h:145

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

PyObject* moose_Id_getPath ( _Id self)

Not to be redone. 2011-03-23 14:42:48 (+0530)

Definition at line 588 of file vec.cpp.

References moose::endswith(), Id::isValid(), path, and RAISE_INVALID_ID.

Referenced by get_Id_attr().

589 {
590  if (!Id::isValid(self->id_))
591  {
592  RAISE_INVALID_ID(NULL, "moose_Id_getPath");
593  }
594  string path = self->id_.path();
595  string default_end("[0]");
596  if (moose::endswith(path, default_end))
597  {
598  path.erase(path.length() - default_end.length(), default_end.length());
599  }
600  PyObject * ret = Py_BuildValue("s", path.c_str());
601  return ret;
602 }
PyObject_HEAD Id id_
Definition: moosemodule.h:114
bool endswith(const string &full, const string &ending)
Definition: strutil.cpp:138
#define RAISE_INVALID_ID(ret, msg)
Definition: moosemodule.h:71
static bool isValid(Id id)
Definition: Id.h:145
static char path[]
Definition: mfield.cpp:403

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

PyObject* moose_Id_getShape ( _Id self)

Definition at line 623 of file vec.cpp.

References Id::isValid(), and RAISE_INVALID_ID.

Referenced by get_Id_attr().

624 {
625  if (!Id::isValid(self->id_))
626  {
627  RAISE_INVALID_ID(NULL, "moose_Id_getShape");
628  }
629  unsigned int numData = 1;
630  if (self->id_.element()->hasFields())
631  {
632  numData = Field < unsigned int >::get(self->id_, "numField");
633  }
634  else
635  {
636  // numData = Field < unsigned int >::get(self->id_, "numData");
637  numData = self->id_.element()->numData();
638  }
639  PyObject * ret = PyTuple_New((Py_ssize_t)1);
640  if (PyTuple_SetItem(ret, (Py_ssize_t)0, Py_BuildValue("I", numData)))
641  {
642  Py_XDECREF(ret);
643  PyErr_SetString(PyExc_RuntimeError, "moose_Id_getShape: could not set tuple entry.");
644  return NULL;
645  }
646  return ret;
647 }
PyObject_HEAD Id id_
Definition: moosemodule.h:114
Element * element() const
Synonym for Id::operator()()
Definition: Id.cpp:113
Definition: SetGet.h:236
#define RAISE_INVALID_ID(ret, msg)
Definition: moosemodule.h:71
virtual bool hasFields() const =0
static bool isValid(Id id)
Definition: Id.h:145

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

PyObject* moose_Id_getSlice ( _Id self,
Py_ssize_t  start,
Py_ssize_t  end 
)

Definition at line 702 of file vec.cpp.

References Id::isValid(), moose_Id_fillSlice(), moose_Id_getLength(), and RAISE_INVALID_ID.

703 {
704  if (!Id::isValid(self->id_))
705  {
706  RAISE_INVALID_ID(NULL, "moose_Id_getSlice");
707  }
708  Py_ssize_t len = moose_Id_getLength(self);
709  while (start < 0)
710  {
711  start += len;
712  }
713  while (end < 0)
714  {
715  end += len;
716  }
717  return moose_Id_fillSlice(self, start, end, 1, std::max(end - start, (Py_ssize_t) 0));
718 }
PyObject_HEAD Id id_
Definition: moosemodule.h:114
Py_ssize_t moose_Id_getLength(_Id *self)
Definition: vec.cpp:607
#define RAISE_INVALID_ID(ret, msg)
Definition: moosemodule.h:71
static bool isValid(Id id)
Definition: Id.h:145
static PyObject * moose_Id_fillSlice(_Id *self, Py_ssize_t start, Py_ssize_t end, Py_ssize_t step, Py_ssize_t slicelength)
Definition: vec.cpp:678

+ Here is the call graph for this function:

PyObject* moose_Id_getValue ( _Id self)

Definition at line 578 of file vec.cpp.

Referenced by get_Id_attr().

579 {
580  unsigned int id = self->id_.value();
581  PyObject * ret = Py_BuildValue("I", id);
582  return ret;
583 }

+ Here is the caller graph for this function:

long moose_Id_hash ( _Id self)

Definition at line 509 of file vec.cpp.

510 {
511  return self->id_.value(); // hash is the same as the Id value
512 }
int moose_Id_init ( _Id self,
PyObject *  args,
PyObject *  kwargs 
)

Definition at line 416 of file vec.cpp.

References create_Id_from_path(), Id_SubtypeCheck, IdType, ObjId_SubtypeCheck, path, and moose::trim().

417 {
418  extern PyTypeObject IdType;
419  PyObject * src = NULL;
420  unsigned int id = 0;
421  unsigned int isGlobal = 0;
422  char * type = NULL;
423  // first try parsing the arguments as (path, size, classname)
424  static char _path[] = "path";
425  static char _dtype[] = "dtype";
426  static char _size[] = "n";
427  static char _global[] = "g";
428  static char * kwlist[] = {_path, _size, _global, _dtype, NULL};
429  char * path = NULL;
430  char _default_type[] = "Neutral";
431  // set it to 0 for unspecified value in case the user tries to
432  // get an existing id without specifying it. If the user is
433  // specifying it but the existing vec does not have same
434  // numData we warn the user about the misconception. If it is
435  // nonexisting vec, we change the unspecifed numData to 1.
436  unsigned int numData = 0;
437  // char *type = _default_type;
438  /* The expected arguments are:
439  string path,
440  [unsigned int numData] - default: 1
441  [unsigned int isGlobal] - default: 0
442  [string type] - default: Neutral
443  */
444  if (PyArg_ParseTupleAndKeywords(args, kwargs, "s|IIs:moose_Id_init",
445  kwlist, &path, &numData, &isGlobal,
446  &type)
447  )
448  {
449  // Parsing args successful, if any error happens now,
450  // different argument processing will not help. Return error
451  string trimmed_path(path);
452  trimmed_path = moose::trim(trimmed_path);
453  size_t length = trimmed_path.length();
454  if (length <= 0)
455  {
456  PyErr_SetString(PyExc_ValueError,
457  "moose_Id_init: path must be non-empty string.");
458  return -1;
459  }
460  self->id_ = Id(trimmed_path);
461 
462  // Return already existing object
463  if (self->id_ != Id() || trimmed_path == "/" || trimmed_path == "/root")
464  {
465  if ((numData > 0) && (numData != Field<unsigned int>::get(self->id_, "numData")))
466  {
467  PyErr_WarnEx(NULL, "moose_Id_init_: Length specified does not match that of existing object.", 1);
468  }
469  return 0;
470  }
471  if (type == NULL)
472  type = _default_type;
473  if (numData <= 0)
474  numData = 1;
475 
476  self->id_ = create_Id_from_path(trimmed_path, numData, isGlobal, type);
477  if (self->id_ == Id() && PyErr_Occurred())
478  {
479  return -1;
480  }
481  return 0;
482  }
483  // The arguments could not be parsed as (path, dims, class),
484  // try to parse it as an existing Id
485  PyErr_Clear();
486  if (PyArg_ParseTuple(args, "O:moose_Id_init", &src) && Id_SubtypeCheck(src))
487  {
488  self->id_ = ((_Id*)src)->id_;
489  return 0;
490  }
491  // The arguments could not be parsed as (path, dims, class), or Id
492  // try to parse it as an existing ObjId
493  PyErr_Clear();
494  if (PyArg_ParseTuple(args, "O:moose_Id_init", &src) && ObjId_SubtypeCheck(src))
495  {
496  self->id_ = ((_ObjId*)src)->oid_.id;
497  return 0;
498  }
499  // Next try to parse it as an integer value for an existing Id
500  PyErr_Clear(); // clear the error from parsing error
501  if (PyArg_ParseTuple(args, "I:moose_Id_init", &id))
502  {
503  self->id_ = Id(id);
504  return 0;
505  }
506  return -1;
507 }// ! moose_Id_init
PyObject_HEAD Id id_
Definition: moosemodule.h:114
#define ObjId_SubtypeCheck(v)
Definition: moosemodule.h:98
Definition: SetGet.h:236
Id create_Id_from_path(string path, unsigned int numData, unsigned int isGlobal, string type)
Definition: vec.cpp:358
#define Id_SubtypeCheck(v)
Definition: moosemodule.h:96
PyTypeObject IdType
Definition: vec.cpp:262
Definition: Id.h:17
std::string trim(const std::string myString, const string &delimiters)
Definition: strutil.cpp:53
static char path[]
Definition: mfield.cpp:403

+ Here is the call graph for this function:

PyObject* moose_Id_repr ( _Id self)

Definition at line 551 of file vec.cpp.

References Field< A >::get(), Id::isValid(), and RAISE_INVALID_ID.

552 {
553  if (!Id::isValid(self->id_))
554  {
555  RAISE_INVALID_ID(NULL, "moose_Id_repr");
556  }
557  ostringstream repr;
558  repr << "<moose.vec: class="
559  << Field<string>::get(self->id_, "className") << ", "
560  << "id=" << self->id_.value() << ", "
561  << "path=" << self->id_.path() << ">";
562  return PyString_FromString(repr.str().c_str());
563 } // ! moose_Id_repr
PyObject_HEAD Id id_
Definition: moosemodule.h:114
#define RAISE_INVALID_ID(ret, msg)
Definition: moosemodule.h:71
static bool isValid(Id id)
Definition: Id.h:145
static A get(const ObjId &dest, const string &field)
Definition: SetGet.h:284

+ Here is the call graph for this function:

PyObject* moose_Id_richCompare ( _Id self,
PyObject *  args,
int  op 
)

Definition at line 755 of file vec.cpp.

References Id::id_, and IdType.

756 {
757  extern PyTypeObject IdType;
758  bool ret = false;
759  Id other_id = ((_Id*)other)->id_;
760  if (!self || !other)
761  {
762  ret = false;
763  }
764  else if (!PyObject_IsInstance(other, (PyObject*)&IdType))
765  {
766  ret = false;
767  }
768  else if (op == Py_EQ)
769  {
770  ret = self->id_ == other_id;
771  }
772  else if (op == Py_NE)
773  {
774  ret = self->id_ != other_id;
775  }
776  else if (op == Py_LT)
777  {
778  ret = self->id_ < other_id;
779  }
780  else if (op == Py_GT)
781  {
782  ret = other_id < self->id_;
783  }
784  else if (op == Py_LE)
785  {
786  ret = (self->id_ < other_id) || (self->id_ == other_id);
787  }
788  else if (op == Py_GE)
789  {
790  ret = (other_id < self->id_) || (self->id_ == other_id);
791  }
792  if (ret)
793  {
794  Py_RETURN_TRUE;
795  }
796  Py_RETURN_FALSE;
797 }
PyObject_HEAD Id id_
Definition: moosemodule.h:114
static double op(double x)
PyTypeObject IdType
Definition: vec.cpp:262
Definition: Id.h:17
unsigned int id_
Definition: Id.h:172
int moose_Id_setattro ( _Id self,
PyObject *  attr,
PyObject *  value 
)

Definition at line 977 of file vec.cpp.

References Field< A >::get(), getFieldType(), Id::isValid(), moose_Id_getLength(), RAISE_INVALID_ID, Field< A >::setVec(), shortType(), and value.

Referenced by moose_Id_setField().

978 {
979  if (!Id::isValid(self->id_))
980  {
981  RAISE_INVALID_ID(-1, "moose_Id_setattro");
982  }
983  char * fieldname = NULL;
984  int ret = -1;
985  if (PyString_Check(attr))
986  {
987  fieldname = PyString_AsString(attr);
988  }
989  else
990  {
991  PyErr_SetString(PyExc_TypeError, "moose_Id_setattro: Attribute name must be a string");
992  return -1;
993  }
994  string moose_class = Field<string>::get(self->id_, "className");
995  string fieldtype = getFieldType(moose_class, string(fieldname));
996  if (fieldtype.length() == 0)
997  {
998  // If it is instance of a MOOSE Id then throw
999  // error (to avoid silently creating new attributes due to
1000  // typos). Otherwise, it must have been subclassed in
1001  // Python. Then we allow normal Pythonic behaviour and
1002  // consider such mistakes user's responsibility.
1003  string className = ((PyTypeObject*)PyObject_Type((PyObject*)self))->tp_name;
1004  if (className != "vec")
1005  {
1006  Py_INCREF(attr);
1007  ret = PyObject_GenericSetAttr((PyObject*)self, attr, value);
1008  Py_XDECREF(attr);
1009  return ret;
1010  }
1011  ostringstream msg;
1012  msg << "moose_Id_setattro: '" << moose_class << "' class has no field '" << fieldname << "'" << endl;
1013  PyErr_SetString(PyExc_AttributeError, msg.str().c_str());
1014  return -1;
1015  }
1016  char ftype = shortType(fieldtype);
1017  Py_ssize_t length = moose_Id_getLength(self);
1018  bool is_seq = true;
1019  if (!PySequence_Check(value))
1020  {
1021  is_seq = false;
1022  }
1023  else if (length != PySequence_Length(value))
1024  {
1025  PyErr_SetString(PyExc_IndexError,
1026  "moose_Id_setattro: length of the sequence on the right hand side does not match Id size.");
1027  return -1;
1028  }
1029  switch(ftype)
1030  {
1031  case 'd': //SET_VECFIELD(double, d)
1032  {
1033  vector<double> _value;
1034  if (is_seq)
1035  {
1036  for ( int ii = 0; ii < length; ++ii)
1037  {
1038  PyObject * vo = PySequence_GetItem(value, ii);
1039  double v = PyFloat_AsDouble(vo);
1040  Py_XDECREF(vo);
1041  _value.push_back(v);
1042  }
1043  }
1044  else
1045  {
1046  double v = PyFloat_AsDouble(value);
1047  _value.assign(length, v);
1048  }
1049  ret = Field<double>::setVec(self->id_, string(fieldname), _value);
1050  break;
1051  }
1052  case 's':
1053  {
1054  vector<string> _value;
1055  if (is_seq)
1056  {
1057  for ( int ii = 0; ii < length; ++ii)
1058  {
1059  PyObject * vo = PySequence_GetItem(value, ii);
1060  char * v = PyString_AsString(vo);
1061  Py_XDECREF(v);
1062  _value.push_back(string(v));
1063  }
1064  }
1065  else
1066  {
1067  char * v = PyString_AsString(value);
1068  _value.assign(length, string(v));
1069  }
1070  ret = Field<string>::setVec(self->id_, string(fieldname), _value);
1071  break;
1072  }
1073  case 'i':
1074  {
1075  vector<int> _value;
1076  if (is_seq)
1077  {
1078  for ( int ii = 0; ii < length; ++ii)
1079  {
1080  PyObject * vo = PySequence_GetItem(value, ii);
1081  int v = PyInt_AsLong(vo);
1082  Py_XDECREF(vo);
1083  _value.push_back(v);
1084  }
1085  }
1086  else
1087  {
1088  int v = PyInt_AsLong(value);
1089  _value.assign(length, v);
1090  }
1091  ret = Field< int >::setVec(self->id_, string(fieldname), _value);
1092  break;
1093  }
1094  case 'I': //SET_VECFIELD(unsigned int, I)
1095  {
1096  vector<unsigned int> _value;
1097  if (is_seq)
1098  {
1099  for ( int ii = 0; ii < length; ++ii)
1100  {
1101  PyObject * vo = PySequence_GetItem(value, ii);
1102  unsigned int v = PyInt_AsUnsignedLongMask(vo);
1103  Py_DECREF(vo);
1104  _value.push_back(v);
1105  }
1106  }
1107  else
1108  {
1109  unsigned int v = PyInt_AsUnsignedLongMask(value);
1110  _value.assign(length, v);
1111  }
1112  ret = Field< unsigned int >::setVec(self->id_, string(fieldname), _value);
1113  break;
1114  }
1115  case 'l': //SET_VECFIELD(long, l)
1116  {
1117  vector<long> _value;
1118  if (is_seq)
1119  {
1120  for ( int ii = 0; ii < length; ++ii)
1121  {
1122  PyObject * vo = PySequence_GetItem(value, ii);
1123  long v = PyInt_AsLong(vo);
1124  Py_DECREF(vo);
1125  _value.push_back(v);
1126  }
1127  }
1128  else
1129  {
1130  long v = PyInt_AsLong(value);
1131  _value.assign(length, v);
1132  }
1133  ret = Field<long>::setVec(self->id_, string(fieldname), _value);
1134  break;
1135  }
1136  case 'k': //SET_VECFIELD(unsigned long, k)
1137  {
1138  vector<unsigned long> _value;
1139  if (is_seq)
1140  {
1141  for ( int ii = 0; ii < length; ++ii)
1142  {
1143  PyObject * vo = PySequence_GetItem(value, ii);
1144  unsigned long v = PyInt_AsUnsignedLongMask(vo);
1145  Py_XDECREF(vo);
1146  _value.push_back(v);
1147  }
1148  }
1149  else
1150  {
1151  unsigned long v = PyInt_AsUnsignedLongMask(value);
1152  _value.assign(length, v);
1153  }
1154  ret = Field< unsigned long >::setVec(self->id_, string(fieldname), _value);
1155  break;
1156  }
1157  case 'b':
1158  {
1159  vector<bool> _value;
1160  if (is_seq)
1161  {
1162  for ( int ii = 0; ii < length; ++ii)
1163  {
1164  PyObject * _v = PySequence_GetItem(value, ii);
1165  bool v = (Py_True ==_v) || (PyInt_AsLong(_v) != 0);
1166  Py_XDECREF(_v);
1167  _value.push_back(v);
1168  }
1169  }
1170  else
1171  {
1172  bool v = (Py_True ==value) || (PyInt_AsLong(value) != 0);
1173  _value.assign(length, v);
1174  }
1175  ret = Field< bool >::setVec(self->id_, string(fieldname), _value);
1176  break;
1177  }
1178  case 'c':
1179  {
1180  vector<char> _value;
1181  if (is_seq)
1182  {
1183  for ( int ii = 0; ii < length; ++ii)
1184  {
1185  PyObject * _v = PySequence_GetItem(value, ii);
1186  char * v = PyString_AsString(_v);
1187  Py_XDECREF(_v);
1188  if (v && v[0])
1189  {
1190  _value.push_back(v[0]);
1191  }
1192  else
1193  {
1194  ostringstream err;
1195  err << "moose_Id_setattro:" << ii << "-th element is NUL";
1196  PyErr_SetString(PyExc_ValueError, err.str().c_str());
1197  return -1;
1198  }
1199  }
1200  }
1201  else
1202  {
1203  char * v = PyString_AsString(value);
1204  if (v && v[0])
1205  {
1206  _value.assign(length, v[0]);
1207  }
1208  else
1209  {
1210  PyErr_SetString(PyExc_ValueError, "moose_Id_setattro: value is an empty string");
1211  return -1;
1212  }
1213  }
1214  ret = Field< char >::setVec(self->id_, string(fieldname), _value);
1215  break;
1216  }
1217  case 'h':
1218  {
1219  vector<short> _value;
1220  if (is_seq)
1221  {
1222  for ( int ii = 0; ii < length; ++ii)
1223  {
1224  PyObject * vo = PySequence_GetItem(value, ii);
1225  short v = PyInt_AsLong(vo);
1226  Py_XDECREF(vo);
1227  _value.push_back(v);
1228  }
1229  }
1230  else
1231  {
1232  short v = PyInt_AsLong(value);
1233  _value.assign(length, v);
1234  }
1235  ret = Field< short >::setVec(self->id_, string(fieldname), _value);
1236  break;
1237  }
1238  case 'f': //SET_VECFIELD(float, f)
1239  {
1240  vector<float> _value;
1241  if (is_seq)
1242  {
1243  for ( int ii = 0; ii < length; ++ii)
1244  {
1245  PyObject * vo = PySequence_GetItem(value, ii);
1246  float v = PyFloat_AsDouble(vo);
1247  Py_XDECREF(vo);
1248  _value.push_back(v);
1249  }
1250  }
1251  else
1252  {
1253  float v = PyFloat_AsDouble(value);
1254  _value.assign(length, v);
1255  }
1256  ret = Field<float>::setVec(self->id_, string(fieldname), _value);
1257  break;
1258  }
1259  default:
1260  break;
1261  }
1262  // MOOSE Field::set returns 1 for success 0 for
1263  // failure. Python treats return value 0 from setters as
1264  // success, anything else failure.
1265  if (ret && (PyErr_Occurred() == NULL))
1266  {
1267  return 0;
1268  }
1269  else
1270  {
1271  return -1;
1272  }
1273 
1274 }
PyObject_HEAD Id id_
Definition: moosemodule.h:114
Py_ssize_t moose_Id_getLength(_Id *self)
Definition: vec.cpp:607
char shortType(string)
uint32_t value
Definition: moosemodule.h:42
#define RAISE_INVALID_ID(ret, msg)
Definition: moosemodule.h:71
string getFieldType(string className, string fieldName)
static bool setVec(ObjId destId, const string &field, const vector< A > &arg)
Definition: SetGet.h:252
static bool isValid(Id id)
Definition: Id.h:145
static A get(const ObjId &dest, const string &field)
Definition: SetGet.h:284

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

PyObject* moose_Id_setField ( _Id self,
PyObject *  args 
)

Definition at line 958 of file vec.cpp.

References Id::isValid(), moose_Id_setattro(), RAISE_INVALID_ID, and value.

959 {
960  if (!Id::isValid(self->id_))
961  {
962  RAISE_INVALID_ID(NULL, "moose_Id_setField");
963  }
964  PyObject * field = NULL;
965  PyObject * value = NULL;
966  if (!PyArg_ParseTuple(args, "OO:moose_Id_setField", &field, &value))
967  {
968  return NULL;
969  }
970  if (moose_Id_setattro(self, field, value) == -1)
971  {
972  return NULL;
973  }
974  Py_RETURN_NONE;
975 }
PyObject_HEAD Id id_
Definition: moosemodule.h:114
uint32_t value
Definition: moosemodule.h:42
#define RAISE_INVALID_ID(ret, msg)
Definition: moosemodule.h:71
static bool isValid(Id id)
Definition: Id.h:145
int moose_Id_setattro(_Id *self, PyObject *attr, PyObject *value)
Definition: vec.cpp:977

+ Here is the call graph for this function:

PyObject* moose_Id_str ( _Id self)

Definition at line 566 of file vec.cpp.

References Id::isValid(), and RAISE_INVALID_ID.

567 {
568  if (!Id::isValid(self->id_))
569  {
570  RAISE_INVALID_ID(NULL, "moose_Id_str");
571  }
572  return PyString_FromFormat("<moose.vec: class=%s, id=%u, path=%s>",
573  Field<string>::get(self->id_, "className").c_str(),
574  self->id_.value(), self->id_.path().c_str());
575 } // ! moose_Id_str
PyObject_HEAD Id id_
Definition: moosemodule.h:114
Definition: SetGet.h:236
#define RAISE_INVALID_ID(ret, msg)
Definition: moosemodule.h:71
static bool isValid(Id id)
Definition: Id.h:145

+ Here is the call graph for this function:

PyObject* moose_Id_subscript ( _Id self,
PyObject *  op 
)

Definition at line 730 of file vec.cpp.

References moose_Id_fillSlice(), moose_Id_getItem(), moose_Id_getLength(), SLICE_OBJ, and value.

731 {
732  if (PySlice_Check(op))
733  {
734  const Py_ssize_t len = moose_Id_getLength(self);
735  Py_ssize_t start, stop, step, slicelength;
736 
737  if (PySlice_GetIndicesEx(SLICE_OBJ(op), len, &start, &stop, &step, &slicelength) < 0)
738  return NULL;
739 
740  return moose_Id_fillSlice(self, start, stop, step, slicelength);
741  }
742 
743  if (PyInt_Check(op) || PyLong_Check(op))
744  {
745  Py_ssize_t value = PyInt_AsLong(op);
746  return moose_Id_getItem(self, value);
747  }
748  else
749  {
750  PyErr_SetString(PyExc_KeyError, "moose_Id_subscript: invalid index.");
751  return NULL;
752  }
753 }
Py_ssize_t moose_Id_getLength(_Id *self)
Definition: vec.cpp:607
uint32_t value
Definition: moosemodule.h:42
PyObject * moose_Id_getItem(_Id *self, Py_ssize_t index)
Definition: vec.cpp:649
static double op(double x)
#define SLICE_OBJ(x)
Definition: vec.cpp:724
static PyObject * moose_Id_fillSlice(_Id *self, Py_ssize_t start, Py_ssize_t end, Py_ssize_t step, Py_ssize_t slicelength)
Definition: vec.cpp:678

+ Here is the call graph for this function:

PyObject* moose_isRunning ( PyObject *  dummy,
PyObject *  args 
)

Definition at line 1759 of file moosemodule.cpp.

References SHELLPTR.

1760 {
1761  return Py_BuildValue("i", SHELLPTR->isRunning());
1762 }
#define SHELLPTR
Definition: moosemodule.h:105
PyObject* moose_loadModel ( PyObject *  dummy,
PyObject *  args 
)

Definition at line 1794 of file moosemodule.cpp.

References _Id::id_, IdType, and SHELLPTR.

1795 {
1796  char * fname = NULL, * modelpath = NULL, * solverclass = NULL;
1797 
1798  if(!PyArg_ParseTuple(args, "ss|s:moose_loadModel", &fname, &modelpath, &solverclass))
1799  {
1800  cout << "here in moose load";
1801  return NULL;
1802  }
1803  _Id * model = (_Id*)PyObject_New(_Id, &IdType);
1804  if (!solverclass)
1805  {
1806  model->id_ = SHELLPTR->doLoadModel(string(fname), string(modelpath));
1807  }
1808  else
1809  {
1810  model->id_ = SHELLPTR->doLoadModel(string(fname), string(modelpath), string(solverclass));
1811  }
1812  if (model->id_ == Id())
1813  {
1814  Py_XDECREF(model);
1815  PyErr_SetString(PyExc_IOError, "could not load model");
1816  return NULL;
1817  }
1818  PyObject * ret = reinterpret_cast<PyObject*>(model);
1819  return ret;
1820 }
PyObject_HEAD Id id_
Definition: moosemodule.h:114
#define SHELLPTR
Definition: moosemodule.h:105
Definition: Id.h:17
PyTypeObject IdType
Definition: vec.cpp:262
PyObject* moose_LookupField_getItem ( _Field self,
PyObject *  key 
)

Definition at line 221 of file mfield.cpp.

References getLookupField().

222 {
223  return getLookupField(self->owner->oid_, self->name, key);
224 }
PyObject * getLookupField(ObjId target, char *fieldName, PyObject *key)
Definition: melement.cpp:1295
PyObject_HEAD ObjId oid_
Definition: moosemodule.h:133
_ObjId * owner
Definition: moosemodule.h:140
PyObject_HEAD char * name
Definition: moosemodule.h:139

+ Here is the call graph for this function:

int moose_LookupField_setItem ( _Field self,
PyObject *  key,
PyObject *  value 
)

Definition at line 226 of file mfield.cpp.

References setLookupField().

228 {
229  return setLookupField(self->owner->oid_,
230  self->name, key, value);
231 }
uint32_t value
Definition: moosemodule.h:42
PyObject_HEAD ObjId oid_
Definition: moosemodule.h:133
_ObjId * owner
Definition: moosemodule.h:140
int setLookupField(ObjId target, char *fieldName, PyObject *key, PyObject *value)
Definition: melement.cpp:1480
PyObject_HEAD char * name
Definition: moosemodule.h:139

+ Here is the call graph for this function:

PyObject* moose_move ( PyObject *  dummy,
PyObject *  args 
)

Definition at line 1468 of file moosemodule.cpp.

References ObjId::bad(), Id::id_, IdType, Id::isValid(), ObjIdType, RAISE_INVALID_ID, and SHELLPTR.

1469 {
1470  PyObject * src, * dest;
1471  if (!PyArg_ParseTuple(args, "OO:moose_move", &src, &dest))
1472  {
1473  return NULL;
1474  }
1475  Id _src;
1476  ObjId _dest;
1477  if (PyObject_IsInstance(src, (PyObject*)&IdType))
1478  {
1479  _src = ((_Id*)src)->id_;
1480  }
1481  else if (PyObject_IsInstance(src, (PyObject*)&ObjIdType))
1482  {
1483  _src = ((_ObjId*)src)->oid_.id;
1484  }
1485  else if (PyString_Check(src))
1486  {
1487  _src = Id(PyString_AsString(src));
1488  }
1489  else
1490  {
1491  PyErr_SetString(PyExc_TypeError, "Source must be instance of vec, element or string.");
1492  return NULL;
1493  }
1494  if (_src == Id())
1495  {
1496  PyErr_SetString(PyExc_ValueError, "Cannot make move moose shell.");
1497  return NULL;
1498  }
1499  if (PyObject_IsInstance(dest, (PyObject*)&IdType))
1500  {
1501  _dest = ObjId(((_Id*)dest)->id_);
1502  }
1503  else if (PyObject_IsInstance(dest, (PyObject*)&ObjIdType))
1504  {
1505  _dest = ((_ObjId*)dest)->oid_;
1506  }
1507  else if (PyString_Check(dest))
1508  {
1509  _dest = ObjId(PyString_AsString(dest));
1510  }
1511  else
1512  {
1513  PyErr_SetString(PyExc_TypeError, "destination must be instance of vec, element or string.");
1514  return NULL;
1515  }
1516  if (!Id::isValid(_src))
1517  {
1518  RAISE_INVALID_ID(NULL, "moose_copy: invalid source Id.");
1519  }
1520  else if (_dest.bad())
1521  {
1522  RAISE_INVALID_ID(NULL, "moose_copy: invalid destination.");
1523  }
1524  SHELLPTR->doMove(_src, _dest);
1525  Py_RETURN_NONE;
1526 }
#define SHELLPTR
Definition: moosemodule.h:105
bool bad() const
Definition: ObjId.cpp:18
Definition: ObjId.h:20
#define RAISE_INVALID_ID(ret, msg)
Definition: moosemodule.h:71
PyTypeObject ObjIdType
static bool isValid(Id id)
Definition: Id.h:145
Definition: Id.h:17
PyTypeObject IdType
Definition: vec.cpp:262
unsigned int id_
Definition: Id.h:172

+ Here is the call graph for this function:

PyObject* moose_ObjId_connect ( _ObjId self,
PyObject *  args 
)

Definition at line 2195 of file melement.cpp.

References ObjId::bad(), Id::isValid(), ObjIdType, _ObjId::oid_, RAISE_INVALID_ID, and SHELLPTR.

2196 {
2197  if (!Id::isValid(self->oid_.id))
2198  {
2199  RAISE_INVALID_ID(NULL, "moose_ObjId_connect");
2200  }
2201  extern PyTypeObject ObjIdType;
2202  PyObject * destPtr = NULL;
2203  char * srcField = NULL, * destField = NULL, * msgType = NULL;
2204  static char default_msg_type[] = "Single";
2205  if(!PyArg_ParseTuple(args,
2206  "sOs|s:moose_ObjId_connect",
2207  &srcField,
2208  &destPtr,
2209  &destField,
2210  &msgType))
2211  {
2212  return NULL;
2213  }
2214  if (msgType == NULL)
2215  {
2216  msgType = default_msg_type;
2217  }
2218  _ObjId * dest = reinterpret_cast<_ObjId*>(destPtr);
2219  ObjId mid = SHELLPTR->doAddMsg(msgType,
2220  self->oid_,
2221  string(srcField),
2222  dest->oid_,
2223  string(destField));
2224  if (mid.bad())
2225  {
2226  PyErr_SetString(PyExc_NameError,
2227  "connect failed: check field names and type compatibility.");
2228  return NULL;
2229  }
2230  _ObjId* msgMgrId = (_ObjId*)PyObject_New(_ObjId, &ObjIdType);
2231  msgMgrId->oid_ = mid;
2232  return (PyObject*)msgMgrId;
2233 }
#define SHELLPTR
Definition: moosemodule.h:105
bool bad() const
Definition: ObjId.cpp:18
Id id
Definition: ObjId.h:98
Definition: ObjId.h:20
#define RAISE_INVALID_ID(ret, msg)
Definition: moosemodule.h:71
PyObject_HEAD ObjId oid_
Definition: moosemodule.h:133
static bool isValid(Id id)
Definition: Id.h:145
PyTypeObject ObjIdType
Definition: melement.cpp:2463

+ Here is the call graph for this function:

PyObject* moose_ObjId_get_destField_attr ( PyObject *  self,
void *  closure 
)

Definition at line 2677 of file moosemodule.cpp.

References ObjId::id, Id::isValid(), moose_DestField, name, ObjIdType, _ObjId::oid_, and RAISE_INVALID_ID.

Referenced by defineDestFinfos().

2678 {
2679  if (!PyObject_IsInstance(self, (PyObject*)&ObjIdType))
2680  {
2681  PyErr_SetString(PyExc_TypeError, "First argument must be an instance of element");
2682  return NULL;
2683  }
2684  _ObjId * obj = (_ObjId*)self;
2685  if (!Id::isValid(obj->oid_.id))
2686  {
2687  RAISE_INVALID_ID(NULL, "moose_ObjId_get_destField_attr");
2688  }
2689  char * name = NULL;
2690  if (!PyArg_ParseTuple((PyObject *)closure,
2691  "s:_get_destField: "
2692  "expected a string in getter closure.",
2693  &name))
2694  {
2695  return NULL;
2696  }
2697  PyObject * args = PyTuple_New(2);
2698 
2699  PyTuple_SetItem(args, 0, self);
2700  Py_INCREF(self); // compensate for reference stolen by PyTuple_SetItem
2701  PyTuple_SetItem(args, 1, PyString_FromString(name));
2702  _Field * ret = PyObject_New(_Field, &moose_DestField);
2703  if (moose_DestField.tp_init((PyObject*)ret, args, NULL) != 0)
2704  {
2705  Py_XDECREF((PyObject*)ret);
2706  ret = NULL;
2707  PyErr_SetString(PyExc_RuntimeError, "moose_ObjId_get_destField_attr: failed to init DestField object");
2708  }
2709  Py_DECREF(args);
2710  return (PyObject*)ret;
2711 }
Id id
Definition: ObjId.h:98
#define RAISE_INVALID_ID(ret, msg)
Definition: moosemodule.h:71
PyObject_HEAD ObjId oid_
Definition: moosemodule.h:133
PyTypeObject moose_DestField
Definition: mfield.cpp:333
PyTypeObject ObjIdType
static bool isValid(Id id)
Definition: Id.h:145
static char name[]
Definition: mfield.cpp:401

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

PyObject* moose_ObjId_get_elementField_attr ( PyObject *  self,
void *  closure 
)

Definition at line 2822 of file moosemodule.cpp.

References ObjId::id, Id::isValid(), moose_ElementField, name, _ObjId::oid_, and RAISE_INVALID_ID.

Referenced by defineElementFinfos().

2824 {
2825  // if (!PyObject_IsInstance(self, (PyObject*)&ObjIdType)){
2826  // PyErr_SetString(PyExc_TypeError,
2827  // "First argument must be an instance of element");
2828  // return NULL;
2829  // }
2830  _ObjId * obj = (_ObjId*)self;
2831  if (!Id::isValid(obj->oid_.id))
2832  {
2833  RAISE_INVALID_ID(NULL, "moose_ObjId_get_elementField_attr");
2834  }
2835  char * name = NULL;
2836  if (!PyArg_ParseTuple((PyObject *)closure,
2837  "s:moose_ObjId_get_elementField_attr: expected a string in getter closure.",
2838  &name))
2839  {
2840  return NULL;
2841  }
2842  // Create a new instance of ElementField `name` and set it as
2843  // an attribute of the object `self`.
2844  // 1. Create the argument for init method of ElementField. This
2845  // will be (fieldname, self)
2846  PyObject * args = PyTuple_New(2);
2847  PyTuple_SetItem(args, 0, self);
2848  Py_INCREF(self); // compensate for stolen ref
2849  PyTuple_SetItem(args, 1, PyString_FromString(name));
2850  _Field * ret = PyObject_New(_Field, &moose_ElementField);
2851 
2852  // 2. Now use this arg to actually create the element field.
2853  if (moose_ElementField.tp_init((PyObject*)ret, args, NULL) != 0)
2854  {
2855  Py_DECREF((PyObject*)ret);
2856  ret = NULL;
2857  PyErr_SetString(PyExc_RuntimeError, "moose_ObjId_get_elementField_attr: failed to init ElementField object");
2858  }
2859  Py_DECREF(args);
2860  return (PyObject*)ret;
2861 }
PyTypeObject moose_ElementField
Definition: mfield.cpp:473
Id id
Definition: ObjId.h:98
#define RAISE_INVALID_ID(ret, msg)
Definition: moosemodule.h:71
PyObject_HEAD ObjId oid_
Definition: moosemodule.h:133
static bool isValid(Id id)
Definition: Id.h:145
static char name[]
Definition: mfield.cpp:401

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

PyObject* moose_ObjId_get_lookupField_attr ( PyObject *  self,
void *  closure 
)

Try to obtain a LookupField object for a specified lookupFinfo. The first item in closure must be the name of the LookupFinfo - {fieldname}. The LookupField is identified by {path}.{fieldname} where {path} is the unique path of the moose element self. We look for an already initialized LookupField object for this identifier and return if one is found. Otherwise, we create a new LookupField object and buffer it in a map before returning.

Definition at line 2781 of file moosemodule.cpp.

References ObjId::id, Id::isValid(), moose_LookupField, name, ObjIdType, _ObjId::oid_, and RAISE_INVALID_ID.

Referenced by defineLookupFinfos().

2783 {
2784  if (!PyObject_IsInstance(self, (PyObject*)&ObjIdType))
2785  {
2786  PyErr_SetString(PyExc_TypeError,
2787  "First argument must be an instance of element");
2788  return NULL;
2789  }
2790  _ObjId * obj = (_ObjId*)self;
2791  if (!Id::isValid(obj->oid_.id))
2792  {
2793  RAISE_INVALID_ID(NULL, "moose_ObjId_get_lookupField_attr");
2794  }
2795  char * name = NULL;
2796  if (!PyArg_ParseTuple((PyObject *)closure,
2797  "s:moose_ObjId_get_lookupField_attr: expected a string in getter closure.",
2798  &name))
2799  {
2800  return NULL;
2801  }
2802  assert(name);
2803  /* Create a new instance of LookupField `name` and set it as
2804  * an attribute of the object self. Create the argument for
2805  * init method of LookupField. This will be (fieldname, self) */
2806  PyObject * args = PyTuple_New(2);
2807  PyTuple_SetItem(args, 0, self);
2808  Py_INCREF(self); // compensate for stolen ref
2809  PyTuple_SetItem(args, 1, PyString_FromString(name));
2810  _Field * ret = PyObject_New(_Field, &moose_LookupField);
2811  if (moose_LookupField.tp_init((PyObject*)ret, args, NULL) != 0)
2812  {
2813  Py_XDECREF((PyObject*)ret);
2814  ret = NULL;
2815  PyErr_SetString(PyExc_RuntimeError,
2816  "moose_ObjId_get_lookupField_attr: failed to init LookupField object");
2817  }
2818  Py_DECREF(args);
2819  return (PyObject*)ret;
2820 }
Id id
Definition: ObjId.h:98
#define RAISE_INVALID_ID(ret, msg)
Definition: moosemodule.h:71
PyObject_HEAD ObjId oid_
Definition: moosemodule.h:133
PyTypeObject ObjIdType
static bool isValid(Id id)
Definition: Id.h:145
PyTypeObject moose_LookupField
Definition: mfield.cpp:252
static char name[]
Definition: mfield.cpp:401

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

PyObject* moose_ObjId_getattro ( _ObjId self,
PyObject *  attr 
)

2011-03-28 13:59:41 (+0530)

Get a specified field. Re-done on: 2011-03-23 14:42:03 (+0530)

I wonder how to cleanly do this. The Id - ObjId dichotomy is really ugly. When you don't pass an index, it is just treated as 0. Then what is the point of having Id separately? ObjId would been just fine!

Definition at line 484 of file melement.cpp.

References Field< A >::get(), get_field_alias(), get_ObjId_attr(), getFieldNames(), getFieldType(), RAISE_INVALID_ID, shortType(), to_py(), and value.

Referenced by moose_ObjId_getField().

485 {
486  int new_attr = 0;
487  if (self->oid_.bad())
488  {
489  RAISE_INVALID_ID(NULL, "moose_ObjId_getattro");
490  }
491  // extern PyTypeObject IdType;
492  // extern PyTypeObject ObjIdType;
493  const char * field;
494  char ftype;
495  if (PyString_Check(attr))
496  {
497  field = PyString_AsString(attr);
498  }
499  else
500  {
501  return PyObject_GenericGetAttr((PyObject*)self, attr);
502  }
503  PyObject * _ret = get_ObjId_attr(self, field);
504  if (_ret != NULL)
505  {
506  return _ret;
507  }
508  string fieldName(field);
509  string className = Field<string>::get(self->oid_, "className");
510  vector<string> valueFinfos = getFieldNames(className, "valueFinfo");
511  bool isValueField = false;
512  for (unsigned int ii = 0; ii < valueFinfos.size(); ++ii)
513  {
514  if (fieldName == valueFinfos[ii])
515  {
516  isValueField = true;
517  break;
518  }
519  }
520 
521  string type = getFieldType(className, fieldName);
522  if (type.empty() || !isValueField )
523  {
524  // Check if this field name is aliased and update fieldName and type if so.
525  map<string, string>::const_iterator it = get_field_alias().find(fieldName);
526  if (it != get_field_alias().end())
527  {
528  fieldName = it->second;
529  field = fieldName.c_str();
530  isValueField = false;
531  for (unsigned int ii = 0; ii < valueFinfos.size(); ++ii)
532  {
533  if (fieldName == valueFinfos[ii])
534  {
535  isValueField = true;
536  break;
537  }
538  }
539  type = getFieldType(Field<string>::get(self->oid_, "className"), fieldName);
540  // Update attr for next level (PyObject_GenericGetAttr) in case.
541  // Py_XDECREF(attr);
542  attr = PyString_FromString(field);
543  new_attr = 1;
544  }
545  }
546  if (type.empty() || !isValueField)
547  {
548  _ret = PyObject_GenericGetAttr((PyObject*)self, attr);
549  if (new_attr)
550  {
551  Py_DECREF(attr);
552  }
553  return _ret;
554  }
555  ftype = shortType(type);
556  if (!ftype)
557  {
558  _ret = PyObject_GenericGetAttr((PyObject*)self, attr);
559  if (new_attr)
560  {
561  Py_DECREF(attr);
562  }
563  return _ret;
564  }
565  fieldName= string(field);
566  switch(ftype)
567  {
568  case 's':
569  {
570  string _s = Field<string>::get(self->oid_, fieldName);
571  _ret = Py_BuildValue("s", _s.c_str());
572  break;
573  }
574  case 'd':
575  {
576  double value = Field< double >::get(self->oid_, fieldName);
577  _ret = to_py(&value, ftype);
578  break;
579  }
580  case 'i':
581  {
582  int value = Field<int>::get(self->oid_, fieldName);
583  _ret = to_py(&value, ftype);
584  break;
585  }
586  case 'I':
587  {
588  unsigned int value = Field<unsigned int>::get(self->oid_, fieldName);
589  _ret = to_py(&value, ftype);
590  break;
591  }
592  case 'l':
593  {
594  long value = Field<long>::get(self->oid_, fieldName);
595  _ret = to_py(&value, ftype);
596  break;
597  }
598  case 'L':
599  {
600  long long value = Field<long long>::get(self->oid_, fieldName);
601  _ret = to_py(&value, ftype);
602  break;
603  }
604  case 'k':
605  {
606  unsigned long value = Field<unsigned long>::get(self->oid_, fieldName);
607  _ret = to_py(&value, ftype);
608  break;
609  }
610  case 'K':
611  {
612  unsigned long long value = Field<unsigned long long>::get(self->oid_, fieldName);
613  _ret = to_py(&value, ftype);
614  break;
615  }
616  case 'f':
617  {
618  float value = Field<float>::get(self->oid_, fieldName);
619  _ret = to_py(&value, ftype);
620  break;
621  }
622  case 'x':
623  {
624  Id value = Field<Id>::get(self->oid_, fieldName);
625  _ret = to_py(&value, ftype);
626  break;
627  }
628  case 'y':
629  {
630  ObjId value = Field<ObjId>::get(self->oid_, fieldName);
631  _ret = to_py(&value, ftype);
632  break;
633  }
634  case 'z':
635  {
636  PyErr_SetString(PyExc_NotImplementedError, "DataId handling not implemented yet.");
637  _ret = NULL;
638  break;
639  }
640  case 'D':
641  {
642  vector< double > value = Field< vector < double > >::get(self->oid_, fieldName);
643  _ret = to_py(&value, ftype);
644  break;
645  }
646  case 'X': // vector<Id>
647  {
648  vector < Id > value = Field<vector <Id> >::get(self->oid_, fieldName);
649  _ret = to_py(&value, ftype);
650  break;
651  }
652  case 'Y': // vector<ObjId>
653  {
654  vector < ObjId > value = Field<vector <ObjId> >::get(self->oid_, fieldName);
655  _ret = to_py(&value, ftype);
656  break;
657  }
658  case 'M':
659  {
660  vector< long > value = Field< vector <long> >::get(self->oid_, fieldName);
661  _ret = to_py(&value, ftype);
662  break;
663  }
664  case 'P':
665  {
666  vector < unsigned long > value = Field< vector < unsigned long > >::get(self->oid_, fieldName);
667  _ret = to_py(&value, ftype);
668  break;
669  }
670  case 'S':
671  {
672  vector < string > value = Field<vector <string> >::get(self->oid_, fieldName);
673  _ret = to_py(&value, ftype);
674  break;
675  }
676  case 'v':
677  {
678  vector < int > value = Field<vector <int> >::get(self->oid_, fieldName);
679  _ret = to_py(&value, ftype);
680  break;
681  }
682  case 'N':
683  {
684  vector <unsigned int > value = Field< vector < unsigned int> >::get(self->oid_, fieldName);
685  _ret = to_py(&value, ftype);
686  break;
687  }
688  case 'T': // vector<vector < unsigned int >>
689  {
690  vector < vector < unsigned int > > value = Field<vector <vector < unsigned int > > >::get(self->oid_, fieldName);
691  _ret = to_py(&value, ftype);
692  break;
693  }
694  case 'Q': // vector< vector < int > >
695  {
696  vector < vector < int > > value = Field<vector < vector < int > > >::get(self->oid_, fieldName);
697  _ret = to_py(&value, ftype);
698  break;
699  }
700  case 'R': // vector< vector < double > >
701  {
702  vector < vector < double > > value = Field<vector < vector < double > > >::get(self->oid_, fieldName);
703  _ret = to_py(&value, ftype);
704  break;
705  }
706  case 'F':
707  {
708  vector <float> value = Field< vector < float > >::get(self->oid_, fieldName);
709  _ret = to_py(&value, ftype);
710  break;
711  }
712  case 'c':
713  {
714  char value = Field<char>::get(self->oid_, fieldName);
715  _ret = to_py(&value, ftype);
716  break;
717  }
718  case 'h':
719  {
720  short value = Field<short>::get(self->oid_, fieldName);
721  _ret = to_py(&value, ftype);
722  break;
723  }
724  case 'H':
725  {
726  unsigned short value = Field<unsigned short>::get(self->oid_, fieldName);
727  _ret = to_py(&value, ftype);
728  break;
729  }
730  case 'w':
731  {
732  vector < short > value = Field<vector <short> >::get(self->oid_, fieldName);
733  _ret = to_py(&value, ftype);
734  break;
735  }
736  case 'C':
737  {
738  vector < char > value = Field<vector <char> >::get(self->oid_, fieldName);
739  _ret = to_py(&value, ftype);
740  break;
741  }
742 
743  case 'b':
744  {
745  bool value = Field<bool>::get(self->oid_, fieldName);
746  if (value)
747  {
748  _ret = Py_True;
749  Py_INCREF(Py_True);
750  }
751  else
752  {
753  _ret = Py_False;
754  Py_INCREF(Py_False);
755  }
756  break;
757  }
758 
759  default:
760  _ret = PyObject_GenericGetAttr((PyObject*)self, attr);
761 
762  }
763  if (new_attr)
764  {
765  Py_DECREF(attr);
766  }
767  return _ret;
768 }
char shortType(string)
uint32_t value
Definition: moosemodule.h:42
bool bad() const
Definition: ObjId.cpp:18
Definition: SetGet.h:236
Definition: ObjId.h:20
const map< string, string > & get_field_alias()
#define RAISE_INVALID_ID(ret, msg)
Definition: moosemodule.h:71
PyObject_HEAD ObjId oid_
Definition: moosemodule.h:133
PyObject * get_ObjId_attr(_ObjId *oid, string attribute)
Definition: melement.cpp:83
string getFieldType(string className, string fieldName)
Definition: Id.h:17
PyObject * to_py(void *obj, char typecode)
static A get(const ObjId &dest, const string &field)
Definition: SetGet.h:284
vector< string > getFieldNames(string className, string finfoType)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

PyObject* moose_ObjId_getDataIndex ( _ObjId self)

Definition at line 2317 of file melement.cpp.

References Id::isValid(), and RAISE_INVALID_ID.

Referenced by get_ObjId_attr().

2318 {
2319  if (!Id::isValid(self->oid_.id))
2320  {
2321  RAISE_INVALID_ID(NULL, "moose_ObjId_getDataIndex");
2322  }
2323  PyObject * ret = Py_BuildValue("I", self->oid_.dataIndex);
2324  return ret;
2325 }
Id id
Definition: ObjId.h:98
#define RAISE_INVALID_ID(ret, msg)
Definition: moosemodule.h:71
PyObject_HEAD ObjId oid_
Definition: moosemodule.h:133
static bool isValid(Id id)
Definition: Id.h:145
unsigned int dataIndex
Definition: ObjId.h:99

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

PyObject* moose_ObjId_getField ( _ObjId self,
PyObject *  args 
)

Definition at line 460 of file melement.cpp.

References Id::isValid(), moose_ObjId_getattro(), and RAISE_INVALID_ID.

461 {
462  if (!Id::isValid(self->oid_.id))
463  {
464  RAISE_INVALID_ID(NULL, "moose_ObjId_getField");
465  }
466  PyObject * attr;
467  if (!PyArg_ParseTuple(args, "O:moose_ObjId_getField", &attr))
468  {
469  return NULL;
470  }
471  return moose_ObjId_getattro(self, attr);
472 }
Id id
Definition: ObjId.h:98
#define RAISE_INVALID_ID(ret, msg)
Definition: moosemodule.h:71
PyObject_HEAD ObjId oid_
Definition: moosemodule.h:133
PyObject * moose_ObjId_getattro(_ObjId *self, PyObject *attr)
Definition: melement.cpp:484
static bool isValid(Id id)
Definition: Id.h:145

+ Here is the call graph for this function:

PyObject* moose_ObjId_getFieldIndex ( _ObjId self)

Definition at line 2330 of file melement.cpp.

References Id::isValid(), and RAISE_INVALID_ID.

Referenced by get_ObjId_attr().

2331 {
2332  if (!Id::isValid(self->oid_.id))
2333  {
2334  RAISE_INVALID_ID(NULL, "moose_ObjId_getFieldIndex");
2335  }
2336  PyObject * ret = Py_BuildValue("I", self->oid_.dataIndex);
2337  return ret;
2338 }
Id id
Definition: ObjId.h:98
#define RAISE_INVALID_ID(ret, msg)
Definition: moosemodule.h:71
PyObject_HEAD ObjId oid_
Definition: moosemodule.h:133
static bool isValid(Id id)
Definition: Id.h:145
unsigned int dataIndex
Definition: ObjId.h:99

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

PyObject* moose_ObjId_getFieldNames ( _ObjId self,
PyObject *  args 
)

Definition at line 2047 of file melement.cpp.

References Field< A >::get(), getFieldNames(), getFinfoTypes(), Id::isValid(), and RAISE_INVALID_ID.

2048 {
2049  if (!Id::isValid(self->oid_.id))
2050  {
2051  RAISE_INVALID_ID(NULL, "moose_ObjId_getFieldNames");
2052  }
2053  char * ftype = NULL;
2054  if (!PyArg_ParseTuple(args, "|s:moose_ObjId_getFieldNames", &ftype))
2055  {
2056  return NULL;
2057  }
2058  string ftype_str = (ftype != NULL)? string(ftype): "";
2059  vector<string> ret;
2060  string className = Field<string>::get(self->oid_, "className");
2061  if (ftype_str == "")
2062  {
2063  for (const char **a = getFinfoTypes(); *a; ++a)
2064  {
2065  vector<string> fields = getFieldNames(className, string(*a));
2066  ret.insert(ret.end(), fields.begin(), fields.end());
2067  }
2068  }
2069  else
2070  {
2071  ret = getFieldNames(className, ftype_str);
2072  }
2073 
2074  PyObject * pyret = PyTuple_New((Py_ssize_t)ret.size());
2075 
2076  for (unsigned int ii = 0; ii < ret.size(); ++ ii )
2077  {
2078  PyObject * fname = Py_BuildValue("s", ret[ii].c_str());
2079  if (!fname)
2080  {
2081  Py_XDECREF(pyret);
2082  pyret = NULL;
2083  break;
2084  }
2085  if (PyTuple_SetItem(pyret, (Py_ssize_t)ii, fname))
2086  {
2087  Py_XDECREF(pyret);
2088  // Py_DECREF(fname);
2089  pyret = NULL;
2090  break;
2091  }
2092  }
2093  return pyret;
2094 }
const char ** getFinfoTypes()
finalize()
Id id
Definition: ObjId.h:98
#define RAISE_INVALID_ID(ret, msg)
Definition: moosemodule.h:71
PyObject_HEAD ObjId oid_
Definition: moosemodule.h:133
static bool isValid(Id id)
Definition: Id.h:145
static A get(const ObjId &dest, const string &field)
Definition: SetGet.h:284
vector< string > getFieldNames(string className, string finfoType)

+ Here is the call graph for this function:

PyObject* moose_ObjId_getFieldType ( _ObjId self,
PyObject *  args 
)

Definition at line 420 of file melement.cpp.

References getFieldType(), Id::isValid(), and RAISE_INVALID_ID.

421 {
422  if (!Id::isValid(self->oid_.id))
423  {
424  RAISE_INVALID_ID(NULL, "moose_ObjId_getFieldType");
425  }
426  char * fieldName = NULL;
427  if (!PyArg_ParseTuple(args, "s:moose_ObjId_getFieldType", &fieldName))
428  {
429  return NULL;
430  }
431  string typeStr = getFieldType(Field<string>::get(self->oid_, "className"),
432  string(fieldName));
433  if (typeStr.length() <= 0)
434  {
435  PyErr_SetString(PyExc_ValueError,
436  "Empty string for field type. "
437  "Field name may be incorrect.");
438  return NULL;
439  }
440  PyObject * type = PyString_FromString(typeStr.c_str());
441  return type;
442 } // ! moose_Id_getFieldType
Definition: SetGet.h:236
Id id
Definition: ObjId.h:98
#define RAISE_INVALID_ID(ret, msg)
Definition: moosemodule.h:71
PyObject_HEAD ObjId oid_
Definition: moosemodule.h:133
string getFieldType(string className, string fieldName)
static bool isValid(Id id)
Definition: Id.h:145

+ Here is the call graph for this function:

PyObject* moose_ObjId_getId ( _ObjId self)

Definition at line 394 of file melement.cpp.

References _Id::id_, IdType, Id::isValid(), and RAISE_INVALID_ID.

Referenced by get_ObjId_attr().

395 {
396  if (!Id::isValid(self->oid_.id))
397  {
398  RAISE_INVALID_ID(NULL, "moose_ObjId_getId");
399  }
400  extern PyTypeObject IdType;
401  _Id * ret = PyObject_New(_Id, &IdType);
402  ret->id_ = self->oid_.id;
403  return (PyObject*)ret;
404 }
PyObject_HEAD Id id_
Definition: moosemodule.h:114
Id id
Definition: ObjId.h:98
#define RAISE_INVALID_ID(ret, msg)
Definition: moosemodule.h:71
PyObject_HEAD ObjId oid_
Definition: moosemodule.h:133
PyTypeObject IdType
Definition: vec.cpp:262
static bool isValid(Id id)
Definition: Id.h:145

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

PyObject* moose_ObjId_getItem ( _ObjId self,
Py_ssize_t  index 
)

Definition at line 1210 of file melement.cpp.

References moose_ObjId_getLength(), ObjIdType, and _ObjId::oid_.

1211 {
1212  if (index < 0)
1213  {
1214  index += moose_ObjId_getLength(self);
1215  }
1216  if ((index < 0) || (index >= moose_ObjId_getLength(self)))
1217  {
1218  PyErr_SetString(PyExc_IndexError, "Index out of bounds.");
1219  return NULL;
1220  }
1221  // Here I am assuming the user can start with any ObjId and
1222  // ask for an index - which will be field index.
1223  // Thus if syn[0...9] correspond to chan[0...9], then syn[0] is still a valid ObjId.
1224  // For example, syn has Id X, dataIndex 0...9, and under dataIndex=0, we have 5 field elements f[0...5]
1225  // Then syn = Id(X)
1226  // syn[0] = ObjId(X, 0, 0) = syn[0][0]
1227  // assign s0 <- syn[0]
1228  // what is s0[1]? ObjId(X
1229  // syn[0][1]->ObjId(X, 0, 1) =syn[0][0][0] - which is an ObjId.
1230  // Now, what is syn[0][1][2] ?
1231 
1232  // In PyMOOSE, user is allowed to directly put in the numbers
1233  // for Id, dataIndex and fieldIndex directly and construct an
1234  // ObjId.
1235  _ObjId * ret = PyObject_New(_ObjId, &ObjIdType);
1236  ret->oid_ = ObjId(self->oid_.id, self->oid_.dataIndex, index);
1237  return (PyObject*)ret;
1238 }
Id id
Definition: ObjId.h:98
Definition: ObjId.h:20
Py_ssize_t moose_ObjId_getLength(_ObjId *self)
Definition: melement.cpp:1276
PyObject_HEAD ObjId oid_
Definition: moosemodule.h:133
PyTypeObject ObjIdType
Definition: melement.cpp:2463
unsigned int dataIndex
Definition: ObjId.h:99

+ Here is the call graph for this function:

Py_ssize_t moose_ObjId_getLength ( _ObjId self)

Definition at line 1276 of file melement.cpp.

References Element::hasFields(), and FieldElement::numData().

Referenced by moose_ObjId_getItem(), and moose_ObjId_getSlice().

1277 {
1278  Element * el = self->oid_.element();
1279  if (!el->hasFields())
1280  {
1281  return 0;
1282  }
1283  FieldElement * fe = reinterpret_cast< FieldElement* >(el);
1284  if (fe == NULL)
1285  {
1286  return 0;
1287  }
1288  return (Py_ssize_t)(fe->numData());
1289 }
virtual bool hasFields() const =0
unsigned int numData() const
Virtual: Returns number of data entries.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

PyObject* moose_ObjId_getLookupField ( _ObjId self,
PyObject *  args 
)

Definition at line 1465 of file melement.cpp.

References getLookupField(), Id::isValid(), and RAISE_INVALID_ID.

1466 {
1467  if (!Id::isValid(self->oid_.id))
1468  {
1469  RAISE_INVALID_ID(NULL, "moose_ObjId_getLookupField");
1470  }
1471  char * fieldName = NULL;
1472  PyObject * key = NULL;
1473  if (!PyArg_ParseTuple(args, "sO:moose_ObjId_getLookupField", &fieldName, &key))
1474  {
1475  return NULL;
1476  }
1477  return getLookupField(self->oid_, fieldName, key);
1478 } // moose_ObjId_getLookupField
PyObject * getLookupField(ObjId target, char *fieldName, PyObject *key)
Definition: melement.cpp:1295
Id id
Definition: ObjId.h:98
#define RAISE_INVALID_ID(ret, msg)
Definition: moosemodule.h:71
PyObject_HEAD ObjId oid_
Definition: moosemodule.h:133
static bool isValid(Id id)
Definition: Id.h:145

+ Here is the call graph for this function:

PyObject* moose_ObjId_getNeighbors ( _ObjId self,
PyObject *  args 
)

Definition at line 2112 of file melement.cpp.

References _Id::id_, IdType, Id::isValid(), and RAISE_INVALID_ID.

2113 {
2114  if (!Id::isValid(self->oid_.id))
2115  {
2116  RAISE_INVALID_ID(NULL, "moose_ObjId_getNeighbors");
2117  }
2118  char * field = NULL;
2119  if (!PyArg_ParseTuple(args, "s:moose_ObjId_getNeighbors", &field))
2120  {
2121  return NULL;
2122  }
2123  vector< Id > val = LookupField< string, vector< Id > >::get(self->oid_, "neighbors", string(field));
2124 
2125  PyObject * ret = PyTuple_New((Py_ssize_t)val.size());
2126 
2127  for (unsigned int ii = 0; ii < val.size(); ++ ii )
2128  {
2129  _Id * entry = PyObject_New(_Id, &IdType);
2130  if (!entry || PyTuple_SetItem(ret, (Py_ssize_t)ii, (PyObject*)entry))
2131  {
2132  Py_DECREF(ret);
2133  // Py_DECREF((PyObject*)entry);
2134  ret = NULL;
2135  break;
2136  }
2137  entry->id_ = val[ii];
2138  }
2139  return ret;
2140 }
PyObject_HEAD Id id_
Definition: moosemodule.h:114
Id id
Definition: ObjId.h:98
#define RAISE_INVALID_ID(ret, msg)
Definition: moosemodule.h:71
PyObject_HEAD ObjId oid_
Definition: moosemodule.h:133
PyTypeObject IdType
Definition: vec.cpp:262
static bool isValid(Id id)
Definition: Id.h:145

+ Here is the call graph for this function:

PyObject* moose_ObjId_getSlice ( _ObjId self,
Py_ssize_t  start,
Py_ssize_t  end 
)

Definition at line 1240 of file melement.cpp.

References moose_ObjId_getLength(), ObjIdType, _ObjId::oid_, and value.

1241 {
1242  Py_ssize_t len = moose_ObjId_getLength(self);
1243  while (start < 0)
1244  {
1245  start += len;
1246  }
1247  while (end < 0)
1248  {
1249  end += len;
1250  }
1251  if (start > end)
1252  {
1253  // PyErr_SetString(PyExc_IndexError, "Start index must be less than end.");
1254  // python itself returns empty tuple - follow that
1255  return PyTuple_New(0);
1256  }
1257  PyObject * ret = PyTuple_New((Py_ssize_t)(end - start));
1258 
1259  // Py_XINCREF(ret);
1260  for ( int ii = start; ii < end; ++ii)
1261  {
1262  _ObjId * value = PyObject_New(_ObjId, &ObjIdType);
1263  value->oid_ = ObjId(self->oid_.id, self->oid_.dataIndex, ii);
1264  if (PyTuple_SetItem(ret, (Py_ssize_t)(ii-start), (PyObject*)value)) // danger - must we DECREF all prior values?
1265  {
1266  Py_XDECREF(ret);
1267  // Py_XDECREF(value);
1268  PyErr_SetString(PyExc_RuntimeError, "Failed to assign tuple entry.");
1269  return NULL;
1270  }
1271  }
1272  return ret;
1273 }
uint32_t value
Definition: moosemodule.h:42
Id id
Definition: ObjId.h:98
Definition: ObjId.h:20
Py_ssize_t moose_ObjId_getLength(_ObjId *self)
Definition: melement.cpp:1276
PyObject_HEAD ObjId oid_
Definition: moosemodule.h:133
PyTypeObject ObjIdType
Definition: melement.cpp:2463
unsigned int dataIndex
Definition: ObjId.h:99

+ Here is the call graph for this function:

long moose_ObjId_hash ( _ObjId self)

This function combines Id, DataId and fieldIndex to construct the hash of this object. Here we assume 16 most significant bits for Id, next 32 bits for dataIndex and the least significant 16 bits for fieldIndex. If these criteria are not met, the hash function will cause collissions. Note that the bitshift opeartions are byte order independent - so they should give the same result on both little- and big-endian systems.

Definition at line 333 of file melement.cpp.

References dataIndex, Id::isValid(), and RAISE_INVALID_ID.

334 {
335  if (!Id::isValid(self->oid_.id))
336  {
337  RAISE_INVALID_ID(-1, "moose_ObjId_hash");
338  }
339  long long id = (long long)(self->oid_.id.value());
340  long dataIndex = self->oid_.dataIndex;
341  long fieldIndex = self->oid_.fieldIndex;
342  /* attempt to make it with 32 bit system - assuming id will
343  * have its value within least significant 16 bits and
344  * dataIndex and fieldIndex will be limited to first 8 bits */
345  if (sizeof(size_t) == 8)
346  {
347  return id << 48 | dataIndex << 16 | fieldIndex;
348  }
349  else
350  {
351  return id << 16 | dataIndex << 8 | fieldIndex;
352  }
353 }
unsigned int value() const
Definition: Id.cpp:197
Id id
Definition: ObjId.h:98
#define RAISE_INVALID_ID(ret, msg)
Definition: moosemodule.h:71
PyObject_HEAD ObjId oid_
Definition: moosemodule.h:133
static char dataIndex[]
Definition: mfield.cpp:406
static bool isValid(Id id)
Definition: Id.h:145

+ Here is the call graph for this function:

int moose_ObjId_init ( _ObjId self,
PyObject *  args,
PyObject *  kwargs 
)

Definition at line 296 of file melement.cpp.

References moose::error, moose_ObjId_init_from_id(), and moose_ObjId_init_from_path().

298 {
299  if (self && !PyObject_IsInstance((PyObject*)self, (PyObject*)Py_TYPE((PyObject*)self)))
300  {
301  ostringstream error;
302  error << "Expected an melement or subclass. Found "
303  << Py_TYPE(self)->tp_name;
304  PyErr_SetString(PyExc_TypeError, error.str().c_str());
305  return -1;
306  }
307  int ret = moose_ObjId_init_from_path(self, args, kwargs);
308  if (ret >= -1)
309  {
310  return ret;
311  }
312  // parsing arguments as (path, dims, classname) failed. See if it is existing Id or ObjId.
313  if (moose_ObjId_init_from_id(self, args, kwargs) == 0)
314  {
315  return 0;
316  }
317  PyErr_SetString(PyExc_ValueError,
318  "Could not parse arguments. "
319  " Call __init__(path, n, g, dtype) or"
320  " __init__(id, dataIndex, fieldIndex)");
321  return -1;
322 }
int moose_ObjId_init_from_id(_ObjId *self, PyObject *args, PyObject *kwargs)
Definition: melement.cpp:100
int moose_ObjId_init_from_path(_ObjId *self, PyObject *args, PyObject *kwargs)
Definition: melement.cpp:164

+ Here is the call graph for this function:

PyObject* moose_ObjId_repr ( _ObjId self)

Definition at line 355 of file melement.cpp.

References Field< A >::get(), Id::isValid(), and RAISE_INVALID_ID.

356 {
357  if (!Id::isValid(self->oid_.id))
358  {
359  RAISE_INVALID_ID(NULL, "moose_ObjId_repr");
360  }
361  ostringstream repr;
362  repr << "<moose." << Field<string>::get(self->oid_, "className") << ": "
363  << "id=" << self->oid_.id.value() << ", "
364  << "dataIndex=" << self->oid_.dataIndex << ", "
365  << "path=" << self->oid_.path() << ">";
366  return PyString_FromString(repr.str().c_str());
367 } // ! moose_ObjId_repr
Id id
Definition: ObjId.h:98
#define RAISE_INVALID_ID(ret, msg)
Definition: moosemodule.h:71
PyObject_HEAD ObjId oid_
Definition: moosemodule.h:133
static bool isValid(Id id)
Definition: Id.h:145
static A get(const ObjId &dest, const string &field)
Definition: SetGet.h:284

+ Here is the call graph for this function:

PyObject* moose_ObjId_richcompare ( _ObjId self,
PyObject *  args,
int  op 
)

Definition at line 2241 of file melement.cpp.

References moose::error, Id::isValid(), ObjIdType, and RAISE_INVALID_ID.

2242 {
2243  if (!Id::isValid(self->oid_.id))
2244  {
2245  RAISE_INVALID_ID(NULL, "moose_ObjId_richcompare");
2246  }
2247  extern PyTypeObject ObjIdType;
2248  if ((self != NULL && other == NULL) || (self == NULL && other != NULL))
2249  {
2250  if (op == Py_EQ)
2251  {
2252  Py_RETURN_FALSE;
2253  }
2254  else if (op == Py_NE)
2255  {
2256  Py_RETURN_TRUE;
2257  }
2258  else
2259  {
2260  PyErr_SetString(PyExc_TypeError, "Cannot compare NULL with non-NULL");
2261  return NULL;
2262  }
2263  }
2264  if (!PyObject_IsInstance(other, (PyObject*)&ObjIdType))
2265  {
2266  ostringstream error;
2267  error << "Cannot compare ObjId with "
2268  << Py_TYPE(other)->tp_name;
2269  PyErr_SetString(PyExc_TypeError, error.str().c_str());
2270  return NULL;
2271  }
2272  if (!Id::isValid(((_ObjId*)other)->oid_.id))
2273  {
2274  RAISE_INVALID_ID(NULL, "moose_ObjId_richcompare");
2275  }
2276 
2277  string l_path = self->oid_.path();
2278  string r_path = ((_ObjId*)other)->oid_.path();
2279  int result = l_path.compare(r_path);
2280  if (result == 0)
2281  {
2282  if (op == Py_EQ || op == Py_LE || op == Py_GE)
2283  {
2284  Py_RETURN_TRUE;
2285  }
2286  Py_RETURN_FALSE;
2287  }
2288  else if (result < 0)
2289  {
2290  if (op == Py_LT || op == Py_LE || op == Py_NE)
2291  {
2292  Py_RETURN_TRUE;
2293  }
2294  Py_RETURN_FALSE;
2295  }
2296  else
2297  {
2298  if (op == Py_GT || op == Py_GE || op == Py_NE)
2299  {
2300  Py_RETURN_TRUE;
2301  }
2302  Py_RETURN_FALSE;
2303  }
2304 }
static double op(double x)
Id id
Definition: ObjId.h:98
#define RAISE_INVALID_ID(ret, msg)
Definition: moosemodule.h:71
PyObject_HEAD ObjId oid_
Definition: moosemodule.h:133
static bool isValid(Id id)
Definition: Id.h:145
PyTypeObject ObjIdType
Definition: melement.cpp:2463

+ Here is the call graph for this function:

int moose_ObjId_setattro ( _ObjId self,
PyObject *  attr,
PyObject *  value 
)

Set a specified field. Redone on 2011-03-23 14:41:45 (+0530)

Definition at line 809 of file melement.cpp.

References get_moose_classes(), getFieldType(), Id::id_, Id::isValid(), RAISE_INVALID_ID, Field< A >::set(), shortType(), to_cpp(), and value.

Referenced by moose_ObjId_setField().

810 {
811  if (!Id::isValid(self->oid_.id))
812  {
813  RAISE_INVALID_ID(-1, "moose_ObjId_setattro");
814  }
815  const char * field;
816  if (PyString_Check(attr))
817  {
818  field = PyString_AsString(attr);
819  }
820  else
821  {
822  PyErr_SetString(PyExc_TypeError, "Attribute name must be a string");
823  return -1;
824  }
825  string fieldtype = getFieldType(Field<string>::get(self->oid_, "className"), string(field));
826  if (fieldtype.length() == 0)
827  {
828  // If it is instance of a MOOSE built-in class then throw
829  // error (to avoid silently creating new attributes due to
830  // typos). Otherwise, it must have been subclassed in
831  // Python. Then we allow normal Pythonic behaviour and
832  // consider such mistakes user's responsibility.
833  string className = ((PyTypeObject*)PyObject_Type((PyObject*)self))->tp_name;
834  if (get_moose_classes().find(className) == get_moose_classes().end())
835  {
836  return PyObject_GenericSetAttr((PyObject*)self, PyString_FromString(field), value);
837  }
838  ostringstream msg;
839  msg << "'" << className << "' class has no field '" << field << "'" << endl;
840  PyErr_SetString(PyExc_AttributeError, msg.str().c_str());
841  return -1;
842  }
843  char ftype = shortType(fieldtype);
844  int ret = 0;
845  switch(ftype)
846  {
847  case 'd':
848  {
849  double _value = PyFloat_AsDouble(value);
850  ret = Field<double>::set(self->oid_, string(field), _value);
851  break;
852  }
853  case 'l':
854  {
855  long _value = PyInt_AsLong(value);
856  if ((_value != -1) || (!PyErr_Occurred()))
857  {
858  ret = Field<long>::set(self->oid_, string(field), _value);
859  }
860  break;
861  }
862  case 'I':
863  {
864  unsigned long _value = PyInt_AsUnsignedLongMask(value);
865  ret = Field<unsigned int>::set(self->oid_, string(field), (unsigned int)_value);
866  break;
867  }
868  case 'k':
869  {
870  unsigned long _value = PyInt_AsUnsignedLongMask(value);
871  ret = Field<unsigned long>::set(self->oid_, string(field), _value);
872  break;
873  }
874  case 'f':
875  {
876  float _value = PyFloat_AsDouble(value);
877  ret = Field<float>::set(self->oid_, string(field), _value);
878  break;
879  }
880  case 's':
881  {
882  char * _value = PyString_AsString(value);
883  if (_value)
884  {
885  ret = Field<string>::set(self->oid_, string(field), string(_value));
886  }
887  break;
888  }
889  case 'x': // Id
890  {
891  if (value)
892  {
893  ret = Field<Id>::set(self->oid_, string(field), ((_Id*)value)->id_);
894  }
895  else
896  {
897  PyErr_SetString(PyExc_ValueError, "Null pointer passed as vec Id value.");
898  return -1;
899  }
900  break;
901  }
902  case 'y': // ObjId
903  {
904  if (value)
905  {
906  ret = Field<ObjId>::set(self->oid_, string(field), ((_ObjId*)value)->oid_);
907  }
908  else
909  {
910  PyErr_SetString(PyExc_ValueError, "Null pointer passed as vec Id value.");
911  return -1;
912  }
913  break;
914  }
915  case 'D': //SET_VECFIELD(double, d)
916  {
917  if (!PySequence_Check(value))
918  {
919  PyErr_SetString(PyExc_TypeError, "For setting vector<double> field, specified value must be a sequence." );
920  }
921  else
922  {
923  Py_ssize_t length = PySequence_Length(value);
924  vector<double> _value;
925  for ( int ii = 0; ii < length; ++ii)
926  {
927  PyObject * vo = PySequence_GetItem(value, ii);
928  double v = PyFloat_AsDouble(vo);
929  Py_XDECREF(vo);
930  _value.push_back(v);
931  }
932  ret = Field< vector < double > >::set(self->oid_, string(field), _value);
933  }
934  break;
935  }
936  case 'b':
937  {
938  bool _value = (Py_True == value) || (PyInt_AsLong(value) != 0);
939  ret = Field<bool>::set(self->oid_, string(field), _value);
940  break;
941  }
942  case 'c':
943  {
944  char * _value = PyString_AsString(value);
945  if (_value && _value[0])
946  {
947  ret = Field<char>::set(self->oid_, string(field), _value[0]);
948  }
949  break;
950  }
951  case 'i':
952  {
953  int _value = PyInt_AsLong(value);
954  if ((_value != -1) || (!PyErr_Occurred()))
955  {
956  ret = Field<int>::set(self->oid_, string(field), _value);
957  }
958  break;
959  }
960  case 'h':
961  {
962  short _value = (short)PyInt_AsLong(value);
963  if ((_value != -1) || (!PyErr_Occurred()))
964  {
965  ret = Field<short>::set(self->oid_, string(field), _value);
966  }
967  break;
968  }
969  case 'z': // DataId
970  {
971  PyErr_SetString(PyExc_NotImplementedError, "DataId handling not implemented yet.");
972  return -1;
973  }
974  case 'v':
975  {
976  if (!PySequence_Check(value))
977  {
978  PyErr_SetString(PyExc_TypeError, "For setting vector<int> field, specified value must be a sequence." );
979  }
980  Py_ssize_t length = PySequence_Length(value);
981  vector<int> _value;
982  for ( int ii = 0; ii < length; ++ii)
983  {
984  PyObject * vo = PySequence_GetItem(value, ii);
985  int v = PyInt_AsLong(vo);
986  Py_XDECREF(vo);
987  _value.push_back(v);
988  }
989  ret = Field< vector < int > >::set(self->oid_, string(field), _value);
990  break;
991  }
992  case 'w':
993  {
994  if (!PySequence_Check(value))
995  {
996  PyErr_SetString(PyExc_TypeError, "For setting vector<short> field, specified value must be a sequence." );
997  }
998  else
999  {
1000  Py_ssize_t length = PySequence_Length(value);
1001  vector<short> _value;
1002  for ( int ii = 0; ii < length; ++ii)
1003  {
1004  PyObject * vo = PySequence_GetItem(value, ii);
1005  short v = PyInt_AsLong(vo);
1006  Py_XDECREF(vo);
1007  _value.push_back(v);
1008  }
1009  ret = Field< vector < short > >::set(self->oid_, string(field), _value);
1010  }
1011  break;
1012  }
1013  case 'L': //SET_VECFIELD(long, l)
1014  {
1015  if (!PySequence_Check(value))
1016  {
1017  PyErr_SetString(PyExc_TypeError,
1018  "For setting vector<long> field, specified value must be a sequence." );
1019  }
1020  else
1021  {
1022  Py_ssize_t length = PySequence_Length(value);
1023  vector<long> _value;
1024  for ( int ii = 0; ii < length; ++ii)
1025  {
1026  PyObject * vo = PySequence_GetItem(value, ii);
1027  long v = PyInt_AsLong(vo);
1028  Py_XDECREF(vo);
1029  _value.push_back(v);
1030  }
1031  ret = Field< vector < long > >::set(self->oid_, string(field), _value);
1032  }
1033  break;
1034  }
1035  case 'N': //SET_VECFIELD(unsigned int, I)
1036  {
1037  if (!PySequence_Check(value))
1038  {
1039  PyErr_SetString(PyExc_TypeError, "For setting vector<unsigned int> field, specified value must be a sequence." );
1040  }
1041  else
1042  {
1043  Py_ssize_t length = PySequence_Length(value);
1044  vector<unsigned int> _value;
1045  for ( int ii = 0; ii < length; ++ii)
1046  {
1047  PyObject * vo = PySequence_GetItem(value, ii);
1048  unsigned int v = PyInt_AsUnsignedLongMask(vo);
1049  Py_XDECREF(vo);
1050  _value.push_back(v);
1051  }
1052  ret = Field< vector < unsigned int > >::set(self->oid_, string(field), _value);
1053  }
1054  break;
1055  }
1056  case 'K': //SET_VECFIELD(unsigned long, k)
1057  {
1058  if (!PySequence_Check(value))
1059  {
1060  PyErr_SetString(PyExc_TypeError, "For setting vector<unsigned long> field, specified value must be a sequence." );
1061  }
1062  else
1063  {
1064  Py_ssize_t length = PySequence_Length(value);
1065  vector<unsigned long> _value;
1066  for ( int ii = 0; ii < length; ++ii)
1067  {
1068  PyObject * vo = PySequence_GetItem(value, ii);
1069  unsigned long v = PyInt_AsUnsignedLongMask(vo);
1070  Py_XDECREF(vo);
1071  _value.push_back(v);
1072  }
1073  ret = Field< vector < unsigned long > >::set(self->oid_, string(field), _value);
1074  }
1075  break;
1076  }
1077  case 'F': //SET_VECFIELD(float, f)
1078  {
1079  if (!PySequence_Check(value))
1080  {
1081  PyErr_SetString(PyExc_TypeError, "For setting vector<float> field, specified value must be a sequence." );
1082  }
1083  else
1084  {
1085  Py_ssize_t length = PySequence_Length(value);
1086  vector<float> _value;
1087  for ( int ii = 0; ii < length; ++ii)
1088  {
1089  PyObject * vo = PySequence_GetItem(value, ii);
1090  float v = PyFloat_AsDouble(vo);
1091  Py_XDECREF(vo);
1092  _value.push_back(v);
1093  }
1094  ret = Field< vector < float > >::set(self->oid_, string(field), _value);
1095  }
1096  break;
1097  }
1098  case 'S':
1099  {
1100  if (!PySequence_Check(value))
1101  {
1102  PyErr_SetString(PyExc_TypeError, "For setting vector<string> field, specified value must be a sequence." );
1103  }
1104  else
1105  {
1106  Py_ssize_t length = PySequence_Length(value);
1107  vector<string> _value;
1108  for ( int ii = 0; ii < length; ++ii)
1109  {
1110  PyObject * vo = PySequence_GetItem(value, ii);
1111  char * v = PyString_AsString(vo);
1112  Py_XDECREF(vo);
1113  _value.push_back(string(v));
1114  }
1115  ret = Field< vector < string > >::set(self->oid_, string(field), _value);
1116  }
1117  break;
1118  }
1119  case 'T': // vector< vector<unsigned int> >
1120  {
1121  vector < vector <unsigned> > * _value = (vector < vector <unsigned> > *)to_cpp(value, ftype);
1122  if (!PyErr_Occurred())
1123  {
1124  ret = Field < vector < vector <unsigned> > >::set(self->oid_, string(field), *_value);
1125  }
1126  delete _value;
1127  break;
1128  }
1129  case 'Q': // vector< vector<int> >
1130  {
1131  vector < vector <int> > * _value = (vector < vector <int> > *)to_cpp(value, ftype);
1132  if (!PyErr_Occurred())
1133  {
1134  ret = Field < vector < vector <int> > >::set(self->oid_, string(field), *_value);
1135  }
1136  delete _value;
1137  break;
1138  }
1139  case 'R': // vector< vector<double> >
1140  {
1141  vector < vector <double> > * _value = (vector < vector <double> > *)to_cpp(value, ftype);
1142  if (!PyErr_Occurred())
1143  {
1144  ret = Field < vector < vector <double> > >::set(self->oid_, string(field), *_value);
1145  }
1146  delete _value;
1147  break;
1148  }
1149  case 'X': //SET_VECFIELD(Id, f)
1150  {
1151  if (!PySequence_Check(value))
1152  {
1153  PyErr_SetString(PyExc_TypeError, "For setting vector<Id> field, specified value must be a sequence." );
1154  }
1155  else
1156  {
1157  Py_ssize_t length = PySequence_Length(value);
1158  vector<Id> _value;
1159  for ( int ii = 0; ii < length; ++ii)
1160  {
1161  PyObject * vo = PySequence_GetItem(value, ii);
1162  Id v = ((_Id*)vo)->id_;
1163  Py_XDECREF(vo);
1164  _value.push_back(v);
1165  }
1166  ret = Field< vector < Id > >::set(self->oid_, string(field), _value);
1167  }
1168  break;
1169  }
1170  case 'Y': //SET_VECFIELD(ObjId, f)
1171  {
1172  if (!PySequence_Check(value))
1173  {
1174  PyErr_SetString(PyExc_TypeError, "For setting vector<ObjId> field, specified value must be a sequence." );
1175  }
1176  else
1177  {
1178  Py_ssize_t length = PySequence_Length(value);
1179  vector<ObjId> _value;
1180  for ( int ii = 0; ii < length; ++ii)
1181  {
1182  PyObject * vo = PySequence_GetItem(value, ii);
1183  ObjId v = ((_ObjId*)vo)->oid_;
1184  Py_XDECREF(vo);
1185  _value.push_back(v);
1186  }
1187  ret = Field< vector < ObjId > >::set(self->oid_, string(field), _value);
1188  }
1189  break;
1190  }
1191  default:
1192  break;
1193  }
1194  // MOOSE Field::set returns 1 for success 0 for
1195  // failure. Python treats return value 0 from stters as
1196  // success, anything else failure.
1197  if (ret)
1198  {
1199  return 0;
1200  }
1201  else
1202  {
1203  ostringstream msg;
1204  msg << "Failed to set field '" << field << "'";
1205  PyErr_SetString(PyExc_AttributeError,msg.str().c_str());
1206  return -1;
1207  }
1208 } // moose_ObjId_setattro
char shortType(string)
uint32_t value
Definition: moosemodule.h:42
Definition: SetGet.h:236
map< string, PyTypeObject * > & get_moose_classes()
Id id
Definition: ObjId.h:98
Definition: ObjId.h:20
static bool set(const ObjId &dest, const string &field, A arg)
Definition: SetGet.h:245
#define RAISE_INVALID_ID(ret, msg)
Definition: moosemodule.h:71
PyObject_HEAD ObjId oid_
Definition: moosemodule.h:133
void * to_cpp(PyObject *object, char typecode)
string getFieldType(string className, string fieldName)
static bool isValid(Id id)
Definition: Id.h:145
Definition: Id.h:17
unsigned int id_
Definition: Id.h:172

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

PyObject* moose_ObjId_setDestField ( _ObjId self,
PyObject *  args 
)

Definition at line 1634 of file melement.cpp.

References moose::error, Id::isValid(), maxArgs, minArgs, parseFinfoType(), RAISE_INVALID_ID, SetGet0::set(), setDestFinfo(), setDestFinfo2(), and shortType().

Referenced by moose_DestField_call().

1635 {
1636  if (!Id::isValid(self->oid_.id))
1637  {
1638  RAISE_INVALID_ID(NULL, "moose_ObjId_setDestField");
1639  }
1640  PyObject * arglist[10] = {NULL, NULL, NULL, NULL, NULL,
1641  NULL, NULL, NULL, NULL, NULL
1642  };
1643  ostringstream error;
1644  ObjId oid = ((_ObjId*)self)->oid_;
1645 
1646  error << "moose.setDestField: ";
1647  // Unpack the arguments
1648  if (!PyArg_UnpackTuple(args, "setDestField", minArgs, maxArgs,
1649  &arglist[0], &arglist[1], &arglist[2],
1650  &arglist[3], &arglist[4], &arglist[5],
1651  &arglist[6], &arglist[7], &arglist[8],
1652  &arglist[9]))
1653  {
1654  error << "At most " << maxArgs - 1 << " arguments can be handled.";
1655  PyErr_SetString(PyExc_ValueError, error.str().c_str());
1656  return NULL;
1657  }
1658 
1659  // Get the destFinfo name
1660  char * fieldName = PyString_AsString(arglist[0]);
1661  if (!fieldName) // not a string, raises TypeError
1662  {
1663  error << "first argument must be a string specifying field name.";
1664  PyErr_SetString(PyExc_TypeError, error.str().c_str());
1665  return NULL;
1666  }
1667 
1668  // Try to parse the arguments.
1669  vector< string > argType;
1670  if (parseFinfoType(Field<string>::get(oid, "className"),
1671  "destFinfo", string(fieldName), argType) < 0)
1672  {
1673  error << "Arguments not handled: " << fieldName << "(";
1674  for (unsigned int ii = 0; ii < argType.size(); ++ii)
1675  {
1676  error << argType[ii] << ",";
1677  }
1678  error << ")";
1679  PyErr_SetString(PyExc_TypeError, error.str().c_str());
1680  return NULL;
1681  }
1682  if (argType.size() == 1)
1683  {
1684  if ( arglist[1] == NULL && argType[0] == "void")
1685  {
1686  bool ret = SetGet0::set(oid, string(fieldName));
1687  if (ret)
1688  {
1689  Py_RETURN_TRUE;
1690  }
1691  else
1692  {
1693  Py_RETURN_FALSE;
1694  }
1695  }
1696  return setDestFinfo(oid, string(fieldName), arglist[1], argType[0]);
1697  }
1698  else if (argType.size() == 2)
1699  {
1700  return setDestFinfo2(oid, string(fieldName), arglist[1], shortType(argType[0]), arglist[2], shortType(argType[1]));
1701  }
1702  else
1703  {
1704  error << "Can handle only up to 2 arguments" << endl;
1705  return NULL;
1706  }
1707 } // moose_ObjId_setDestField
char shortType(string)
#define minArgs
Definition: moosemodule.h:84
Definition: SetGet.h:236
Id id
Definition: ObjId.h:98
Definition: ObjId.h:20
#define RAISE_INVALID_ID(ret, msg)
Definition: moosemodule.h:71
PyObject_HEAD ObjId oid_
Definition: moosemodule.h:133
PyObject * setDestFinfo2(ObjId obj, string fieldName, PyObject *arg1, char type1, PyObject *arg2, char type2)
Definition: melement.cpp:1886
static bool isValid(Id id)
Definition: Id.h:145
int parseFinfoType(string className, string finfoType, string fieldName, vector< string > &typeVec)
static bool set(const ObjId &dest, const string &field)
Definition: SetGet.h:103
#define maxArgs
Definition: moosemodule.h:88
PyObject * setDestFinfo(ObjId obj, string fieldName, PyObject *arg, string argType)
Definition: melement.cpp:1709

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

PyObject* moose_ObjId_setField ( _ObjId self,
PyObject *  args 
)

Definition at line 791 of file melement.cpp.

References moose_ObjId_setattro(), and value.

792 {
793  PyObject * field;
794  PyObject * value;
795  if (!PyArg_ParseTuple(args, "OO:moose_ObjId_setField", &field, &value))
796  {
797  return NULL;
798  }
799  if (moose_ObjId_setattro(self, field, value) == -1)
800  {
801  return NULL;
802  }
803  Py_RETURN_NONE;
804 }
uint32_t value
Definition: moosemodule.h:42
int moose_ObjId_setattro(_ObjId *self, PyObject *attr, PyObject *value)
Definition: melement.cpp:809

+ Here is the call graph for this function:

PyObject* moose_ObjId_setLookupField ( _ObjId self,
PyObject *  args 
)

Definition at line 1600 of file melement.cpp.

References Id::isValid(), setLookupField(), and value.

1601 {
1602  if (!Id::isValid(self->oid_.id))
1603  {
1604  return NULL;
1605  }
1606  PyObject * key;
1607  PyObject * value;
1608  char * field;
1609  if (!PyArg_ParseTuple(args, "sOO:moose_ObjId_setLookupField", &field, &key, &value))
1610  {
1611  return NULL;
1612  }
1613  if ( setLookupField(self->oid_, field, key, value) == 0)
1614  {
1615  Py_RETURN_NONE;
1616  }
1617  return NULL;
1618 }// moose_ObjId_setLookupField
uint32_t value
Definition: moosemodule.h:42
Id id
Definition: ObjId.h:98
PyObject_HEAD ObjId oid_
Definition: moosemodule.h:133
int setLookupField(ObjId target, char *fieldName, PyObject *key, PyObject *value)
Definition: melement.cpp:1480
static bool isValid(Id id)
Definition: Id.h:145

+ Here is the call graph for this function:

PyObject* moose_quit ( PyObject *  dummy)

This should not be required or accessible to the user. Put here for debugging threading issue.

Definition at line 2450 of file moosemodule.cpp.

References finalize().

2451 {
2452  finalize();
2453  cout << "Quitting MOOSE." << endl;
2454  Py_RETURN_NONE;
2455 }
void finalize()
create_shell()

+ Here is the call graph for this function:

PyObject* moose_reinit ( PyObject *  dummy,
PyObject *  args 
)

Definition at line 1749 of file moosemodule.cpp.

References SHELLPTR.

1750 {
1751  SHELLPTR->doReinit();
1752  Py_RETURN_NONE;
1753 }
#define SHELLPTR
Definition: moosemodule.h:105
PyObject* moose_seed ( PyObject *  dummy,
PyObject *  args 
)

Definition at line 2339 of file moosemodule.cpp.

References pymoose_mtseed_().

2340 {
2341  long int seed = 0;
2342  if (!PyArg_ParseTuple(args, "|l", &seed))
2343  {
2344  return NULL;
2345  }
2346  pymoose_mtseed_(seed);
2347  Py_RETURN_NONE;
2348 }
void pymoose_mtseed_(long int seed)

+ Here is the call graph for this function:

PyObject* moose_setClock ( PyObject *  dummy,
PyObject *  args 
)

Definition at line 1656 of file moosemodule.cpp.

References SHELLPTR.

1657 {
1658  unsigned int tick;
1659  double dt;
1660  if(!PyArg_ParseTuple(args, "Id:moose_setClock", &tick, &dt))
1661  {
1662  return NULL;
1663  }
1664  if (dt < 0)
1665  {
1666  PyErr_SetString(PyExc_ValueError, "dt must be positive.");
1667  return NULL;
1668  }
1669  SHELLPTR->doSetClock(tick, dt);
1670  Py_RETURN_NONE;
1671 }
#define SHELLPTR
Definition: moosemodule.h:105
PyObject* moose_setCwe ( PyObject *  dummy,
PyObject *  args 
)

Definition at line 1879 of file moosemodule.cpp.

References ObjId::bad(), IdType, ObjIdType, path, RAISE_INVALID_ID, and SHELLPTR.

1880 {
1881  PyObject * element = NULL;
1882  char * path = NULL;
1883  ObjId oid;
1884  if (PyTuple_Size(args) == 0)
1885  {
1886  oid = Id("/");
1887  }
1888  else if(PyArg_ParseTuple(args, "s:moose_setCwe", &path))
1889  {
1890  oid = ObjId(string(path));
1891  }
1892  else if (PyArg_ParseTuple(args, "O:moose_setCwe", &element))
1893  {
1894  PyErr_Clear();
1895  if (PyObject_IsInstance(element, (PyObject*)&IdType))
1896  {
1897  oid = (reinterpret_cast<_Id*>(element))->id_;
1898  }
1899  else if (PyObject_IsInstance(element, (PyObject*)&ObjIdType))
1900  {
1901  oid = (reinterpret_cast<_ObjId*>(element))->oid_;
1902  }
1903  else
1904  {
1905  PyErr_SetString(PyExc_NameError, "setCwe: Argument must be an vec or element");
1906  return NULL;
1907  }
1908  }
1909  else
1910  {
1911  return NULL;
1912  }
1913  if (oid.bad())
1914  {
1915  RAISE_INVALID_ID(NULL, "moose_setCwe");
1916  }
1917  SHELLPTR->setCwe(oid);
1918  Py_RETURN_NONE;
1919 }
#define SHELLPTR
Definition: moosemodule.h:105
bool bad() const
Definition: ObjId.cpp:18
Definition: ObjId.h:20
#define RAISE_INVALID_ID(ret, msg)
Definition: moosemodule.h:71
PyTypeObject ObjIdType
Definition: Id.h:17
PyTypeObject IdType
Definition: vec.cpp:262
static char path[]
Definition: mfield.cpp:403

+ Here is the call graph for this function:

PyObject* moose_start ( PyObject *  dummy,
PyObject *  args 
)

Definition at line 1703 of file moosemodule.cpp.

References handle_keyboard_interrupts(), and SHELLPTR.

1704 {
1705  double runtime = 0.0;
1706  bool notify = false;
1707 
1708  PyArg_ParseTuple(args, "d|I:moose_start", &runtime, &notify);
1709 
1710  if (runtime <= 0.0)
1711  {
1712  PyErr_SetString(PyExc_ValueError, "simulation runtime must be positive.");
1713  return NULL;
1714  }
1715 
1716  // This is from http://stackoverflow.com/questions/1641182/how-can-i-catch-a-ctrl-c-event-c
1717  struct sigaction sigHandler;
1718  sigHandler.sa_handler = handle_keyboard_interrupts;
1719  sigemptyset(&sigHandler.sa_mask);
1720  sigHandler.sa_flags = 0;
1721  sigaction(SIGINT, &sigHandler, NULL);
1722 
1723 #if 0
1724  // NOTE: (dilawar) Does not know if Py_BEGIN_ALLOW_THREADS is
1725  // neccessary.
1726  // Py_BEGIN_ALLOW_THREADS
1727  SHELLPTR->doStart(runtime);
1728  // Py_END_ALLOW_THREADS
1729  Py_RETURN_NONE;
1730 #endif
1731  SHELLPTR->doStart( runtime, notify );
1732  Py_RETURN_NONE;
1733 
1734 }
#define SHELLPTR
Definition: moosemodule.h:105
void handle_keyboard_interrupts(int signum)
Handle signal raised by user during simulation.

+ Here is the call graph for this function:

PyObject* moose_stop ( PyObject *  dummy,
PyObject *  args 
)

Definition at line 1754 of file moosemodule.cpp.

References SHELLPTR.

1755 {
1756  SHELLPTR->doStop();
1757  Py_RETURN_NONE;
1758 }
#define SHELLPTR
Definition: moosemodule.h:105
PyObject* moose_syncDataHandler ( PyObject *  dummy,
PyObject *  target 
)
PyObject* moose_useClock ( PyObject *  dummy,
PyObject *  args 
)

Definition at line 1629 of file moosemodule.cpp.

References path, and SHELLPTR.

1630 {
1631  char * path, * field;
1632  unsigned int tick;
1633  if(!PyArg_ParseTuple(args, "Iss:moose_useClock", &tick, &path, &field))
1634  {
1635  return NULL;
1636  }
1637  SHELLPTR->doUseClock(string(path), string(field), tick);
1638  Py_RETURN_NONE;
1639 }
#define SHELLPTR
Definition: moosemodule.h:105
static char path[]
Definition: mfield.cpp:403
PyObject* moose_wildcardFind ( PyObject *  dummy,
PyObject *  args 
)

Definition at line 2412 of file moosemodule.cpp.

References oid_to_element(), and wildcardFind().

2413 {
2414  vector <ObjId> objects;
2415  char * wildcard_path = NULL;
2416  if (!PyArg_ParseTuple(args, "s:moose.wildcardFind", &wildcard_path))
2417  {
2418  return NULL;
2419  }
2420  wildcardFind(string(wildcard_path), objects);
2421  PyObject * ret = PyTuple_New(objects.size());
2422  if (ret == NULL)
2423  {
2424  PyErr_SetString(PyExc_RuntimeError, "moose.wildcardFind: failed to allocate new tuple.");
2425  return NULL;
2426  }
2427 
2428  for (unsigned int ii = 0; ii < objects.size(); ++ii)
2429  {
2430  PyObject * entry = oid_to_element(objects[ii]);
2431  if (!entry)
2432  {
2433  Py_XDECREF(ret);
2434  PyErr_SetString(PyExc_RuntimeError, "moose.wildcardFind: failed to allocate new vec.");
2435  return NULL;
2436  }
2437  if (PyTuple_SetItem(ret, (Py_ssize_t)ii, entry))
2438  {
2439  Py_XDECREF(entry);
2440  Py_XDECREF(ret);
2441  return NULL;
2442  }
2443  }
2444  return ret;
2445 }
int wildcardFind(const string &path, vector< ObjId > &ret)
Definition: Wildcard.cpp:169
PyObject * oid_to_element(ObjId oid)

+ Here is the call graph for this function:

PyObject* oid_to_element ( ObjId  oid)

Definition at line 2899 of file moosemodule.cpp.

References Field< A >::get(), get_moose_classes(), and _ObjId::oid_.

Referenced by moose_connect(), moose_element(), moose_ElementField_getItem(), moose_ElementField_getSlice(), moose_getCwe(), moose_Id_fillSlice(), moose_Id_getItem(), and moose_wildcardFind().

2900 {
2901  string classname = Field<string>::get(oid, "className");
2902  map<string, PyTypeObject *>::iterator it = get_moose_classes().find(classname);
2903  if (it == get_moose_classes().end())
2904  {
2905  return NULL;
2906  }
2907  PyTypeObject * pyclass = it->second;
2908  _ObjId * new_obj = PyObject_New(_ObjId, pyclass);
2909  new_obj->oid_ = oid;
2910  // Py_XINCREF(new_obj); // why? PyObject_New initializes refcnt to 1
2911  return (PyObject*)new_obj;
2912 }
map< string, PyTypeObject * > & get_moose_classes()
PyObject_HEAD ObjId oid_
Definition: moosemodule.h:133
static A get(const ObjId &dest, const string &field)
Definition: SetGet.h:284

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int parseFinfoType ( string  className,
string  finfoType,
string  fieldName,
vector< string > &  typeVec 
)
vector<int> pysequence_to_dimvec ( PyObject *  dims)

Utility function to convert an Python integer or a sequence object into a vector of dimensions

Definition at line 178 of file moosemodule.cpp.

179 {
180  vector <int> vec_dims;
181  Py_ssize_t num_dims = 1;
182  long dim_value = 1;
183  if (dims)
184  {
185  // First try to use it as a tuple of dimensions
186  if (PyTuple_Check(dims))
187  {
188  num_dims = PyTuple_Size(dims);
189  for (Py_ssize_t ii = 0; ii < num_dims; ++ ii)
190  {
191  PyObject* dim = PyTuple_GetItem(dims, ii);
192  dim_value = PyInt_AsLong(dim);
193  if ((dim_value == -1) && PyErr_Occurred())
194  {
195  return vec_dims;
196  }
197  vec_dims.push_back((unsigned int)dim_value);
198  }
199  }
200  else if (PyInt_Check(dims)) // 1D array
201  {
202  dim_value = PyInt_AsLong(dims);
203  if (dim_value <= 0)
204  {
205  dim_value = 1;
206  }
207  vec_dims.push_back(dim_value);
208  }
209  }
210  else
211  {
212  vec_dims.push_back(dim_value);
213  }
214  return vec_dims;
215 }
template<typename T >
vector< T >* PySequenceToVector ( PyObject *  seq,
char  typecode 
)

Convert a Python sequence into a C++ vector. This dynamically allocates the vector and it is the caller's responsibility to free it.

Definition at line 309 of file moosemodule.h.

References moose::error, to_cpp(), and value.

310 {
311  Py_ssize_t length = PySequence_Length(seq);
312  vector <T> * ret = new vector<T>((unsigned int)length);
313  T * value;
314  for (unsigned int ii = 0; ii < length; ++ii)
315  {
316  PyObject * item = PySequence_GetItem(seq, ii);
317  if (item == NULL)
318  {
319  ostringstream error;
320  error << "Item # " << ii << "is NULL";
321  PyErr_SetString(PyExc_ValueError, error.str().c_str());
322  delete ret;
323  return NULL;
324  }
325  value = (T*)to_cpp(item, typecode);
326  Py_DECREF(item); // PySequence_GetItem returns a new reference. Reduce the refcount now.
327  if (value == NULL)
328  {
329  ostringstream error;
330  error << "Cannot handle sequence of type " << Py_TYPE(item)->tp_name;
331  PyErr_SetString(PyExc_TypeError, error.str().c_str());
332  delete ret;
333  return NULL;
334  }
335  ret->at(ii) = *value;
336  delete value;
337  }
338  return ret;
339 }
uint32_t value
Definition: moosemodule.h:42
void * to_cpp(PyObject *object, char typecode)

+ Here is the call graph for this function:

template<typename T >
vector< vector < T > >* PySequenceToVectorOfVectors ( PyObject *  seq,
char  typecode 
)

Definition at line 342 of file moosemodule.h.

References moose::error.

343 {
344  Py_ssize_t outerLength = PySequence_Length(seq);
345  vector < vector <T> > * ret = new vector < vector < T > >((unsigned int) outerLength);
346  for (unsigned int ii = 0; ii < outerLength; ++ii)
347  {
348  PyObject * innerSeq = PySequence_GetItem(seq, ii);
349  if (innerSeq == NULL)
350  {
351  ostringstream error;
352  error << "PySequenceToVectorOfVectors: error converting inner sequence " << ii;
353  PyErr_SetString(PyExc_ValueError, error.str().c_str());
354  delete ret;
355  return NULL;
356  }
357  vector< T > * inner = PySequenceToVector< T >(innerSeq, typecode);
358  Py_DECREF(innerSeq);
359  if (inner == NULL)
360  {
361  delete ret;
362  return NULL;
363  }
364  ret->at(ii).assign(inner->begin(), inner->end());
365  delete inner;
366  }
367  return ret;
368 }
template<class KeyType >
int set_lookup_value ( const ObjId oid,
string  fname,
char  value_type_code,
char  key_type_code,
PyObject *  key,
PyObject *  value_obj 
)

Definition at line 486 of file moosemodule.h.

References SET_LOOKUP_VALUE, and to_cpp().

487 {
488  bool success = false;
489  KeyType *cpp_key = (KeyType*)to_cpp(key, key_type_code);
490  if (cpp_key == NULL)
491  {
492  return -1;
493  }
494 #define SET_LOOKUP_VALUE( TYPE ) \
495  { \
496  TYPE * value = (TYPE*)to_cpp(value_obj, value_type_code); \
497  if (value){ \
498  success = LookupField < KeyType, TYPE > ::set(oid, fname, *cpp_key, *value); \
499  delete value; \
500  delete cpp_key; \
501  } \
502  break; \
503  }
504 
505  switch (value_type_code)
506  {
507  case 'b':
508  SET_LOOKUP_VALUE(bool)
509  case 'c':
510  SET_LOOKUP_VALUE(char)
511  case 'h':
512  SET_LOOKUP_VALUE(short)
513  case 'H':
514  SET_LOOKUP_VALUE(unsigned short)
515  case 'i':
516  SET_LOOKUP_VALUE(int)
517  case 'I':
518  SET_LOOKUP_VALUE(unsigned int)
519  case 'l':
520  SET_LOOKUP_VALUE(long)
521  case 'k':
522  SET_LOOKUP_VALUE(unsigned long)
523 #ifdef HAVE_LONG_LONG
524  case 'L':
525  SET_LOOKUP_VALUE(long long)
526  case 'K':
527  SET_LOOKUP_VALUE(unsigned long long);
528 #endif
529  case 'd':
530  SET_LOOKUP_VALUE(double)
531  case 'f':
532  SET_LOOKUP_VALUE(float)
533  case 's':
534  SET_LOOKUP_VALUE(string)
535  case 'x':
537  case 'y':
539  case 'D':
540  SET_LOOKUP_VALUE( vector <double> )
541  case 'S':
542  SET_LOOKUP_VALUE( vector <string> )
543  case 'X':
544  SET_LOOKUP_VALUE( vector <Id> )
545  case 'Y':
546  SET_LOOKUP_VALUE( vector <ObjId> )
547  case 'v':
548  SET_LOOKUP_VALUE( vector <int> )
549  case 'M':
550  SET_LOOKUP_VALUE( vector <long> )
551  case 'N':
552  SET_LOOKUP_VALUE( vector <unsigned int> )
553  case 'P':
554  SET_LOOKUP_VALUE( vector <unsigned long> )
555  case 'F':
556  SET_LOOKUP_VALUE( vector <float> )
557  case 'w':
558  SET_LOOKUP_VALUE( vector <short> )
559  case 'C':
560  SET_LOOKUP_VALUE( vector <char> )
561  default:
562  ostringstream err;
563  err << "Value type " << value_type_code << " not supported yet.";
564  PyErr_SetString(PyExc_TypeError, err.str().c_str());
565  }
566  if (success)
567  {
568  return 0;
569  }
570  else
571  {
572  return -1;
573  }
574 }
Definition: ObjId.h:20
void * to_cpp(PyObject *object, char typecode)
Definition: Id.h:17
#define SET_LOOKUP_VALUE(TYPE)

+ Here is the call graph for this function:

PyObject* setDestFinfo ( ObjId  obj,
string  fieldName,
PyObject *  arg,
string  argType 
)
template<class A >
PyObject* setDestFinfo1 ( ObjId  obj,
string  fieldName,
PyObject *  arg1,
char  type1,
arg2 
)

Set destFinfo for 2 argument destination field functions.

Definition at line 607 of file moosemodule.h.

References moose::error, Id::id_, _ObjId::oid_, and SetGet2< A1, A2 >::set().

608 {
609  bool ret;
610  ostringstream error;
611  error << "moose.setDestFinfo1: ";
612  switch (type1)
613  {
614  case 'f':
615  case 'd':
616  {
617  double param = PyFloat_AsDouble(arg1);
618  if (type1 == 'f')
619  {
620  ret = SetGet2<float, A>::set(obj, fieldName, (float)param, arg2);
621  }
622  else
623  {
624  ret = SetGet2<double, A>::set(obj, fieldName, param, arg2);
625  }
626  }
627  break;
628  case 's':
629  {
630  char * param = PyString_AsString(arg1);
631  ret = SetGet2<string, A>::set(obj, fieldName, string(param), arg2);
632  }
633  break;
634  case 'i':
635  case 'l':
636  {
637  long param = PyInt_AsLong(arg1);
638  if (param == -1 && PyErr_Occurred())
639  {
640  return NULL;
641  }
642  if (type1 == 'i')
643  {
644  ret = SetGet2<int, A>::set(obj, fieldName, (int)param, arg2);
645  }
646  else
647  {
648  ret = SetGet2<long, A>::set(obj, fieldName, param, arg2);
649  }
650  }
651  break;
652  case 'I':
653  case 'k':
654  {
655  unsigned long param =PyLong_AsUnsignedLong(arg1);
656  if (PyErr_Occurred())
657  {
658  return NULL;
659  }
660  if (type1 == 'I')
661  {
662  ret = SetGet2< unsigned int, A>::set(obj, fieldName, (unsigned int)param, arg2);
663  }
664  else
665  {
666  ret = SetGet2<unsigned long, A>::set(obj, fieldName, param, arg2);
667  }
668  }
669  break;
670  case 'x':
671  {
672  Id param;
673  // if (Id_SubtypeCheck(arg1)){
674  _Id * id = (_Id*)(arg1);
675  if (id == NULL)
676  {
677  error << "argument should be an vec or an melement";
678  PyErr_SetString(PyExc_TypeError, error.str().c_str());
679  return NULL;
680  }
681  param = id->id_;
682  // } else if (ObjId_SubtypeCheck(arg)){
683  // _ObjId * oid = (_ObjId*)(arg);
684  // if (oid == NULL){
685  // error << "argument should be an vec or an melement";
686  // PyErr_SetString(PyExc_TypeError, error.str().c_str());
687  // return NULL;
688  // }
689  // param = oid->oid_.id;
690  // }
691  ret = SetGet2<Id, A>::set(obj, fieldName, param, arg2);
692  }
693  break;
694  case 'y':
695  {
696  ObjId param;
697  // if (Id_SubtypeCheck(arg)){
698  // _Id * id = (_Id*)(arg);
699  // if (id == NULL){
700  // error << "argument should be an vec or an melement";
701  // PyErr_SetString(PyExc_TypeError, error.str().c_str());
702  // return NULL;
703  // }
704  // param = ObjId(id->id_);
705  // } else if (ObjId_SubtypeCheck(arg)){
706  _ObjId * oid = (_ObjId*)(arg1);
707  if (oid == NULL)
708  {
709  error << "argument should be an vec or an melement";
710  PyErr_SetString(PyExc_TypeError, error.str().c_str());
711  return NULL;
712  }
713  param = oid->oid_;
714  // }
715  ret = SetGet2<ObjId, A>::set(obj, fieldName, param, arg2);
716  }
717  break;
718  case 'c':
719  {
720  char * param = PyString_AsString(arg1);
721  if (!param)
722  {
723  error << "expected argument of type char/string";
724  PyErr_SetString(PyExc_TypeError, error.str().c_str());
725  return NULL;
726  }
727  else if (strlen(param) == 0)
728  {
729  error << "Empty string not allowed.";
730  PyErr_SetString(PyExc_ValueError, error.str().c_str());
731  return NULL;
732  }
733  ret = SetGet2<char, A>::set(obj, fieldName, param[0], arg2);
734  }
735  default:
736  {
737  error << "Unhandled argument 1 type (shortType=" << type1 << ")";
738  PyErr_SetString(PyExc_TypeError, error.str().c_str());
739  return NULL;
740  }
741  }
742  if (ret)
743  {
744  Py_RETURN_TRUE;
745  }
746  else
747  {
748  Py_RETURN_FALSE;
749  }
750 }
Definition: ObjId.h:20
PyObject_HEAD ObjId oid_
Definition: moosemodule.h:133
Definition: Id.h:17
unsigned int id_
Definition: Id.h:172
static bool set(const ObjId &dest, const string &field, A1 arg1, A2 arg2)
Definition: SetGet.h:365

+ Here is the call graph for this function:

PyObject* setDestFinfo2 ( ObjId  obj,
string  fieldName,
PyObject *  arg1,
char  type1,
PyObject *  arg2,
char  type2 
)
int setLookupField ( ObjId  oid,
char *  fieldName,
PyObject *  key,
PyObject *  value 
)

Definition at line 1480 of file melement.cpp.

References moose::error, Field< A >::get(), parseFinfoType(), shortType(), and value.

Referenced by moose_LookupField_setItem(), and moose_ObjId_setLookupField().

1481 {
1482  vector<string> type_vec;
1483  if (parseFinfoType(Field<string>::get(target, "className"), "lookupFinfo", string(fieldName), type_vec) < 0)
1484  {
1485  ostringstream error;
1486  error << "Cannot handle key type for LookupField `" << Field<string>::get(target, "className") << "." << fieldName << "`.";
1487  PyErr_SetString(PyExc_TypeError, error.str().c_str());
1488  return -1;
1489  }
1490  if (type_vec.size() != 2)
1491  {
1492  ostringstream error;
1493  error << "LookupField type signature should be <keytype>, <valuetype>. But for `"
1494  << Field<string>::get(target, "className") << "." << fieldName << "` got " << type_vec.size() << " components." ;
1495  PyErr_SetString(PyExc_AssertionError, error.str().c_str());
1496  return -1;
1497  }
1498  char key_type_code = shortType(type_vec[0]);
1499  char value_type_code = shortType(type_vec[1]);
1500  int ret = -1;
1501  switch(key_type_code)
1502  {
1503  case 'I':
1504  {
1505  ret = set_lookup_value <unsigned int> (target, string(fieldName), value_type_code, key_type_code, key, value);
1506  break;
1507  }
1508  case 'k':
1509  {
1510  ret = set_lookup_value <unsigned long> (target, string(fieldName), value_type_code, key_type_code, key, value);
1511  break;
1512  }
1513  case 's':
1514  {
1515  ret = set_lookup_value <string> (target, string(fieldName), value_type_code, key_type_code, key, value);
1516  break;
1517  }
1518  case 'i':
1519  {
1520  ret = set_lookup_value <int> (target, string(fieldName), value_type_code, key_type_code, key, value);
1521  break;
1522  }
1523  case 'l':
1524  {
1525  ret = set_lookup_value <long> (target, string(fieldName), value_type_code, key_type_code, key, value);
1526  break;
1527  }
1528  case 'L':
1529  {
1530  ret = set_lookup_value <long long> (target, string(fieldName), value_type_code, key_type_code, key, value);
1531  break;
1532  }
1533  case 'K':
1534  {
1535  ret = set_lookup_value <unsigned long long> (target, string(fieldName), value_type_code, key_type_code, key, value);
1536  break;
1537  }
1538  case 'b':
1539  {
1540  ret = set_lookup_value <bool> (target, string(fieldName), value_type_code, key_type_code, key, value);
1541  break;
1542  }
1543  case 'c':
1544  {
1545  ret = set_lookup_value <char> (target, string(fieldName), value_type_code, key_type_code, key, value);
1546  break;
1547  }
1548  case 'h':
1549  {
1550  ret = set_lookup_value <short> (target, string(fieldName), value_type_code, key_type_code, key, value);
1551  break;
1552  }
1553  case 'H':
1554  {
1555  ret = set_lookup_value <unsigned short> (target, string(fieldName), value_type_code, key_type_code, key, value);
1556  break;
1557  }
1558  case 'd':
1559  {
1560  ret = set_lookup_value <double> (target, string(fieldName), value_type_code, key_type_code, key, value);
1561  break;
1562  }
1563  case 'f':
1564  {
1565  ret = set_lookup_value <float> (target, string(fieldName), value_type_code, key_type_code, key, value);
1566  break;
1567  }
1568  case 'x':
1569  {
1570  ret = set_lookup_value <Id> (target, string(fieldName), value_type_code, key_type_code, key, value);
1571  break;
1572  }
1573  case 'y':
1574  {
1575  ret = set_lookup_value <ObjId> (target, string(fieldName), value_type_code, key_type_code, key, value);
1576  break;
1577  }
1578  default:
1579  ostringstream error;
1580  error << "setLookupField: invalid key type " << type_vec[0];
1581  PyErr_SetString(PyExc_TypeError, error.str().c_str());
1582  }
1583  return ret;
1584 }// setLookupField
char shortType(string)
uint32_t value
Definition: moosemodule.h:42
Definition: SetGet.h:236
int parseFinfoType(string className, string finfoType, string fieldName, vector< string > &typeVec)
static A get(const ObjId &dest, const string &field)
Definition: SetGet.h:284

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

char shortType ( string  )

Referenced by getLookupField(), moose_ElementField_getattro(), moose_ElementField_setattro(), moose_Id_getattro(), moose_Id_setattro(), moose_ObjId_getattro(), moose_ObjId_setattro(), moose_ObjId_setDestField(), parseFinfoType(), setDestFinfo(), and setLookupField().

+ Here is the caller graph for this function:

void* to_cpp ( PyObject *  object,
char  typecode 
)

Convert PyObject to C++ object. Returns a pointer to the converted object. Deallocation is caller responsibility

Convert Python object into C++ data structure. The data structure is allocated here and it is the responsibility of the caller to free that memory.

Definition at line 222 of file moosemodule.cpp.

References _Id::id_, _ObjId::oid_, and value.

Referenced by _set_vector_destFinfo(), lookup_value(), moose_ObjId_setattro(), PySequenceToVector(), and set_lookup_value().

223 {
224  switch(typecode)
225  {
226  case 'i':
227  {
228  int * ret = new int();
229  * ret = PyInt_AsLong(object);
230  return (void*)ret;
231  }
232  case 'l':
233  {
234  long v = PyInt_AsLong(object);
235  long * ret = new long();
236  *ret = v;
237  return (void*)ret;
238  }
239  case 'h':
240  {
241  short v = PyInt_AsLong(object);
242  short * ret = new short();
243  *ret = v;
244  return (void*)ret;
245  }
246  case 'f':
247  {
248  float v = (float)PyFloat_AsDouble(object);
249  if ( v == -1.0 && PyErr_Occurred())
250  {
251  PyErr_SetString(PyExc_TypeError, "Expected a sequence of floating point numbers.");
252  }
253  else
254  {
255  float * ret = new float();
256  *ret = v;
257  return (void*)ret;
258  }
259  }
260  case 'd':
261  {
262  double v = PyFloat_AsDouble(object);
263  if ( v == -1.0 && PyErr_Occurred())
264  {
265  PyErr_SetString(PyExc_TypeError, "Expected a sequence of floating point numbers.");
266  }
267  else
268  {
269  double * ret = new double();
270  *ret = v;
271  return (void*)ret;
272  }
273  }
274  case 's':
275  {
276  char* tmp = PyString_AsString(object);
277  if (tmp == NULL)
278  {
279  return NULL;
280  }
281  string * ret = new string(tmp);
282  return (void*)ret;
283  }
284  case 'I':
285  {
286  unsigned int v = PyInt_AsUnsignedLongMask(object);
287  unsigned int * ret = new unsigned int();
288  *ret = v;
289  return (void*)ret;
290  }
291  case 'k':
292  {
293  unsigned long v = PyInt_AsUnsignedLongMask(object);
294  unsigned long * ret = new unsigned long();
295  *ret = v;
296  return (void*)ret;
297  }
298  case 'x':
299  {
300  _Id * value = (_Id*)object;
301  if (value != NULL)
302  {
303  Id * ret = new Id();
304  * ret = value->id_;
305  return (void*)ret;
306  }
307  }
308  case 'y':
309  {
310  _ObjId * value = (_ObjId*)object;
311  if (value != NULL)
312  {
313  ObjId * ret = new ObjId();
314  * ret = value->oid_;
315  return (void*)ret;
316  }
317  }
318  case 'v':
319  return PySequenceToVector< int >(object, 'i');
320  case 'N':
321  return PySequenceToVector < unsigned int > (object, 'I');
322  case 'w':
323  return PySequenceToVector < short > (object, 'h');
324  case 'M':
325  return PySequenceToVector < long > (object, 'l');
326  case 'P':
327  return PySequenceToVector < unsigned long > (object, 'k');
328  case 'F':
329  return PySequenceToVector < float > (object, 'f');
330  case 'D':
331  return PySequenceToVector < double > (object, 'd');
332  case 'S':
333  return PySequenceToVector < string > (object, 's');
334  case 'Y':
335  return PySequenceToVector < ObjId > (object, 'y');
336  case 'X':
337  return PySequenceToVector < Id > (object, 'x');
338  case 'R':
339  return PySequenceToVectorOfVectors< double >(object, 'd');
340  case 'Q':
341  return PySequenceToVectorOfVectors< int >(object, 'i');
342  case 'T':
343  return PySequenceToVectorOfVectors< unsigned int > (object, 'I');
344  }
345  return NULL;
346 }
PyObject_HEAD Id id_
Definition: moosemodule.h:114
uint32_t value
Definition: moosemodule.h:42
Definition: ObjId.h:20
PyObject_HEAD ObjId oid_
Definition: moosemodule.h:133
Definition: Id.h:17

+ Here is the caller graph for this function:

PyObject* to_py ( void *  obj,
char  typecode 
)

Convert C++ object to Python.

Utility function to convert C++ object into Python object.

Definition at line 352 of file moosemodule.cpp.

References id, IdType, innerType(), ObjIdType, _ObjId::oid_, and to_pytuple().

Referenced by convert_and_set_tuple_entry(), get_simple_lookupfield(), moose_ObjId_getattro(), and test_to_py().

353 {
354  switch(typecode)
355  {
356  case 'd':
357  {
358  double * ptr = static_cast<double *>(obj);
359  assert(ptr != NULL);
360  return PyFloat_FromDouble(*ptr);
361  }
362  case 's': // handle only C++ string and NOT C char array because static cast cannot differentiate the two
363  {
364  string * ptr = static_cast< string * >(obj);
365  assert (ptr != NULL);
366  return PyString_FromString(ptr->c_str());
367  }
368  case 'x':
369  {
370  Id * ptr = static_cast< Id * >(obj);
371  assert(ptr != NULL);
372  _Id * id = PyObject_New(_Id, &IdType);
373  id->id_ = *ptr;
374  return (PyObject *)(id);
375  }
376  case 'y':
377  {
378  ObjId * ptr = static_cast< ObjId * >(obj);
379  assert(ptr != NULL);
380  _ObjId * oid = PyObject_New(_ObjId, &ObjIdType);
381  oid->oid_ = *ptr;
382  return (PyObject*)oid;
383  }
384  case 'l':
385  {
386  long * ptr = static_cast< long * >(obj);
387  assert(ptr != NULL);
388  return PyLong_FromLong(*ptr);
389  }
390  case 'k':
391  {
392  unsigned long * ptr = static_cast< unsigned long * >(obj);
393  assert(ptr != NULL);
394  return PyLong_FromUnsignedLong(*ptr);
395  }
396  case 'i': // integer
397  {
398  int * ptr = static_cast< int * >(obj);
399  assert(ptr != NULL);
400  return PyInt_FromLong(*ptr);
401  }
402  case 'I': // unsigned int
403  {
404  unsigned int * ptr = static_cast< unsigned int * >(obj);
405  assert(ptr != NULL);
406  return PyLong_FromUnsignedLong(*ptr);
407  }
408  case 'b': //bool
409  {
410  bool * ptr = static_cast< bool * >(obj);
411  assert(ptr != NULL);
412  if (*ptr)
413  {
414  Py_RETURN_TRUE;
415  }
416  else
417  {
418  Py_RETURN_FALSE;
419  }
420  }
421 #ifdef HAVE_LONG_LONG
422  case 'L': //long long
423  {
424  long long * ptr = static_cast< long long * > (obj);
425  assert(ptr != NULL);
426  return PyLong_FromLongLong(*ptr);
427  }
428  case 'K': // unsigned long long
429  {
430  unsigned long long * ptr = static_cast< unsigned long long * >(obj);
431  assert(ptr != NULL);
432  return PyLong_FromUnsignedLongLong(*ptr);
433  }
434 #endif // HAVE_LONG_LONG
435  case 'f': // float
436  {
437  float * ptr = static_cast< float* >(obj);
438  assert(ptr != NULL);
439  return PyFloat_FromDouble(*ptr);
440  }
441  case 'c': // char
442  {
443  char * ptr = static_cast< char * >(obj);
444  assert(ptr != NULL);
445  return Py_BuildValue("c", *ptr);
446  }
447  case 'h': //short
448  {
449  short * ptr = static_cast< short* >(obj);
450  assert(ptr != NULL);
451  return Py_BuildValue("h", *ptr);
452  }
453  case 'H': // unsigned short
454  {
455  unsigned short * ptr = static_cast< unsigned short * >(obj);
456  assert(ptr != NULL);
457  return Py_BuildValue("H", *ptr);
458  }
459  case 'D':
460  case 'v':
461  case 'M':
462  case 'X':
463  case 'Y':
464  case 'C':
465  case 'w':
466  case 'N':
467  case 'P':
468  case 'F':
469  case 'S':
470  case 'T':
471  case 'Q':
472  case 'R':
473  {
474  return to_pytuple(obj, innerType(typecode));
475  }
476  default:
477  {
478  PyErr_SetString(PyExc_TypeError, "unhandled data type");
479  return NULL;
480  }
481  } // switch(typecode)
482 } // to_py
Definition: ObjId.h:20
PyObject_HEAD ObjId oid_
Definition: moosemodule.h:133
PyTypeObject ObjIdType
PyObject * to_pytuple(void *obj, char typecode)
char innerType(char)
Definition: types.cpp:104
Definition: Id.h:17
PyTypeObject IdType
Definition: vec.cpp:262
static char id[]
Definition: mfield.cpp:404

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

PyObject* to_pytuple ( void *  obj,
char  typecode 
)

Convert C++ vector to Python tuple

Convert a C++ vector to Python tuple

Definition at line 515 of file moosemodule.cpp.

References convert_and_set_tuple_entry().

Referenced by get_vec_lookupfield(), moose_ElementField_getattro(), moose_Id_getattro(), and to_py().

516 {
517  PyObject * ret;
518  switch (typecode)
519  {
520  case 'd': // vector<double>
521  {
522  vector< double > * vec = static_cast< vector < double >* >(obj);
523  assert(vec != NULL);
524 #ifndef USE_NUMPY
525  ret = PyTuple_New((Py_ssize_t)vec->size());
526  for (unsigned int ii = 0; ii < vec->size(); ++ii)
527  {
528  if (0 != PyTuple_SetItem(ret, ii, PyFloat_FromDouble(vec->at(ii))))
529  {
530  Py_DECREF(ret);
531  return NULL;
532  }
533  }
534 #else
535  npy_intp size = (npy_intp)(vec->size());
536  ret = PyArray_SimpleNew(1, &size, NPY_DOUBLE);
537  assert(ret != NULL);
538  char * ptr = PyArray_BYTES((PyArrayObject*)ret);
539  memcpy(ptr, &(*vec)[0], vec->size() * sizeof(double));
540 #endif
541  return ret;
542  }
543  case 'i': // vector<int>
544  {
545  vector< int > * vec = static_cast< vector < int >* >(obj);
546  assert(vec != NULL);
547 #ifndef USE_NUMPY
548  ret = PyTuple_New((Py_ssize_t)vec->size());
549  for (unsigned int ii = 0; ii < vec->size(); ++ii)
550  {
551  if (0 != PyTuple_SetItem(ret, ii, PyInt_FromLong(vec->at(ii))))
552  {
553  Py_DECREF(ret);
554  return NULL;
555  }
556  }
557 #else
558  npy_intp size = (npy_intp)(vec->size());
559  ret = PyArray_SimpleNew(1, &size, NPY_INT);
560  assert(ret != NULL);
561  char * ptr = PyArray_BYTES((PyArrayObject*)ret);
562  memcpy(ptr, &(*vec)[0], size * sizeof(int));
563 #endif
564  return ret;
565  }
566  case 'I': // vector<unsigned int>
567  {
568  vector< int > * vec = static_cast< vector < int >* >(obj);
569  assert(vec != NULL);
570 #ifndef USE_NUMPY
571  ret = PyTuple_New((Py_ssize_t)vec->size());
572  for (unsigned int ii = 0; ii < vec->size(); ++ii)
573  {
574  if (0 != PyTuple_SetItem(ret, ii, PyLong_FromLong(vec->at(ii))))
575  {
576  Py_DECREF(ret);
577  return NULL;
578  }
579  }
580 #else
581  npy_intp size = (npy_intp)(vec->size());
582  ret = PyArray_SimpleNew(1, &size, NPY_UINT);
583  assert(ret != NULL);
584  char * ptr = PyArray_BYTES((PyArrayObject*)ret);
585  memcpy(ptr, &(*vec)[0], size * sizeof(unsigned int));
586 #endif
587  return ret;
588  }
589  case 'l': // vector<long>
590  {
591  vector< long > * vec = static_cast< vector < long >* >(obj);
592  assert(vec != NULL);
593 #ifndef USE_NUMPY
594  ret = PyTuple_New((Py_ssize_t)vec->size());
595  for (unsigned int ii = 0; ii < vec->size(); ++ii)
596  {
597  if (0 != PyTuple_SetItem(ret, ii, PyLong_FromLong(vec->at(ii))))
598  {
599  Py_DECREF(ret);
600  return NULL;
601  }
602  }
603 #else
604  npy_intp size = (npy_intp)(vec->size());
605  ret = PyArray_SimpleNew(1, &size, NPY_INT);
606  assert(ret != NULL);
607  char * ptr = PyArray_BYTES((PyArrayObject*)ret);
608  memcpy(ptr, &(*vec)[0], size * sizeof(long));
609 #endif
610  return ret;
611  }
612  case 'x': // vector<Id>
613  {
614  vector< Id > * vec = static_cast< vector < Id >* >(obj);
615  assert(vec != NULL);
616  ret = PyTuple_New((Py_ssize_t)vec->size());
617  assert(ret != NULL);
618  for (unsigned int ii = 0; ii < vec->size(); ++ii)
619  {
620  if (convert_and_set_tuple_entry(ret, ii, (void*)&vec->at(ii), typecode) == NULL)
621  {
622  return NULL;
623  }
624  }
625  break;
626  }
627  case 'y': // vector<ObjId>
628  {
629  vector< ObjId > * vec = static_cast< vector < ObjId >* >(obj);
630  assert(vec != NULL);
631  ret = PyTuple_New((Py_ssize_t)vec->size());
632  assert(ret != NULL);
633  for (unsigned int ii = 0; ii < vec->size(); ++ii)
634  {
635  if (convert_and_set_tuple_entry(ret, ii, (void*)&vec->at(ii), typecode) == NULL)
636  {
637  return NULL;
638  }
639  }
640  break;
641  }
642  case 'c': // vector<char>
643  {
644  vector< char > * vec = static_cast< vector < char >* >(obj);
645  assert(vec != NULL);
646  ret = PyTuple_New((Py_ssize_t)vec->size());
647  assert(ret != NULL);
648  for (unsigned int ii = 0; ii < vec->size(); ++ii)
649  {
650  if (convert_and_set_tuple_entry(ret, ii, (void*)&vec->at(ii), typecode) == NULL)
651  {
652  return NULL;
653  }
654  }
655  break;
656  }
657  case 'h': // vector<short>
658  {
659  vector< short > * vec = static_cast< vector < short >* >(obj);
660  assert(vec != NULL);
661  ret = PyTuple_New((Py_ssize_t)vec->size());
662  assert(ret != NULL);
663  for (unsigned int ii = 0; ii < vec->size(); ++ii)
664  {
665  if (convert_and_set_tuple_entry(ret, ii, (void*)&vec->at(ii), typecode) == NULL)
666  {
667  return NULL;
668  }
669  }
670  break;
671  }
672  case 'k': // vector<unsigned long>
673  {
674  vector< unsigned int > * vec = static_cast< vector < unsigned int >* >(obj);
675  assert(vec != NULL);
676 #ifndef USE_NUMPY
677  ret = PyTuple_New((Py_ssize_t)vec->size());
678  for (unsigned int ii = 0; ii < vec->size(); ++ii)
679  {
680  if (0 != PyTuple_SetItem(ret, ii, PyLong_FromUnsignedLong(vec->at(ii))))
681  {
682  Py_DECREF(ret);
683  return NULL;
684  }
685  }
686 #else
687  npy_intp size = (npy_intp)(vec->size());
688  ret = PyArray_SimpleNew(1, &size, NPY_UINT);
689  assert(ret != NULL);
690  char * ptr = PyArray_BYTES((PyArrayObject*)ret);
691  memcpy(ptr, &(*vec)[0], size * sizeof(unsigned int));
692 #endif
693  return ret;
694  }
695  case 'L': // vector<long long> - this is not used at present
696  {
697  vector< long long> * vec = static_cast< vector < long long>* >(obj);
698  assert(vec != NULL);
699  ret = PyTuple_New((Py_ssize_t)vec->size());
700 #ifndef USE_NUMPY
701  for (unsigned int ii = 0; ii < vec->size(); ++ii)
702  {
703  if (0 != PyTuple_SetItem(ret, ii, PyLong_FromLongLong(vec->at(ii))))
704  {
705  Py_DECREF(ret);
706  return NULL;
707  }
708  }
709 #else
710  npy_intp size = (npy_intp)(vec->size());
711  ret = PyArray_SimpleNew(1, &size, NPY_LONGLONG);
712  assert(ret != NULL);
713  char * ptr = PyArray_BYTES((PyArrayObject*)ret);
714  memcpy(ptr, &(*vec)[0], size * sizeof(long long));
715 #endif
716  return ret;
717  }
718  case 'K': // vector<unsigned long long> - this is not used at present
719  {
720  vector< unsigned long long> * vec = static_cast< vector < unsigned long long>* >(obj);
721  assert(vec != NULL);
722 #ifndef USE_NUMPY
723  ret = PyTuple_New((Py_ssize_t)vec->size());
724  for (unsigned int ii = 0; ii < vec->size(); ++ii)
725  {
726  if (0 != PyTuple_SetItem(ret, ii, PyLong_FromUnsignedLongLong(vec->at(ii))))
727  {
728  Py_DECREF(ret);
729  return NULL;
730  }
731  }
732 #else
733  npy_intp size = (npy_intp)(vec->size());
734  ret = PyArray_SimpleNew(1, &size, NPY_ULONGLONG);
735  assert(ret != NULL);
736  char * ptr = PyArray_BYTES((PyArrayObject*)ret);
737  memcpy(ptr, &(*vec)[0], size * sizeof(unsigned long long));
738 #endif
739  return ret;
740  }
741  case 'F': // vector<float>
742  {
743  vector< float > * vec = static_cast< vector < float >* >(obj);
744  assert(vec != NULL);
745 #ifndef USE_NUMPY
746  ret = PyTuple_New((Py_ssize_t)vec->size());
747  for (unsigned int ii = 0; ii < vec->size(); ++ii)
748  {
749  if (0 != PyTuple_SetItem(ret, ii, PyFloat_FromDouble(vec->at(ii))))
750  {
751  Py_DECREF(ret);
752  return NULL;
753  }
754  }
755 #else
756  npy_intp size = (npy_intp)(vec->size());
757  ret = PyArray_SimpleNew(1, &size, NPY_FLOAT);
758  assert(ret != NULL);
759  char * ptr = PyArray_BYTES((PyArrayObject*)ret);
760  memcpy(ptr, &(*vec)[0], size * sizeof(float));
761 #endif
762  return ret;
763  }
764  case 's': // vector<string>
765  {
766  vector< string > * vec = static_cast< vector < string >* >(obj);
767  assert(vec != NULL);
768  ret = PyTuple_New((Py_ssize_t)vec->size());
769  assert(ret != NULL);
770  for (unsigned int ii = 0; ii < vec->size(); ++ii)
771  {
772  string v = vec->at(ii);
773  if (convert_and_set_tuple_entry(ret, ii, (void*)&v, typecode) == NULL)
774  {
775  return NULL;
776  }
777  }
778  break;
779  }
780  case 'N': // vector< vector <unsigned int > >
781  {
782  vector< vector< unsigned int > > * vec = static_cast< vector < vector< unsigned int > >* >(obj);
783  assert(vec != NULL);
784  ret = PyTuple_New((Py_ssize_t)vec->size());
785  assert(ret != NULL);
786  for (unsigned int ii = 0; ii < vec->size(); ++ii)
787  {
788  if (convert_and_set_tuple_entry(ret, ii, (void*)&vec->at(ii), typecode) == NULL)
789  {
790  return NULL;
791  }
792  }
793  break;
794  }
795  case 'v': // vector< vector < int > >
796  {
797  vector< vector< int > > * vec = static_cast< vector < vector< int > >* >(obj);
798  assert(vec != NULL);
799  ret = PyTuple_New((Py_ssize_t)vec->size());
800  assert(ret != NULL);
801  for (unsigned int ii = 0; ii < vec->size(); ++ii)
802  {
803  if (convert_and_set_tuple_entry(ret, ii, (void*)&vec->at(ii), typecode) == NULL)
804  {
805  return NULL;
806  }
807  }
808  break;
809  }
810  case 'D': // vector< vector <double > >
811  {
812  vector< vector< double > > * vec = static_cast< vector < vector< double > >* >(obj);
813  assert(vec != NULL);
814  ret = PyTuple_New((Py_ssize_t)vec->size());
815  assert(ret != NULL);
816  for (unsigned int ii = 0; ii < vec->size(); ++ii)
817  {
818  if (convert_and_set_tuple_entry(ret, ii, (void*)&vec->at(ii), typecode) == NULL)
819  {
820  return NULL;
821  }
822  }
823  break;
824  }
825  default:
826  PyErr_SetString(PyExc_TypeError, "unhandled type");
827  return NULL;
828  }
829  return ret;
830 }
PyObject * convert_and_set_tuple_entry(PyObject *tuple, unsigned int index, void *vptr, char typecode)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Variable Documentation

struct module_state _state
static

Definition at line 66 of file moosemodule.h.

unsigned char bytes[4]

Definition at line 41 of file moosemodule.h.

const { ... } o32_host_order
uint32_t value

Definition at line 42 of file moosemodule.h.

Referenced by ReadCell::addCaConc(), ReadCell::addCanonicalChannel(), HSolve::addInject(), ReadCell::buildChannels(), get_simple_lookupfield(), get_vec_lookupfield(), Func::getDerivative(), Function::getDerivative(), Func::getValue(), Function::getValue(), Func::initCinfo(), Function::initCinfo(), PulseGen::input(), isNaN(), moose::mapToString(), moose_ElementField_getSlice(), moose_ElementField_setattro(), moose_getField(), moose_getFieldDict(), moose_Id_fillSlice(), moose_Id_setattro(), moose_Id_setField(), moose_Id_subscript(), moose_ObjId_getattro(), moose_ObjId_getSlice(), moose_ObjId_setattro(), moose_ObjId_setField(), moose_ObjId_setLookupField(), SparseMatrix< unsigned int >::pairFill(), PyRun::process(), PyRun::PyRun(), PySequenceToVector(), PyRun::run(), SparseMatrix< unsigned int >::set(), IzhikevichNrn::setA(), MarkovGslSolver::setAbsoluteAccuracy(), IzhikevichNrn::setAccommodating(), IzhikevichNrn::setAlpha(), IzhikevichNrn::setB(), IzhikevichNrn::setBeta(), IzhikevichNrn::setC(), Nernst::setCin(), HSolve::setCm(), moose::VClamp::setCommand(), SteadyState::setConvergenceCriterion(), Nernst::setCout(), IzhikevichNrn::setD(), moose::CompartmentBase::setDiameter(), Interpol2D::setDx(), Interpol2D::setDy(), HSolve::setEk(), HSolve::setEm(), moose::VClamp::setGain(), IzhikevichNrn::setGamma(), HSolve::setGk(), HSolve::setHHChannelGbar(), HSolve::setHHmodulation(), IzhikevichNrn::setInitU(), HSolve::setInitVm(), IzhikevichNrn::setInitVm(), IzhikevichNrn::setInject(), HSolve::setInject(), Adaptor::setInputOffset(), MarkovGslSolver::setInternalDt(), MMPump::setKd(), moose::CompartmentBase::setLength(), setLookupField(), SteadyState::setMaxIter(), Cell::setMethod(), SynChan::setNormalizeWeights(), Adaptor::setOutputOffset(), Dsolve::setPath(), HSolve::setRa(), MarkovGslSolver::setRelativeAccuracy(), HSolve::setRm(), IzhikevichNrn::setRmByTau(), Nernst::setScale(), Adaptor::setScale(), Cell::setSolverClock(), Cell::setSolverName(), SteadyState::setStoich(), Interpol2D::setSy(), HHGate2D::setTableA(), HHGate2D::setTableB(), Interpol2D::setTableVector(), moose::VClamp::setTau(), moose::VClamp::setTd(), Nernst::setTemperature(), moose::VClamp::setTi(), IzhikevichNrn::setU0(), HHChannelBase::setUseConcentration(), Nernst::setValence(), Func::setVar(), moose::VClamp::setVin(), HSolve::setVm(), IzhikevichNrn::setVm(), MMPump::setVmax(), IzhikevichNrn::setVmax(), moose::CompartmentBase::setX(), HSolve::setX(), moose::CompartmentBase::setX0(), Interpol2D::setXmax(), Interpol::setXmax(), Interpol2D::setXmin(), Interpol::setXmin(), moose::CompartmentBase::setY(), HSolve::setY(), moose::CompartmentBase::setY0(), Interpol2D::setYmax(), Interpol2D::setYmin(), moose::CompartmentBase::setZ(), HSolve::setZ(), moose::CompartmentBase::setZ0(), to_cpp(), PyRun::trigger(), HSolvePassive::updateMatrix(), HSolveActive::updateMatrix(), DifBuffer::vSetActivation(), DifBuffer::vSetBBound(), DifBuffer::vSetBFree(), DifBuffer::vSetBTot(), DifBuffer::vSetD(), DifBuffer::vSetKb(), DifBuffer::vSetKf(), and HHChannel::vSetUseConcentration().