Panda3D
Loading...
Searching...
No Matches
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
26class DCPacker;
27class DCAtomicField;
29class DCParameter;
30class DCSwitch;
31class DCClass;
32class HashGenerator;
33
34/**
35 * A single field of a Distributed Class, either atomic or molecular.
36 */
37class EXPCL_DIRECT_DCPARSER DCField : public DCPackerInterface, public DCKeywordList {
38public:
39 DCField();
40 DCField(const std::string &name, DCClass *dclass);
41 virtual ~DCField();
42
43PUBLISHED:
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;
50 virtual const DCAtomicField *as_atomic_field() const;
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
92public:
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
107protected:
108 void refresh_default_value();
109
110protected:
111 DCClass *_dclass;
112 int _number;
113 bool _default_value_stale;
114 bool _has_default_value;
115 bool _bogus_field;
116
117private:
118 vector_uchar _default_value;
119
120#ifdef WITHIN_PANDA
121 PStatCollector _field_update_pcollector;
122#endif
123};
124
125INLINE 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
A single atomic field of a Distributed Class, as read from a .dc file.
Defines a particular DistributedClass as read from an input .dc file.
Definition dcClass.h:44
A single field of a Distributed Class, either atomic or molecular.
Definition dcField.h:37
bool has_default_value() const
Returns true if a default value has been explicitly established for this field, false otherwise.
Definition dcField.I:36
void set_number(int number)
Assigns the unique number to this field.
Definition dcField.I:158
DCClass * get_class() const
Returns the DCClass pointer for the class that contains this field.
Definition dcField.I:27
bool is_clsend() const
Returns true if the "clsend" flag is set for this field, false otherwise.
Definition dcField.I:101
bool is_ownsend() const
Returns true if the "ownsend" flag is set for this field, false otherwise.
Definition dcField.I:117
bool is_bogus_field() const
Returns true if the field has been flagged as a bogus field.
Definition dcField.I:60
bool is_broadcast() const
Returns true if the "broadcast" flag is set for this field, false otherwise.
Definition dcField.I:77
bool is_clrecv() const
Returns true if the "clrecv" flag is set for this field, false otherwise.
Definition dcField.I:109
int get_number() const
Returns a unique index number associated with this field.
Definition dcField.I:19
bool is_required() const
Returns true if the "required" flag is set for this field, false otherwise.
Definition dcField.I:68
std::string format_data(const std::vector< unsigned char > &packed_data, bool show_field_names=true)
Given a blob that represents the packed data for this field, returns a string formatting it for human...
Definition dcField.cxx:165
void set_default_value(std::vector< unsigned char > default_value)
Establishes a default value for this field.
Definition dcField.I:175
bool is_db() const
Returns true if the "db" flag is set for this field, false otherwise.
Definition dcField.I:93
bool is_airecv() const
Returns true if the "airecv" flag is set for this field, false otherwise.
Definition dcField.I:133
const std::vector< unsigned char > & get_default_value() const
Returns the default value for this field.
Definition dcField.I:46
void write(std::ostream &out, int indent_level) const
Write a string representation of this instance to <out>.
Definition dcField.I:149
std::vector< unsigned char > parse_string(const std::string &formatted_string)
Given a human-formatted string (for instance, as returned by format_data(), above) that represents th...
Definition dcField.cxx:182
virtual DCAtomicField * as_atomic_field()
Returns the same field pointer converted to an atomic field pointer, if this is in fact an atomic fie...
Definition dcField.cxx:112
void output(std::ostream &out) const
Write a string representation of this instance to <out>.
Definition dcField.I:141
void set_class(DCClass *dclass)
Assigns the class pointer to this field.
Definition dcField.I:167
bool is_ram() const
Returns true if the "ram" flag is set for this field, false otherwise.
Definition dcField.I:85
virtual DCMolecularField * as_molecular_field()
Returns the same field pointer converted to a molecular field pointer, if this is in fact a molecular...
Definition dcField.cxx:130
bool is_ownrecv() const
Returns true if the "ownrecv" flag is set for this field, false otherwise.
Definition dcField.I:125
bool validate_ranges(const std::vector< unsigned char > &packed_data) const
Verifies that all of the packed values in the field data are within the specified ranges and that the...
Definition dcField.cxx:203
void generate_hash(HashGenerator &hashgen) const
Accumulates the properties of these keywords into the hash.
A single molecular field of a Distributed Class, as read from a .dc file.
This is a block of data that receives the results of DCPacker.
Definition dcPackData.h:22
virtual void set_name(const std::string &name)
Sets the name of this field.
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...
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
This represents a switch statement, which can appear inside a class body and represents two or more a...
Definition dcSwitch.h:30
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.
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.