source: orange/source/orange/root.hpp @ 10887:43fcaa1ba432

Revision 10887:43fcaa1ba432, 5.4 KB checked in by Bobby Powers <bobby@…>, 2 years ago (diff)

headers: clean up #includes

This both reduces noise and fixes a build error from my distro's gcc
4.7.

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 __ROOT_HPP
23#define __ROOT_HPP
24
25#include "errors.hpp"
26#include "garbage.hpp"
27
28
29class TValue;
30
31#include <string>
32using namespace std;
33
34#define __REGISTER_ABSTRACT_CLASS \
35  static TClassDescription st_classDescription; \
36  virtual TClassDescription const *classDescription() const;
37
38#define __REGISTER_CLASS \
39  static TClassDescription st_classDescription; \
40  virtual TClassDescription const *classDescription() const; \
41  virtual TOrange *clone() const;
42
43
44#define CLASSCONSTANTS(x)
45
46/* traverse vs. visit
47
48'traverse' should call 'visit' on all wrapped objects it (directly) contains.
49Visiting wrapped objects that are registered as components is taken care of
50by TOrange. Thus, only unregistered objects, usually those that are included
51in lists need to be called.
52
53'traverse' should call 'traverse' on all owned unwrapped objects (by inclusion
54or by unwrapped pointers (which are not referenced by any other object! -- use
55of unwrapped pointer is very strongly dissuaded). This is needed so that the
56references to those object are 'explained'.
57*/
58
59
60#define PVISIT(obj) if ((obj).counter) VISIT((obj).counter);
61#define TRAVERSE(proc) { int res=proc(visit, arg); if (res) return res; }
62#define DROPREFERENCES(proc) { int res=proc(); if (res) return res; }
63#define CLONE(type,x) (x) ? dynamic_cast<type *>((x)->clone()) : (type *)(NULL)
64#define call operator()
65
66
67struct _tclassdescription;
68
69typedef void *TPropertyTransformer(void *);
70
71typedef struct {
72  const char *name;
73  const char *description;
74  const type_info *type;
75  const struct _tclassdescription *classDescription;
76
77  size_t offset;
78
79  bool readOnly;
80  bool obsolete;
81  TPropertyTransformer *transformer;
82} TPropertyDescription;
83
84
85typedef struct _tclassdescription {
86  const char *name;
87  const type_info *type;
88  const struct _tclassdescription *base;
89
90  TPropertyDescription const *properties;
91  size_t const *components;
92} TClassDescription;
93
94
95extern TPropertyDescription _no_properties[];
96extern size_t const _no_components[];
97
98bool castableTo(const TClassDescription *objecttype, const TClassDescription *basetype);
99
100#define CONST_MEMBER(ofs) (((char const *)(this)) + ofs)
101
102WRAPPER(Orange)
103
104class ORANGE_API TOrange : public TWrapped {
105public:
106  __REGISTER_CLASS
107  typedef void TWarningFunction(bool exhaustive, const char *);
108  static TWarningFunction *warningFunction;
109
110  TOrange()
111  {}
112
113  TOrange(const TOrange &orb)
114  {}
115 
116  virtual ~TOrange();
117
118  virtual void afterSet(const char *name);
119
120  void    setProperty(const char *name, const bool &b);    void    getProperty(const char *name, bool &b) const;
121  void    setProperty(const char *name, const int &b);     void    getProperty(const char *name, int &b) const;
122  void    setProperty(const char *name, const float &b);   void    getProperty(const char *name, float &b) const;
123  void    setProperty(const char *name, const string &b);  void    getProperty(const char *name, string &b) const;
124  void    setProperty(const char *name, const TValue &b);  void    getProperty(const char *name, TValue &b) const;
125  void wr_setProperty(const char *name, const POrange &b); void wr_getProperty(const char *name, POrange &b) const;
126
127  inline bool getProperty_bool(const TPropertyDescription *pd) const { return *(bool const *)CONST_MEMBER(pd->offset); }
128  inline int getProperty_int(const TPropertyDescription *pd) const { return *(int const *)CONST_MEMBER(pd->offset); }
129  inline float getProperty_float(const TPropertyDescription *pd) const { return *(float const *)CONST_MEMBER(pd->offset); }
130  inline void getProperty_string(const TPropertyDescription *pd, string &b) const { b = *(string const *)CONST_MEMBER(pd->offset); }
131  void getProperty_TValue(const TPropertyDescription *pd, TValue &b) const;
132  inline void getProperty_POrange(const TPropertyDescription *pd, POrange &b) const { b = *(POrange const *)CONST_MEMBER(pd->offset); }
133
134
135  const TPropertyDescription *propertyDescription(const char *name, bool noException = false) const;
136  const type_info &propertyType(const char *name) const;
137  bool hasProperty(const char *name) const;
138
139  virtual int traverse(visitproc visit, void *arg) const;
140  virtual int dropReferences();
141
142  void raiseError(const char *anerr, ...) const;
143  void raiseWarning(const char *anerr, ...) const;
144  void raiseCompatibilityWarning(const char *anerr, ...) const;
145  void raiseErrorWho(const char *who, const char *anerr, ...) const;
146  void raiseWarningWho(const char *who, const char *anerr, ...) const;
147
148  #define checkProperty(name) { if (!name) raiseError("'"#name"' not set"); }
149};
150
151extern ORANGE_API TPropertyDescription TOrange_properties[];
152extern ORANGE_API size_t const TOrange_components[];
153
154#endif
Note: See TracBrowser for help on using the repository browser.