source: orange/source/orange/domain.hpp @ 10596:54f9c123f145

Revision 10596:54f9c123f145, 5.3 KB checked in by Matija Polajnar <matija.polajnar@…>, 2 years ago (diff)

Urgent bugfix: Refactor CRC variables from unsigned long to unsigned int to make it work properly on 64-bit machines (with 64-bit Python and libraries). Fixes #1146.

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#ifndef __DOMAIN_HPP
22#define __DOMAIN_HPP
23
24#include <vector>
25#include <list>
26#include <set>
27#include <string>
28using namespace std;
29
30#include "meta.hpp"
31#include "vars.hpp"
32WRAPPER(Domain);
33
34
35/*  A mapping from one domain to another. It is used by the convert method of the TDomain object which
36    owns the TDomainMapping to convert an example from the domain, described in this object, to the owning domain. */
37class ORANGE_API TDomainMapping {
38public:
39  TDomain *domain;
40  /*  Positions of attributes from owning domain in the domain, denoted by 'domain' field. For example,
41      if position[2]=5, the value of the second attribute from the owning domain is the value of the fifth
42      from the 'domain' domain. Negative values represent id's of `domain`'s meta-attributes.
43      If position[i]==ILLEGAL_INT, i-th attribute has no corresponding attribute in
44      'domain'; convert passes the entire example to the computeValue method of the i-th variable which will
45      either deduce its value from the example or return a DK. */
46  vector<int> positions;
47  vector<pair<int, int> > metaPositions;
48
49  /* These are metas not to copy: metas that are copied through one of the above two or those that appear in
50     definition of the 'domain' */
51  #ifdef _MSC_VER
52    #pragma warning(push)
53    #pragma warning(disable: 4251)
54  #endif
55  set<int> metasNotToCopy;
56  #ifdef _MCS_VER
57    #pragma warning(pop)
58  #endif
59
60  TDomainMapping(TDomain *);
61};
62
63
64class ORANGE_API TDomain : public TOrange {
65public:
66  __REGISTER_CLASS
67
68  PVariable classVar; //PR class variable
69  PVarList attributes; //PR(+features) list of attributes, excluding the class
70  PVarList variables; //PR list of attributes, including the class at the end of the list
71  PVarList classVars; //PR list of class variables, if multiple; else None
72
73  TMetaVector metas;
74
75  /*  Domain version is set to ++domainVersion each time a classVar, attributes or variables is changed.
76      The value of this field is compared to TDomainMapping's field with the same name. */
77  int version; //PR unique version identifier; it's changed each time a domain is changed
78
79  #if _MSC_VER
80    #pragma warning(push)
81    #pragma warning(disable: 4251)
82  #endif
83
84  list<TDomainMapping> knownDomains;
85  list<TDomainMapping>::iterator lastDomain;
86
87  list<TDomain *> knownByDomains;
88
89  typedef void TDestroyNotifier(TDomain *, void *);
90  typedef pair<TDestroyNotifier *, void *> TDestroyNotification;
91  list<TDestroyNotification> destroyNotifiers;
92
93  #ifdef _MSC_VER
94    #pragma warning(pop)
95  #endif
96
97  TDomain();
98  TDomain(PVariable, const TVarList &attributes);
99  TDomain(const TVarList &variables);
100  TDomain(const TDomain &);
101  ~TDomain();
102
103
104  void domainChangedDispatcher();
105  void domainChangedNoticeHandler(TDomain *);
106
107  int traverse(visitproc visit, void *arg) const;
108  int dropReferences();
109
110  virtual bool addVariable(PVariable var);
111  virtual bool addVariable(PVariable var, int position);
112  virtual bool delVariable(PVariable var);
113
114  virtual void removeClass();
115  virtual void setClass(PVariable var);
116  virtual void changeClass(PVariable var);
117
118  int getVarNum(PVariable, bool throwExc=true) const;
119  int getVarNum(const string &, bool throwExc=true) const;
120
121  PVariable getVar(int num, bool throwExc=true);
122  PVariable getVar(int num, bool throwExc=true) const;
123
124  PVariable getVar(const string &, bool takeMetas=true, bool throwExc=true);
125  PVariable getVar(const string &, bool takeMetas=true, bool throwExc=true) const;
126
127  long getMetaNum(const string &, bool throwExc=true) const;
128  long getMetaNum(PVariable, bool throwExc=true) const;
129
130  PVariable getMetaVar(const int &idx, bool throwExc=true);
131  PVariable getMetaVar(const int &idx, bool throwExc=true) const;
132
133  PVariable getMetaVar(const string &wname, bool throwExc=true);
134  PVariable getMetaVar(const string &wname, bool throwExc=true) const;
135
136  const TMetaDescriptor *getMetaDescriptor(const int &idx, bool throwExc=true) const;
137  const TMetaDescriptor *getMetaDescriptor(const string &wname, bool throwExc=true) const;
138  const TMetaDescriptor *getMetaDescriptor(const PVariable var, bool throwExc=true) const;
139
140  PVariable operator[](const string &name);
141  PVariable operator[](const string &name) const;
142
143  virtual void convert(TExample &dest, const TExample &src, bool filterMetas = false);
144  virtual void domainHasChanged();
145
146  void afterSet(const char *name);
147
148  PVariable hasDiscreteAttributes(bool checkClass = true) const;
149  PVariable hasContinuousAttributes(bool checkClass = true) const;
150  PVariable hasOtherAttributes(bool checkClass = true) const;
151 
152  void addToCRC(unsigned int &crc) const;
153  int sumValues() const;
154};
155
156
157#endif
Note: See TracBrowser for help on using the repository browser.