Panda3D
interrogateType.h
1 // Filename: interrogateType.h
2 // Created by: drose (31Jul00)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef INTERROGATETYPE_H
16 #define INTERROGATETYPE_H
17 
18 #include "dtoolbase.h"
19 
20 #include "interrogateComponent.h"
21 
22 #include <vector>
23 
24 class IndexRemapper;
25 class CPPType;
26 class CPPScope;
27 
28 ////////////////////////////////////////////////////////////////////
29 // Class : InterrogateType
30 // Description : An internal representation of a type.
31 ////////////////////////////////////////////////////////////////////
32 class EXPCL_DTOOLCONFIG InterrogateType : public InterrogateComponent {
33 public:
35  InterrogateType(const InterrogateType &copy);
36  void operator = (const InterrogateType &copy);
37 
38  INLINE bool is_global() const;
39 
40  INLINE bool has_scoped_name() const;
41  INLINE const string &get_scoped_name() const;
42 
43  INLINE bool has_true_name() const;
44  INLINE const string &get_true_name() const;
45 
46  INLINE bool has_comment() const;
47  INLINE const string &get_comment() const;
48 
49  INLINE bool is_nested() const;
50  INLINE TypeIndex get_outer_class() const;
51 
52  INLINE bool is_atomic() const;
53  INLINE AtomicToken get_atomic_token() const;
54  INLINE bool is_unsigned() const;
55  INLINE bool is_signed() const;
56  INLINE bool is_long() const;
57  INLINE bool is_longlong() const;
58  INLINE bool is_short() const;
59 
60  INLINE bool is_wrapped() const;
61  INLINE bool is_pointer() const;
62  INLINE bool is_const() const;
63  INLINE bool is_typedef() const;
64  INLINE TypeIndex get_wrapped_type() const;
65 
66  INLINE bool is_array() const;
67  INLINE int get_array_size() const;
68 
69  INLINE bool is_enum() const;
70  INLINE int number_of_enum_values() const;
71  INLINE const string &get_enum_value_name(int n) const;
72  INLINE const string &get_enum_value_scoped_name(int n) const;
73  INLINE const string &get_enum_value_comment(int n) const;
74  INLINE int get_enum_value(int n) const;
75 
76  INLINE bool is_struct() const;
77  INLINE bool is_class() const;
78  INLINE bool is_union() const;
79 
80  INLINE bool is_fully_defined() const;
81  INLINE bool is_unpublished() const;
82  INLINE int number_of_constructors() const;
83  INLINE FunctionIndex get_constructor(int n) const;
84  INLINE bool has_destructor() const;
85  INLINE bool destructor_is_inherited() const;
86  INLINE FunctionIndex get_destructor() const;
87  INLINE int number_of_elements() const;
88  INLINE ElementIndex get_element(int n) const;
89  INLINE int number_of_methods() const;
90  INLINE FunctionIndex get_method(int n) const;
91  INLINE int number_of_make_seqs() const;
92  INLINE MakeSeqIndex get_make_seq(int n) const;
93 
94  INLINE int number_of_casts() const;
95  INLINE FunctionIndex get_cast(int n) const;
96 
97  INLINE int number_of_derivations() const;
98  INLINE TypeIndex get_derivation(int n) const;
99 
100  INLINE bool derivation_has_upcast(int n) const;
101  INLINE FunctionIndex derivation_get_upcast(int n) const;
102 
103  INLINE bool derivation_downcast_is_impossible(int n) const;
104  INLINE bool derivation_has_downcast(int n) const;
105  INLINE FunctionIndex derivation_get_downcast(int n) const;
106 
107  INLINE int number_of_nested_types() const;
108  INLINE TypeIndex get_nested_type(int n) const;
109 
110  void merge_with(const InterrogateType &other);
111  void output(ostream &out) const;
112  void input(istream &in);
113 
114  void remap_indices(const IndexRemapper &remap);
115 
116 private:
117  enum Flags {
118  F_global = 0x000001,
119  F_atomic = 0x000002,
120  F_unsigned = 0x000004,
121  F_signed = 0x000008,
122  F_long = 0x000010,
123  F_longlong = 0x000020,
124  F_short = 0x000040,
125  F_wrapped = 0x000080,
126  F_pointer = 0x000100,
127  F_const = 0x000200,
128  F_struct = 0x000400,
129  F_class = 0x000800,
130  F_union = 0x001000,
131  F_fully_defined = 0x002000,
132  F_true_destructor = 0x004000,
133  F_private_destructor = 0x008000,
134  F_inherited_destructor = 0x010000,
135  F_implicit_destructor = 0x020000,
136  F_nested = 0x040000,
137  F_enum = 0x080000,
138  F_unpublished = 0x100000,
139  F_typedef = 0x200000,
140  F_array = 0x400000,
141  };
142 
143 public:
144  int _flags;
145 
146  string _scoped_name;
147  string _true_name;
148  string _comment;
149  TypeIndex _outer_class;
150  AtomicToken _atomic_token;
151  TypeIndex _wrapped_type;
152  int _array_size;
153 
154  typedef vector<FunctionIndex> Functions;
155  Functions _constructors;
156  FunctionIndex _destructor;
157 
158  typedef vector<ElementIndex> Elements;
159  Elements _elements;
160  Functions _methods;
161  Functions _casts;
162 
163  typedef vector<MakeSeqIndex> MakeSeqs;
164  MakeSeqs _make_seqs;
165 
166  enum DerivationFlags {
167  DF_upcast = 0x01,
168  DF_downcast = 0x02,
169  DF_downcast_impossible = 0x04
170  };
171 
172 public:
173  // This nested class must be declared public just so we can declare
174  // the external ostream and istream I/O operator functions, on the
175  // SGI compiler. Arguably a compiler bug, but what can you do.
176  class Derivation {
177  public:
178  void output(ostream &out) const;
179  void input(istream &in);
180 
181  int _flags;
182  TypeIndex _base;
183  FunctionIndex _upcast;
184  FunctionIndex _downcast;
185  };
186 
187 private:
188  typedef vector<Derivation> Derivations;
189  Derivations _derivations;
190 
191 public:
192  // This nested class must also be public, for the same reason.
193  class EnumValue {
194  public:
195  void output(ostream &out) const;
196  void input(istream &in);
197 
198  string _name;
199  string _scoped_name;
200  string _comment;
201  int _value;
202  };
203 
204 private:
205  typedef vector<EnumValue> EnumValues;
206  EnumValues _enum_values;
207 
208  typedef vector<TypeIndex> Types;
209  Types _nested_types;
210 
211 public:
212  // The rest of the members in this class aren't part of the public
213  // interface to interrogate, but are used internally as the
214  // interrogate database is built. They are valid only during the
215  // session of interrogate that generates the database, and will not
216  // be filled in when the database is reloaded from disk.
217  CPPType *_cpptype;
218  CPPScope *_cppscope;
219 
220  friend class InterrogateBuilder;
221 };
222 
223 INLINE ostream &operator << (ostream &out, const InterrogateType &type);
224 INLINE istream &operator >> (istream &in, InterrogateType &type);
225 
226 INLINE ostream &operator << (ostream &out, const InterrogateType::Derivation &d);
227 INLINE istream &operator >> (istream &in, InterrogateType::Derivation &d);
228 
229 INLINE ostream &operator << (ostream &out, const InterrogateType::EnumValue &d);
230 INLINE istream &operator >> (istream &in, InterrogateType::EnumValue &d);
231 
232 #include "interrogateType.I"
233 
234 #include <set>
235 #include <map>
236 struct Dtool_PyTypedObject;
237 typedef std::map< int , Dtool_PyTypedObject *> RunTimeTypeDictionary;
238 typedef std::set<int > RunTimeTypeList;
239 
240 EXPCL_DTOOLCONFIG RunTimeTypeDictionary & GetRunTimeDictionary();
241 EXPCL_DTOOLCONFIG RunTimeTypeList & GetRunTimeTypeList();
242 
243 
244 #endif
This class manages a mapping of integers to integers.
Definition: indexRemapper.h:33
void input(istream &in)
Reads the data file as previously formatted by output().
void output(ostream &out) const
Formats the component for output to a data file.
An internal representation of a type.
The base class for things that are part of the interrogate database.