source: orange/source/pyxtract/defvectors.py @ 6538:a5f65d7f0b2c

Revision 6538:a5f65d7f0b2c, 9.5 KB checked in by Mitar <Mitar@…>, 4 years ago (diff)

Made XPM version of the icon 32x32.

Line 
1### writes a text file with code that defines methods for sequence slots
2
3from pyprops import ClassDefinition
4classes = {None: None}
5
6definition ="""
7$wrappedlistname$ P$pyname$_FromArguments(PyObject *arg) { return $classname$::P_FromArguments(arg); }
8PyObject *$pyname$_FromArguments(PyTypeObject *type, PyObject *arg) { return $classname$::_FromArguments(type, arg); }
9PyObject *$pyname$_new(PyTypeObject *type, PyObject *arg, PyObject *kwds) BASED_ON(Orange, "(<list of $pyelement$>)") ALLOWS_EMPTY { return $classname$::_new(type, arg, kwds); }
10PyObject *$pyname$_getitem_sq(TPyOrange *self, Py_ssize_t index) { return $classname$::_getitem(self, index); }
11int       $pyname$_setitem_sq(TPyOrange *self, Py_ssize_t index, PyObject *item) { return $classname$::_setitem(self, index, item); }
12PyObject *$pyname$_getslice(TPyOrange *self, Py_ssize_t start, Py_ssize_t stop) { return $classname$::_getslice(self, start, stop); }
13int       $pyname$_setslice(TPyOrange *self, Py_ssize_t start, Py_ssize_t stop, PyObject *item) { return $classname$::_setslice(self, start, stop, item); }
14Py_ssize_t       $pyname$_len_sq(TPyOrange *self) { return $classname$::_len(self); }
15PyObject *$pyname$_richcmp(TPyOrange *self, PyObject *object, int op) { return $classname$::_richcmp(self, object, op); }
16PyObject *$pyname$_concat(TPyOrange *self, PyObject *obj) { return $classname$::_concat(self, obj); }
17PyObject *$pyname$_repeat(TPyOrange *self, Py_ssize_t times) { return $classname$::_repeat(self, times); }
18PyObject *$pyname$_str(TPyOrange *self) { return $classname$::_str(self); }
19PyObject *$pyname$_repr(TPyOrange *self) { return $classname$::_str(self); }
20int       $pyname$_contains(TPyOrange *self, PyObject *obj) { return $classname$::_contains(self, obj); }
21PyObject *$pyname$_append(TPyOrange *self, PyObject *item) PYARGS(METH_O, "($pyelement$) -> None") { return $classname$::_append(self, item); }
22PyObject *$pyname$_extend(TPyOrange *self, PyObject *obj) PYARGS(METH_O, "(sequence) -> None") { return $classname$::_extend(self, obj); }
23PyObject *$pyname$_count(TPyOrange *self, PyObject *obj) PYARGS(METH_O, "($pyelement$) -> int") { return $classname$::_count(self, obj); }
24PyObject *$pyname$_filter(TPyOrange *self, PyObject *args) PYARGS(METH_VARARGS, "([filter-function]) -> $pyname$") { return $classname$::_filter(self, args); }
25PyObject *$pyname$_index(TPyOrange *self, PyObject *obj) PYARGS(METH_O, "($pyelement$) -> int") { return $classname$::_index(self, obj); }
26PyObject *$pyname$_insert(TPyOrange *self, PyObject *args) PYARGS(METH_VARARGS, "(index, item) -> None") { return $classname$::_insert(self, args); }
27PyObject *$pyname$_native(TPyOrange *self) PYARGS(METH_NOARGS, "() -> list") { return $classname$::_native(self); }
28PyObject *$pyname$_pop(TPyOrange *self, PyObject *args) PYARGS(METH_VARARGS, "() -> $pyelement$") { return $classname$::_pop(self, args); }
29PyObject *$pyname$_remove(TPyOrange *self, PyObject *obj) PYARGS(METH_O, "($pyelement$) -> None") { return $classname$::_remove(self, obj); }
30PyObject *$pyname$_reverse(TPyOrange *self) PYARGS(METH_NOARGS, "() -> None") { return $classname$::_reverse(self); }
31PyObject *$pyname$_sort(TPyOrange *self, PyObject *args) PYARGS(METH_VARARGS, "([cmp-func]) -> None") { return $classname$::_sort(self, args); }
32PyObject *$pyname$__reduce__(TPyOrange *self, PyObject *) { return $classname$::_reduce(self); }
33"""
34
35wdefinition = "\nextern PyTypeObject PyOr$pyelement$_Type_inh;\n" + definition
36
37udefinition = """
38bool convertFromPython(PyObject *, $elementname$ &);
39PyObject *convertToPython(const $elementname$ &);
40""" \
41+ definition
42
43# removed from udefinition
44# #define $listname$ _TOrangeVector<$elementname$>
45# typedef GCPtr< $listname$ > $wrappedlistname$;
46
47outf = open("lib_vectors_auto.txt", "wt")
48
49def normalList(name, goesto):
50  return tuple([x % name for x in ("%sList", "%s", "P%sList", "T%sList", "P%s")] + [goesto])
51
52
53#  list name in Python,    element name in Py, wrapped list name in C, list name in C,         list element name in C, interface file
54for (pyname, pyelementname, wrappedlistname, listname, elementname, goesto) in \
55  [("ValueList",           "Value",            "PValueList",           "TValueList",           "TValue",               "cls_value.cpp"),
56   ("VarList",             "Variable",         "PVarList",             "TVarList",             "PVariable",            "lib_kernel.cpp"),
57   ("VarListList",         "VarList",          "PVarListList",         "TVarListList",         "PVarList",             "lib_kernel.cpp"),
58   ("DomainDistributions", "Distribution",     "PDomainDistributions", "TDomainDistributions", "PDistribution",        "lib_kernel.cpp"),
59   normalList("Distribution", "lib_kernel.cpp"),
60   normalList("ExampleGenerator", "lib_kernel.cpp"),
61   normalList("Classifier", "lib_kernel.cpp"),
62   
63   ("DomainBasicAttrStat", "BasicAttrStat",    "PDomainBasicAttrStat", "TDomainBasicAttrStat", "PBasicAttrStat",       "lib_components.cpp"),
64   ("DomainContingency",   "Contingency",      "PDomainContingency",   "TDomainContingency",   "PContingencyClass",    "lib_components.cpp"),
65   normalList("ValueFilter", "lib_components.cpp"),
66   normalList("Filter", "lib_components.cpp"),
67   normalList("HierarchicalCluster", "lib_components.cpp"),
68   
69   ("AssociationRules",    "AssociationRule",  "PAssociationRules",    "TAssociationRules",    "PAssociationRule",     "lib_learner.cpp"),
70   normalList("TreeNode", "lib_learner.cpp"),
71   normalList("C45TreeNode", "lib_learner.cpp"),
72   normalList("Rule", "lib_learner.cpp"),
73   normalList("ConditionalProbabilityEstimator", "lib_components.cpp"),
74   normalList("ProbabilityEstimator", "lib_components.cpp"),
75   normalList("EVDist", "lib_learner.cpp"),
76
77   normalList("Heatmap", "orangene.cpp"),
78   normalList("SOMNode", "som.cpp")
79   ]:
80  outf.write("**** This goes to '%s' ****\n" % goesto)
81  outf.write(wdefinition.replace("$pyname$", pyname)
82                        .replace("$classname$", "ListOfWrappedMethods<%s, %s, %s, &PyOr%s_Type>" % (wrappedlistname, listname, elementname, pyelementname))
83                       .replace("$pyelement$", pyelementname)
84                       .replace("$wrappedlistname$", wrappedlistname)
85                       .replace(">>", "> >")
86             +"\n\n"
87            )
88
89  classes[listname] = ClassDefinition(listname, "TOrange") 
90
91
92
93coutf = open("lib_vectors.cpp", "wt")
94
95coutf.write("""/*
96    This file is part of Orange.
97
98    Orange is free software; you can redistribute it and/or modify
99    it under the terms of the GNU General Public License as published by
100    the Free Software Foundation; either version 2 of the License, or
101    (at your option) any later version.
102
103    Orange is distributed in the hope that it will be useful,
104    but WITHOUT ANY WARRANTY; without even the implied warranty of
105    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
106    GNU General Public License for more details.
107
108    You should have received a copy of the GNU General Public License
109    along with Orange; if not, write to the Free Software
110    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
111
112    Authors: Janez Demsar, Blaz Zupan, 1996--2002
113    Contact: janez.demsar@fri.uni-lj.si
114*/
115
116
117#include "orvector.hpp"
118#include "cls_orange.hpp"
119#include "vectortemplates.hpp"
120#include "externs.px"
121
122#include "distance_dtw.hpp"
123""")
124
125for (pyname, pyelementname, wrappedlistname, listname, elementname, wrapped) in \
126  [("BoolList",         "bool",     "PBoolList",         "TBoolList",         "bool", 0),
127   ("IntList",          "int",      "PIntList",          "TIntList",          "int", 0),
128   ("FloatList",        "float",    "PFloatList",        "TFloatList",        "float", 0),
129   ("FloatListList",    "FloatList","PFloatListList",    "TFloatListList",    "PFloatList", 1),
130   ("StringList",       "string",   "PStringList",       "TStringList",       "string", 0),
131   ("LongList",         "int",      "PLongList",         "TLongList",         "long", 0),
132   ("_Filter_index",     "int",     "PFilter_index",     "TFilter_index",     "FOLDINDEXTYPE", 0),
133   ("AlignmentList",    "Alignment", "PAlignmentList",  "TAlignmentList",    "TAlignment", 0),
134
135   ("IntFloatList",     "tuple(int, float)",   "PIntFloatList",    "TIntFloatList",     "pair<int, float>", 0),
136   ("FloatFloatList",   "tuple(float, float)", "PFloatFloatList",  "TFloatFloatList",   "pair<float, float>", 0),
137   ]:
138  if (pyname[0]=="_"):
139    pyname = pyname[1:]
140    outfile=outf
141  else:
142    outfile=coutf
143  if wrapped:
144    classname = "ListOfWrappedMethods<%s, %s, %s, &PyOr%s_Type>" % (wrappedlistname, listname, elementname, pyelementname)
145  else:
146    classname = "ListOfUnwrappedMethods<%s, %s, %s>" % (wrappedlistname, listname, elementname)
147
148  outfile.write((wrapped and wdefinition or udefinition)
149                       .replace("$pyname$", pyname)
150                       .replace("$classname$", classname)
151                       .replace("$pyelement$", pyelementname)
152                       .replace("$wrappedlistname$", wrappedlistname)
153                       .replace("$listname$", listname)
154                       .replace("$elementname$", elementname)
155                       .replace(">>", "> >")
156             +"\n\n"
157            )
158
159  classes[listname] = ClassDefinition(listname, "TOrange")
160
161coutf.write('#include "lib_vectors.px"\n')
162
163outf.close()
164coutf.close()
165
166import pickle
167
168classes["TAttributedFloatList"] = ClassDefinition("TAttributedFloatList", "TFloatList")
169classes["TAttributedBoolList"] = ClassDefinition("TAttributedBoolList", "TBoolList")
170
171import os
172if not os.path.exists("../orange/ppp"):
173  os.mkdir("../orange/ppp")
174pickle.dump(classes, file("../orange/ppp/lists", "wt"))
Note: See TracBrowser for help on using the repository browser.