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