Panda3D
dcField.h
1 // Filename: dcField.h
2 // Created by: drose (11Oct00)
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 DCFIELD_H
16 #define DCFIELD_H
17 
18 #include "dcbase.h"
19 #include "dcPackerInterface.h"
20 #include "dcKeywordList.h"
21 #include "dcPython.h"
22 
23 #ifdef WITHIN_PANDA
24 #include "pStatCollector.h"
25 #endif
26 
27 class DCPacker;
28 class DCAtomicField;
29 class DCMolecularField;
30 class DCParameter;
31 class DCSwitch;
32 class DCClass;
33 class HashGenerator;
34 
35 ////////////////////////////////////////////////////////////////////
36 // Class : DCField
37 // Description : A single field of a Distributed Class, either atomic
38 // or molecular.
39 ////////////////////////////////////////////////////////////////////
40 class EXPCL_DIRECT DCField : public DCPackerInterface, public DCKeywordList {
41 public:
42  DCField();
43  DCField(const string &name, DCClass *dclass);
44  virtual ~DCField();
45 
46 PUBLISHED:
47  INLINE int get_number() const;
48  INLINE DCClass *get_class() const;
49 
50  virtual DCField *as_field();
51  virtual const DCField *as_field() const;
52  virtual DCAtomicField *as_atomic_field();
53  virtual const DCAtomicField *as_atomic_field() const;
54  virtual DCMolecularField *as_molecular_field();
55  virtual const DCMolecularField *as_molecular_field() const;
56  virtual DCParameter *as_parameter();
57  virtual const DCParameter *as_parameter() const;
58 
59  string format_data(const string &packed_data, bool show_field_names = true);
60  string parse_string(const string &formatted_string);
61 
62  bool validate_ranges(const string &packed_data) const;
63 
64  INLINE bool has_default_value() const;
65  INLINE const string &get_default_value() const;
66 
67  INLINE bool is_bogus_field() const;
68 
69  INLINE bool is_required() const;
70  INLINE bool is_broadcast() const;
71  INLINE bool is_ram() const;
72  INLINE bool is_db() const;
73  INLINE bool is_clsend() const;
74  INLINE bool is_clrecv() const;
75  INLINE bool is_ownsend() const;
76  INLINE bool is_ownrecv() const;
77  INLINE bool is_airecv() const;
78 
79  INLINE void output(ostream &out) const;
80  INLINE void write(ostream &out, int indent_level) const;
81 
82 #ifdef HAVE_PYTHON
83  bool pack_args(DCPacker &packer, PyObject *sequence) const;
84  PyObject *unpack_args(DCPacker &packer) const;
85 
86  void receive_update(DCPacker &packer, PyObject *distobj) const;
87 
88  Datagram client_format_update(DOID_TYPE do_id, PyObject *args) const;
89  Datagram ai_format_update(DOID_TYPE do_id, CHANNEL_TYPE to_id, CHANNEL_TYPE from_id,
90  PyObject *args) const;
91  Datagram ai_format_update_msg_type(DOID_TYPE do_id, CHANNEL_TYPE to_id, CHANNEL_TYPE from_id,
92  int msg_type, PyObject *args) const;
93 #endif
94 
95 public:
96  virtual void output(ostream &out, bool brief) const=0;
97  virtual void write(ostream &out, bool brief, int indent_level) const=0;
98  virtual void generate_hash(HashGenerator &hashgen) const;
99  virtual bool pack_default_value(DCPackData &pack_data, bool &pack_error) const;
100  virtual void set_name(const string &name);
101 
102  INLINE void set_number(int number);
103  INLINE void set_class(DCClass *dclass);
104  INLINE void set_default_value(const string &default_value);
105 
106 #ifdef HAVE_PYTHON
107  static string get_pystr(PyObject *value);
108 #endif
109 
110 protected:
111  void refresh_default_value();
112 
113 protected:
114  DCClass *_dclass;
115  int _number;
116  bool _default_value_stale;
117  bool _has_default_value;
118  bool _bogus_field;
119 
120 private:
121  string _default_value;
122 
123 #ifdef WITHIN_PANDA
124  PStatCollector _field_update_pcollector;
125 #endif
126 };
127 
128 INLINE ostream &operator << (ostream &out, const DCField &field) {
129  field.output(out);
130  return out;
131 }
132 
133 #include "dcField.I"
134 
135 #endif
This is a block of data that receives the results of DCPacker.
Definition: dcPackData.h:25
This is a list of keywords (see DCKeyword) that may be set on a particular field. ...
Definition: dcKeywordList.h:28
virtual bool pack_default_value(DCPackData &pack_data, bool &pack_error) const
Packs the field&#39;s specified default value (or a sensible default if no value is specified) into the s...
A single field of a Distributed Class, either atomic or molecular.
Definition: dcField.h:40
This represents a switch statement, which can appear inside a class body and represents two or more a...
Definition: dcSwitch.h:33
Defines a particular DistributedClass as read from an input .dc file.
Definition: dcClass.h:47
A single atomic field of a Distributed Class, as read from a .dc file.
Definition: dcAtomicField.h:34
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
void output(ostream &out) const
Write a string representation of this instance to <out>.
Definition: dcField.I:187
This class generates an arbitrary hash number from a sequence of ints.
Definition: hashGenerator.h:26
void generate_hash(HashGenerator &hashgen) const
Accumulates the properties of these keywords into the hash.
This class can be used for packing a series of numeric and string data into a binary stream...
Definition: dcPacker.h:38
virtual void set_name(const string &name)
Sets the name of this field.
A single molecular field of a Distributed Class, as read from a .dc file.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:43
This defines the internal interface for packing values into a DCField.