Panda3D

dcClass.h

00001 // Filename: dcClass.h
00002 // Created by:  drose (05Oct00)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #ifndef DCCLASS_H
00016 #define DCCLASS_H
00017 
00018 #include "dcbase.h"
00019 #include "dcField.h"
00020 #include "dcDeclaration.h"
00021 #include "dcPython.h"
00022 
00023 #ifdef WITHIN_PANDA
00024 #include "pStatCollector.h"
00025 #include "configVariableBool.h"
00026 
00027 extern ConfigVariableBool dc_multiple_inheritance;
00028 extern ConfigVariableBool dc_virtual_inheritance;
00029 extern ConfigVariableBool dc_sort_inheritance_by_file;
00030 
00031 #else  // WITHIN_PANDA
00032 
00033 static const bool dc_multiple_inheritance = true;
00034 static const bool dc_virtual_inheritance = true;
00035 static const bool dc_sort_inheritance_by_file = false;
00036 
00037 #endif  // WITHIN_PANDA
00038 
00039 class HashGenerator;
00040 class DCParameter;
00041 
00042 ////////////////////////////////////////////////////////////////////
00043 //       Class : DCClass
00044 // Description : Defines a particular DistributedClass as read from an
00045 //               input .dc file.
00046 ////////////////////////////////////////////////////////////////////
00047 class EXPCL_DIRECT DCClass : public DCDeclaration {
00048 public:
00049   DCClass(DCFile *dc_file, const string &name, 
00050           bool is_struct, bool bogus_class);
00051   ~DCClass();
00052 
00053 PUBLISHED:
00054   virtual DCClass *as_class();
00055   virtual const DCClass *as_class() const;
00056 
00057   INLINE DCFile *get_dc_file() const;
00058 
00059   INLINE const string &get_name() const;
00060   INLINE int get_number() const;
00061 
00062   int get_num_parents() const;
00063   DCClass *get_parent(int n) const;
00064   
00065   bool has_constructor() const;
00066   DCField *get_constructor() const;
00067 
00068   int get_num_fields() const;
00069   DCField *get_field(int n) const;
00070 
00071   DCField *get_field_by_name(const string &name) const;
00072   DCField *get_field_by_index(int index_number) const;
00073 
00074   int get_num_inherited_fields() const;
00075   DCField *get_inherited_field(int n) const;
00076 
00077   INLINE bool is_struct() const;
00078   INLINE bool is_bogus_class() const;
00079   bool inherits_from_bogus_class() const;
00080 
00081   INLINE void start_generate();
00082   INLINE void stop_generate();
00083 
00084   virtual void output(ostream &out) const;
00085   
00086 #ifdef HAVE_PYTHON
00087   bool has_class_def() const;
00088   void set_class_def(PyObject *class_def);
00089   PyObject *get_class_def() const;
00090   bool has_owner_class_def() const;
00091   void set_owner_class_def(PyObject *owner_class_def);
00092   PyObject *get_owner_class_def() const;
00093 
00094   void receive_update(PyObject *distobj, DatagramIterator &di) const;
00095   void receive_update_broadcast_required(PyObject *distobj, DatagramIterator &di) const;
00096   void receive_update_broadcast_required_owner(PyObject *distobj, DatagramIterator &di) const;
00097   void receive_update_all_required(PyObject *distobj, DatagramIterator &di) const;
00098   void receive_update_other(PyObject *distobj, DatagramIterator &di) const;
00099 
00100   void direct_update(PyObject *distobj, const string &field_name, 
00101                      const string &value_blob);
00102   void direct_update(PyObject *distobj, const string &field_name, 
00103                      const Datagram &datagram);
00104   bool pack_required_field(Datagram &datagram, PyObject *distobj, 
00105                            const DCField *field) const;
00106   bool pack_required_field(DCPacker &packer, PyObject *distobj, 
00107                            const DCField *field) const;
00108 
00109 
00110 
00111   Datagram client_format_update(const string &field_name,
00112                                 DOID_TYPE do_id, PyObject *args) const;
00113   Datagram ai_format_update(const string &field_name, DOID_TYPE do_id, 
00114                             CHANNEL_TYPE to_id, CHANNEL_TYPE from_id, PyObject *args) const;
00115   Datagram ai_format_update_msg_type(const string &field_name, DOID_TYPE do_id, 
00116                             CHANNEL_TYPE to_id, CHANNEL_TYPE from_id, int msg_type, PyObject *args) const;
00117   Datagram ai_format_generate(PyObject *distobj, DOID_TYPE do_id, ZONEID_TYPE parent_id, ZONEID_TYPE zone_id,
00118                               CHANNEL_TYPE district_channel_id, CHANNEL_TYPE from_channel_id,
00119                               PyObject *optional_fields) const;
00120   Datagram client_format_generate_CMU(PyObject *distobj, DOID_TYPE do_id, 
00121                                       ZONEID_TYPE zone_id,                                                           PyObject *optional_fields) const;
00122 
00123   Datagram ai_database_generate_context(unsigned int context_id, DOID_TYPE parent_id, ZONEID_TYPE zone_id, CHANNEL_TYPE owner_channel,
00124                                 CHANNEL_TYPE database_server_id, CHANNEL_TYPE from_channel_id) const;
00125   Datagram ai_database_generate_context_old(unsigned int context_id, DOID_TYPE parent_id, ZONEID_TYPE zone_id,
00126                                 CHANNEL_TYPE database_server_id, CHANNEL_TYPE from_channel_id) const;
00127   
00128 #endif 
00129 
00130 public:
00131   virtual void output(ostream &out, bool brief) const;
00132   virtual void write(ostream &out, bool brief, int indent_level) const;
00133   void output_instance(ostream &out, bool brief, const string &prename, 
00134                        const string &name, const string &postname) const;
00135   void generate_hash(HashGenerator &hashgen) const;
00136   void clear_inherited_fields();
00137   void rebuild_inherited_fields();
00138 
00139   bool add_field(DCField *field);
00140   void add_parent(DCClass *parent);
00141   void set_number(int number);
00142 
00143 private:
00144   void shadow_inherited_field(const string &name);
00145 
00146 #ifdef WITHIN_PANDA
00147   PStatCollector _class_update_pcollector;
00148   PStatCollector _class_generate_pcollector;
00149   static PStatCollector _update_pcollector;
00150   static PStatCollector _generate_pcollector;
00151 #endif
00152 
00153   DCFile *_dc_file;
00154 
00155   string _name;
00156   bool _is_struct;
00157   bool _bogus_class;
00158   int _number;
00159 
00160   typedef pvector<DCClass *> Parents;
00161   Parents _parents;
00162 
00163   DCField *_constructor;
00164 
00165   typedef pvector<DCField *> Fields;
00166   Fields _fields, _inherited_fields;
00167 
00168   typedef pmap<string, DCField *> FieldsByName;
00169   FieldsByName _fields_by_name;
00170 
00171   typedef pmap<int, DCField *> FieldsByIndex;
00172   FieldsByIndex _fields_by_index;
00173 
00174 #ifdef HAVE_PYTHON
00175   PyObject *_class_def;
00176   PyObject *_owner_class_def;
00177 #endif
00178 
00179   friend class DCField;
00180 };
00181 
00182 #include "dcClass.I"
00183 
00184 #endif
 All Classes Functions Variables Enumerations