source: orange/source/orange/pythonvars.hpp @ 6531:57bdc92cd8e9

Revision 6531:57bdc92cd8e9, 2.9 KB checked in by janezd <janez.demsar@…>, 4 years ago (diff)
  • changed licenses to GPL 3.0
Line 
1/*
2    This file is part of Orange.
3   
4    Copyright 1996-2010 Faculty of Computer and Information Science, University of Ljubljana
5    Contact: janez.demsar@fri.uni-lj.si
6
7    Orange is free software: you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation, either version 3 of the License, or
10    (at your option) any later version.
11
12    Orange is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with Orange.  If not, see <http://www.gnu.org/licenses/>.
19*/
20
21
22#ifndef __PYTHONVARS_HPP
23#define __PYTHONVARS_HPP
24
25#include "root.hpp"
26#include "values.hpp"
27#include "vars.hpp"
28
29#include "c2py.hpp"
30
31#define PYTHONVAR 7
32
33class ORANGE_API TPythonValue : public TSomeValue {
34public:
35  __REGISTER_CLASS
36
37  PyObject *value;
38
39  TPythonValue();
40  TPythonValue(const TPythonValue &other);
41  TPythonValue(PyObject *value);
42
43  TPythonValue &TPythonValue::operator =(const TPythonValue &other);
44
45  ~TPythonValue();
46
47  virtual int  compare(const TSomeValue &v) const;
48  virtual bool compatible(const TSomeValue &v) const;
49};
50
51
52
53class ORANGE_API TPythonVariable : public TVariable {
54public:
55  __REGISTER_CLASS
56
57  bool usePickle; //P tells whether to use pickle for saving to/loading from files
58  bool useSomeValue; //P tells whether the Variable will operate on Value or SomeValue (default)
59
60protected:
61  TValue DC_somevalue;
62  TValue DK_somevalue;
63
64public:
65  TPythonVariable();
66  TPythonVariable(const string &aname);
67
68  bool isOverloaded(char *method) const;
69
70  virtual const TValue &DC() const;
71  virtual const TValue &DK() const;
72  virtual TValue specialValue(int) const;
73
74  virtual void val2str(const TValue &val, string &str) const;
75  virtual void str2val(const string &valname, TValue &valu);
76  virtual void str2val_add(const string &valname, TValue &valu);
77
78  virtual void val2filestr(const TValue &val, string &str, const TExample &) const;
79  virtual void filestr2val(const string &valname, TValue &valu, TExample &);
80
81  virtual bool   firstValue(TValue &val) const;
82  virtual bool   nextValue(TValue &val) const;
83  virtual TValue randomValue(const int &rand=-1);
84
85  // Returns the number of different values, -1 if it cannot be done (for example, if variable is continuous)
86  virtual int  noOfValues() const;
87
88// steals a reference!
89  TValue toValue(PyObject *pyvalue) const;
90
91  TValue toNoneValue(const signed char &valueType) const;
92  void toValue(PyObject *pyvalue, TValue &val) const;
93
94  PyObject *toPyObject(const TValue &valu) const;
95};
96
97
98class ORANGE_API TPythonValueSpecial : public TOrange {
99public:
100  __REGISTER_CLASS
101
102  int valueType; //P value type
103
104  TPythonValueSpecial(const int &vt)
105  : valueType(vt)
106  {}
107};
108
109#endif
Note: See TracBrowser for help on using the repository browser.