Panda3D
 All Classes Functions Variables Enumerations
dcClass.h
1 // Filename: dcClass.h
2 // Created by: drose (05Oct00)
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 DCCLASS_H
16 #define DCCLASS_H
17 
18 #include "dcbase.h"
19 #include "dcField.h"
20 #include "dcDeclaration.h"
21 #include "dcPython.h"
22 
23 #ifdef WITHIN_PANDA
24 #include "pStatCollector.h"
25 #include "configVariableBool.h"
26 
27 extern ConfigVariableBool dc_multiple_inheritance;
28 extern ConfigVariableBool dc_virtual_inheritance;
29 extern ConfigVariableBool dc_sort_inheritance_by_file;
30 
31 #else // WITHIN_PANDA
32 
33 static const bool dc_multiple_inheritance = true;
34 static const bool dc_virtual_inheritance = true;
35 static const bool dc_sort_inheritance_by_file = false;
36 
37 #endif // WITHIN_PANDA
38 
39 class HashGenerator;
40 class DCParameter;
41 
42 ////////////////////////////////////////////////////////////////////
43 // Class : DCClass
44 // Description : Defines a particular DistributedClass as read from an
45 // input .dc file.
46 ////////////////////////////////////////////////////////////////////
47 class EXPCL_DIRECT DCClass : public DCDeclaration {
48 public:
49  DCClass(DCFile *dc_file, const string &name,
50  bool is_struct, bool bogus_class);
51  ~DCClass();
52 
53 PUBLISHED:
54  virtual DCClass *as_class();
55  virtual const DCClass *as_class() const;
56 
57  INLINE DCFile *get_dc_file() const;
58 
59  INLINE const string &get_name() const;
60  INLINE int get_number() const;
61 
62  int get_num_parents() const;
63  DCClass *get_parent(int n) const;
64 
65  bool has_constructor() const;
66  DCField *get_constructor() const;
67 
68  int get_num_fields() const;
69  DCField *get_field(int n) const;
70 
71  DCField *get_field_by_name(const string &name) const;
72  DCField *get_field_by_index(int index_number) const;
73 
74  int get_num_inherited_fields() const;
75  DCField *get_inherited_field(int n) const;
76 
77  INLINE bool is_struct() const;
78  INLINE bool is_bogus_class() const;
79  bool inherits_from_bogus_class() const;
80 
81  INLINE void start_generate();
82  INLINE void stop_generate();
83 
84  virtual void output(ostream &out) const;
85 
86 #ifdef HAVE_PYTHON
87  bool has_class_def() const;
88  void set_class_def(PyObject *class_def);
89  PyObject *get_class_def() const;
90  bool has_owner_class_def() const;
91  void set_owner_class_def(PyObject *owner_class_def);
92  PyObject *get_owner_class_def() const;
93 
94  void receive_update(PyObject *distobj, DatagramIterator &di) const;
95  void receive_update_broadcast_required(PyObject *distobj, DatagramIterator &di) const;
96  void receive_update_broadcast_required_owner(PyObject *distobj, DatagramIterator &di) const;
97  void receive_update_all_required(PyObject *distobj, DatagramIterator &di) const;
98  void receive_update_other(PyObject *distobj, DatagramIterator &di) const;
99 
100  void direct_update(PyObject *distobj, const string &field_name,
101  const string &value_blob);
102  void direct_update(PyObject *distobj, const string &field_name,
103  const Datagram &datagram);
104  bool pack_required_field(Datagram &datagram, PyObject *distobj,
105  const DCField *field) const;
106  bool pack_required_field(DCPacker &packer, PyObject *distobj,
107  const DCField *field) const;
108 
109 
110 
111  Datagram client_format_update(const string &field_name,
112  DOID_TYPE do_id, PyObject *args) const;
113  Datagram ai_format_update(const string &field_name, DOID_TYPE do_id,
114  CHANNEL_TYPE to_id, CHANNEL_TYPE from_id, PyObject *args) const;
115  Datagram ai_format_update_msg_type(const string &field_name, DOID_TYPE do_id,
116  CHANNEL_TYPE to_id, CHANNEL_TYPE from_id, int msg_type, PyObject *args) const;
117  Datagram ai_format_generate(PyObject *distobj, DOID_TYPE do_id, ZONEID_TYPE parent_id, ZONEID_TYPE zone_id,
118  CHANNEL_TYPE district_channel_id, CHANNEL_TYPE from_channel_id,
119  PyObject *optional_fields) const;
120  Datagram client_format_generate_CMU(PyObject *distobj, DOID_TYPE do_id,
121  ZONEID_TYPE zone_id, PyObject *optional_fields) const;
122 
123  Datagram ai_database_generate_context(unsigned int context_id, DOID_TYPE parent_id, ZONEID_TYPE zone_id, CHANNEL_TYPE owner_channel,
124  CHANNEL_TYPE database_server_id, CHANNEL_TYPE from_channel_id) const;
125  Datagram ai_database_generate_context_old(unsigned int context_id, DOID_TYPE parent_id, ZONEID_TYPE zone_id,
126  CHANNEL_TYPE database_server_id, CHANNEL_TYPE from_channel_id) const;
127 
128 #endif
129 
130 public:
131  virtual void output(ostream &out, bool brief) const;
132  virtual void write(ostream &out, bool brief, int indent_level) const;
133  void output_instance(ostream &out, bool brief, const string &prename,
134  const string &name, const string &postname) const;
135  void generate_hash(HashGenerator &hashgen) const;
136  void clear_inherited_fields();
137  void rebuild_inherited_fields();
138 
139  bool add_field(DCField *field);
140  void add_parent(DCClass *parent);
141  void set_number(int number);
142 
143 private:
144  void shadow_inherited_field(const string &name);
145 
146 #ifdef WITHIN_PANDA
147  PStatCollector _class_update_pcollector;
148  PStatCollector _class_generate_pcollector;
149  static PStatCollector _update_pcollector;
150  static PStatCollector _generate_pcollector;
151 #endif
152 
153  DCFile *_dc_file;
154 
155  string _name;
156  bool _is_struct;
157  bool _bogus_class;
158  int _number;
159 
160  typedef pvector<DCClass *> Parents;
161  Parents _parents;
162 
163  DCField *_constructor;
164 
165  typedef pvector<DCField *> Fields;
166  Fields _fields, _inherited_fields;
167 
168  typedef pmap<string, DCField *> FieldsByName;
169  FieldsByName _fields_by_name;
170 
171  typedef pmap<int, DCField *> FieldsByIndex;
172  FieldsByIndex _fields_by_index;
173 
174 #ifdef HAVE_PYTHON
175  PyObject *_class_def;
176  PyObject *_owner_class_def;
177 #endif
178 
179  friend class DCField;
180 };
181 
182 #include "dcClass.I"
183 
184 #endif
This is our own Panda specialization on the default STL map.
Definition: pmap.h:52
A single field of a Distributed Class, either atomic or molecular.
Definition: dcField.h:40
This is a convenience class to specialize ConfigVariable as a boolean type.
Defines a particular DistributedClass as read from an input .dc file.
Definition: dcClass.h:47
Represents the complete list of Distributed Class descriptions as read from a .dc file...
Definition: dcFile.h:34
This is our own Panda specialization on the default STL vector.
Definition: pvector.h:39
A lightweight class that represents a single element that may be timed and/or counted via stats...
Represents the type specification for a single parameter within a field specification.
Definition: dcParameter.h:39
This is a common interface for a declaration in a DC file.
Definition: dcDeclaration.h:33
This class generates an arbitrary hash number from a sequence of ints.
Definition: hashGenerator.h:26
void write(ostream &out, int indent_level) const
Write a string representation of this instance to &lt;out&gt;.
This class can be used for packing a series of numeric and string data into a binary stream...
Definition: dcPacker.h:38
A class to retrieve the individual data elements previously stored in a Datagram. ...
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:43
virtual void output(ostream &out) const
Write a string representation of this instance to &lt;out&gt;.