this repo has no description
1#ifndef __Mzn_OBJECT_H 2#define __Mzn_OBJECT_H 3 4enum Mzn_Object_Code { MOC_BASE, MOC_EXPR, MOC_ANN, MOC_VARSET, MOC_SET }; 5 6struct MznObject { 7 PyObject_HEAD Mzn_Object_Code tid; 8}; 9 10static PyObject* MznObject_new(PyTypeObject* type, PyObject* args, PyObject* kwds) { 11 PyObject* self = type->tp_alloc(type, 0); 12 reinterpret_cast<MznObject*>(self)->tid = MOC_BASE; 13 return self; 14} 15 16static void MznObject_dealloc(MznObject* self) { 17 Py_TYPE(self)->tp_free(reinterpret_cast<PyObject*>(self)); 18} 19 20static PyTypeObject MznObject_Type = { 21 PyVarObject_HEAD_INIT(NULL, 0) "minizinc.Object", /* tp_name */ 22 sizeof(MznObject), /* tp_basicsize */ 23 0, /* tp_itemsize */ 24 (destructor)MznObject_dealloc, /* tp_dealloc */ 25 0, /* tp_print */ 26 0, /* tp_getattr */ 27 0, /* tp_setattr */ 28 0, /* tp_reserved */ 29 0, /* tp_repr */ 30 0, /* tp_as_number */ 31 0, /* tp_as_sequence */ 32 0, /* tp_as_mapping */ 33 0, /* tp_hash */ 34 0, /* tp_call */ 35 0, /* tp_str */ 36 0, /* tp_getattro */ 37 0, /* tp_setattro */ 38 0, /* tp_as_buffer */ 39 Py_TPFLAGS_BASETYPE, /* tp_flags */ 40 "Minizinc Object", /* tp_doc */ 41 0, /* tp_traverse */ 42 0, /* tp_clear */ 43 0, /* tp_richcompare */ 44 0, /* tp_weaklistoffset */ 45 0, /* tp_iter */ 46 0, /* tp_iternext */ 47 0, /* tp_methods */ 48 0, /* tp_members */ 49 0, /* tp_getset */ 50 0, /* tp_base */ 51 0, /* tp_dict */ 52 0, /* tp_descr_get */ 53 0, /* tp_descr_set */ 54 0, /* tp_dictoffset */ 55 0, /* tp_init */ 56 0, /* tp_alloc */ 57 MznObject_new, /* tp_new */ 58 0, /* tp_free */ 59}; 60 61#include "Annotation.h" 62#include "Expression.h" 63#include "Set.h" 64#include "VarSet.h" 65 66// Note: I have tried adding a function Expression* e() to MznObject, 67// but it didn't work well. The derived objects, after being initialized by PyObject_INIT 68// returns unusable derived functions. 69// While this maybe a little bit annoying, it is the best solution that I can come up with. 70// 71// Returns: MiniZinc expression Expression* 72static Expression* MznObject_get_e(MznObject* self) { 73 switch (self->tid) { 74 case MOC_BASE: 75 return NULL; 76 case MOC_SET: 77 return reinterpret_cast<MznSet*>(self)->e(); 78 case MOC_EXPR: 79 case MOC_ANN: 80 return reinterpret_cast<MznExpression*>(self)->e; 81 default: 82 throw logic_error("Unhandled type"); 83 } 84} 85 86#endif