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